Go Down

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

#### veneridesign

##### Dec 21, 2012, 05:46 pmLast Edit: Dec 21, 2012, 07:37 pm by veneridesign Reason: 1
Hello,
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 ?? )
Thank you very much!!!

Luca

#### Arctic_Eddie

#1
##### Dec 21, 2012, 07:00 pm
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.

#### veneridesign

#2
##### Dec 21, 2012, 07:31 pm
Good, Thak you very much!!!!

Luca

#### jgmdavies

#3
##### Dec 22, 2012, 12:29 pm
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.

HTH
Jim

#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()
{
Serial.begin(115200);
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);
delay(100);
digitalWrite(ledPin, LOW);
delay(900);

count++;
}

#### veneridesign

#4
##### Dec 22, 2012, 02:40 pmLast 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...

Luca

Go Up

Please enter a valid email to subscribe