Go Down

Topic: Language problem (Read 1 time) previous topic - next topic

clayender

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


billroy

Does it work if you say:
Code: [Select]

Serial.print(buffer);

…instead?

-br

clayender

Nope still prints ?

Confusing isn't it?

SurferTim

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


clayender

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 .....

SurferTim

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

majenko


  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.
Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

clayender

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

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.

majenko


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

256K?  What kind of an Arduino are you using?!
Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

PaulS

Quote
What kind of an Arduino are you using?!

A Mega, obviously.

majenko


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
Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

SurferTim

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

majenko


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.)
Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

SurferTim

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.  :(

retrolefty



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.   ;)

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


Go Up