Go Down

Topic: square and itoa dont work on ARDUINO DUE (Read 3250 times) previous topic - next topic


Dec 21, 2012, 05:46 pm Last Edit: Dec 21, 2012, 07:37 pm by veneridesign Reason: 1
I dont know why on ARDUINO DUE the square (math library) fubction and the itoa(stdio library) function do not work.
Any solution?
(I Know...use pow or rewrite the function..but why they dont work ????? :smiley-slim:)
Thank you very much!!!



There is a library problem when using IDE V1.5.1r2 and the Due. I had the same problem with the itoa() function on the Due while the IDE would work ok with the Mega. The quickest solution is to switch to the sprintf() function. This function allows you to combine text with converted integers.



There's no mention of a square function in the Arduino reference at http://arduino.cc/en/Reference/HomePage, but it's easy enough to define a C macro to do it.

An itoa function is available if you #include the file itoa.h.

The sketch below uses itoa and square and works as expected with a Due and Arduino 1.5.1r2.


#include "itoa.h"
#include "Print.h"

template<class T> inline Print &operator <<(Print &obj, T arg) { obj.print(arg); return obj; }
#define square(x) pow(x, 2)

int count = 1;
int ledPin =  13;    // LED connected to digital pin 13

// Run once, when the sketch starts.
void setup()
   count = 0;

   // initialize the digital pin as an output:
   pinMode(ledPin, OUTPUT);     

void loop()                     
   String s;
        char temp[20];

   Serial << "Blink: Loop " << count << ", " << itoa(count, temp, 10) << ", " << square(count) << (char)10;

   digitalWrite(ledPin, HIGH);
   digitalWrite(ledPin, LOW);



Dec 22, 2012, 02:40 pm Last Edit: Dec 22, 2012, 02:43 pm by veneridesign Reason: 1
Thank you , I''l try this solution!

There is no referce about square in the Arduino reference at http://arduino.cc/en/Reference/HomePage because of is defined in math.h http://www.arduino.cc/en/Reference/MathHeader, but is for AVR...


Go Up