Pages: [1] 2   Go Down
Author Topic: Language problem  (Read 1184 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Language problem.....info states that Arduino uses C or C++ so why does the following :-

char buffer[20];
float aValue=45.78945;
  sprintf(buffer,"%2.6f \n",aValue);
  Serial.write(buffer);


 compile and download okay but print out on the monitor just a ?

Board is ATmega2560

Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Does it work if you say:
Code:
Serial.print(buffer);
…instead?

-br
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nope still prints ?

Confusing isn't it?
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 148
Posts: 6104
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There is no float support in the printf() functions. Try this instead
Code:
dtostrf(aValue,2,6,buffer);
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes that works.... so the Arduino C / C++ is a restricted subset of the full C/C++.....

I assume there is a similar function to replace the C sscanf .....
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 148
Posts: 6104
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think the ascii to double conversion is atof().
Logged

UK
Offline Offline
Faraday Member
**
Karma: 100
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

  sprintf(buffer,"%2.6f \n",aValue);
To save space, the Arduino has no floating point support in printf/scanf routines.  Adding it is possible, but increases your program size by a good 1500 bytes.
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

1500 bytes out of 256K is a small price to pay ..... smiley

I am begining to see the shortcomings of Arduino VS proper development platform like Atmel Studio and MPXLAB but can also see it is useful for quickie developments/ trials.

Will the DUE support real double values and proper encoding/decoding I wonder, be a shame to waste all that processing power without doing some serious number crunching.
Logged

UK
Offline Offline
Faraday Member
**
Karma: 100
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

1500 bytes out of 256K is a small price to pay ..... smiley
256K?  What kind of an Arduino are you using?!
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 631
Posts: 50084
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What kind of an Arduino are you using?!
A Mega, obviously.
Logged

UK
Offline Offline
Faraday Member
**
Karma: 100
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What kind of an Arduino are you using?!
A Mega, obviously.
http://arduino.cc/en/Main/arduinoBoardMega
Flash Memory   128 KB of which 4 KB used by bootloader
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 148
Posts: 6104
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This one.
http://arduino.cc/en/Main/ArduinoBoardMega2560
Flash Memory   256 KB of which 8 KB used by bootloader
Logged

UK
Offline Offline
Faraday Member
**
Karma: 100
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This one.
http://arduino.cc/en/Main/ArduinoBoardMega2560
Flash Memory   256 KB of which 8 KB used by bootloader

Argh!  Stupid Arduino.  Why can't a Mega be a Mega?  Why have the same board, but with different chips?  That's just barmy.

It would be much less confusing to give it a different name, like the Arduino Giga or Arduino Uber or something.

That's almost as bad as the ZX Spectrum +2, +2, and +2 (actually +2, +2A and +2B, all different, and all with incompatibilities.)
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 148
Posts: 6104
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I know what you mean. The Duemilanove had the same problem. This is where that 1500 bytes really makes a difference.
Flash Memory   16 KB (ATmega168) or 32 KB (ATmega328) of which 2 KB used by bootloader

That would be almost 10% of the memory just to print floats.  smiley-sad
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17301
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This one.
http://arduino.cc/en/Main/ArduinoBoardMega2560
Flash Memory   256 KB of which 8 KB used by bootloader

Argh!  Stupid Arduino.  Why can't a Mega be a Mega?  Why have the same board, but with different chips?  That's just barmy.

Calm down the mega board was released first using a 1280P chip, then later the mega2560 replaced it. You are looking at product evolution not desire to confuse you.   smiley-wink

It would be much less confusing to give it a different name, like the Arduino Giga or Arduino Uber or something.

They did, the official name is mega2560 board. http://arduino.cc/en/Main/Products
For older released boards use this link, http://arduino.cc/en/Main/Boards


That's almost as bad as the ZX Spectrum +2, +2, and +2 (actually +2, +2A and +2B, all different, and all with incompatibilities.)

Can't talk about the ZX Spectrum, but the arduino platform has done a pretty good job of document and supporting both existing products and legacy. You just need to do a little more research on the subject IMHO.
Lefty

Logged

Pages: [1] 2   Go Up
Jump to: