Language problem

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

Does it work if you say:

 Serial.print(buffer);

…instead?

-br

Nope still prints ?

Confusing isn't it?

There is no float support in the printf() functions. Try this instead

dtostrf(aValue,2,6,buffer);

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

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

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

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.

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

256K? What kind of an Arduino are you using?!

What kind of an Arduino are you using?!

A Mega, obviously.

PaulS:

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

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

SurferTim: 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.)

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

majenko:

SurferTim: 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

Oh, it's not personal confusion I'm worried about. It's when people say they have a mega you don't know which one they are talking about. And when you google for the mega, all you find is the 1280 mega, not the 2560 mega.

majenko: Oh, it's not personal confusion I'm worried about. It's when people say they have a mega you don't know which one they are talking about. And when you google for the mega, all you find is the 1280 mega, not the 2560 mega.

Funny, I googled on "arduino mega" and see mostly mega2560 boards links. What search term did you use?

http://www.google.com/webhp?source=search_app#hl=en&sugexp=les%3B&gs_rn=6&gs_ri=psy-ab&cp=12&gs_id=1a&xhr=t&q=arduino+mega&es_nrs=true&pf=p&sclient=psy-ab&oq=arduino+mega&gs_l=&pbx=1&bav=on.2,or.r_qf.&bvm=bv.43828540,d.b2U&fp=6536e23986d2c8d7&biw=1033&bih=787

Lefty

I google for Arduino Mega - first result takes you to the old mega. Yes, the mega2560 is listed there as the mega2560 - nothing really to tell you what is what, so you click on the mega link, and it tells you about the old one. Nothing on the old board's page to say it's been superseded by the 2560.

majenko:
I google for Arduino Mega - first result takes you to the old mega. Yes, the mega2560 is listed there as the mega2560 - nothing really to tell you what is what, so you click on the mega link, and it tells you about the old one. Nothing on the old board’s page to say it’s been superseded by the 2560.

Well your complaints seem pretty minor to me, but then it probably matters how long one has been following the arduino platform rather then if one joined at a later date. The product pace (for both new additions and newer revisions of older products) has been pretty hectic in recent years and the software IDE and supplied ‘standard’ libraries have been in a constant state of flux also. I still think they do a pretty good job of documentation as time has passed, but maybe not as perfect as you would wish. :wink:

Lefty

I have to agree with Lefty..... only found out about Arduino a few weeks ago but am impressed by the quality of both the development platform and the boards.

As I said there are a few shortcomings in the functionality of the compiler but that apart its an excellent way to get a project off the ground and flying as I have found out already with one completed project using the ATmega2560.

I have already been playing with the DUE (well the microchip version MAX32) now thats a VERY good platform, would be nice if Arduino was extended for that one to do full double precision and ascii encoding decoding but the microchip MPLABX does. I have a project that will require 4th and 5th order curve fitting routines and they WILL require true double precision but already have the board driving a CCD array and collecting data from it in less than a day!

Keep up the good work to all at ARDUINO :)