Another issue that i found, create a String object with a float (for example String(3.32)) different from 0 stop the program. If someone can test it please ? For information, i have the lasted arduino library (udoo).
Yes, simply if i create a String object form a float that is equal to zero the sketch run : Code: float myFloat=0; String data =String(myFloat); But if i define this (or modify the value of the float later--> from adc for example) the sketch compile but the program stop or bug in the card : Code: float myFloat=3.14; String data =String(myFloat);
I still don't understand your problem. What do you want to achieve? How is UDOO related to this problem? EDIT: Take a look, this may help http://forum.arduino.cc/index.php?topic=243660.0
I'm not a C++ programmer by heart, but afaik there is no float constructor of a string , is there? If you initialize it with 0 I guess it will create a string solely of '\0' aka The Empty String. if you pass 3.14 it will pass it some string starting with character nonsense until somewhere in the memory it will encounter a \0. The C++ library seems to contain a to_string method, which might have the function you need. See the C++ reference: http://www.cplusplus.com/reference/string/to_string/ (I have no idea of which version/subset of C++ UDOO/Arduino is delivering)
I just want to create a string with a float because i can't send a structure for the moment over serial, see this issue : http://www.udoo.org/forum/threads/bug-with-uart-com.4499/ Otherwise, i just want to use a constructor of Arduino String object that take float in argument ! see here for more details : https://www.arduino.cc/en/Tutorial/StringConstructors I'm not a fan of string use in programming (take more time to process !!!), but for the moment it's the easiest way to use serial com with A9 (send a packed struct not working ....)
Have you tested the float constructor on a standard Arduino? What about using something like snprintf? http://maxsi.org/coding/c-string-creation.html
snprintf is out. The following code crashes the M4: Code: double x = 1234.56; char buf[128]; snprintf(buf, 128, "%f", x);
Okay guys, I came up with a solution that has worked for me so far. I modified the printFloat function from AppData\Local\Arduino15\packages\UDOO\hardware\solox\1.6.7\variants\udooneo\Print.cpp to write a double to a char* buffer, which was exactly what I needed. Leaving it here in case anyone finds it useful: [Edit: Modified to return pointer to buffer.] Code: char *doubleToString(double number, uint8_t digits, char *buffer, int bufferLength) { int bufIndex = 0; if (isnan(number)) { snprintf(buffer, bufferLength, "nan"); return buffer; } if (isinf(number)) { snprintf(buffer, bufferLength, "inf"); return buffer; } if (number > 4294967040.0) { snprintf(buffer, bufferLength, "ovf"); return buffer; } if (number <-4294967040.0) { snprintf(buffer, bufferLength, "ovf"); return buffer; } // Handle negative numbers if (number < 0.0) { buffer[bufIndex++] = '-'; number = -number; } // Round correctly so that print(1.999, 2) prints as "2.00" double rounding = 0.5; for (uint8_t i = 0; i < digits; ++i) { rounding /= 10.0; } number += rounding; // Extract the integer part of the number and print it unsigned long int_part = (unsigned long)number; double remainder = number - (double)int_part; char tmp[bufferLength]; itoa (int_part, tmp, 10); for (int i = 0; i < strlen(tmp); i++) { buffer[bufIndex++] = tmp[i]; } // Print the decimal point, but only if there are digits beyond if (digits > 0) { buffer[bufIndex++] = '.'; } // Extract digits from the remainder one at a time while (digits-- > 0) { remainder *= 10.0; int toPrint = int(remainder); itoa (toPrint, tmp, 10); buffer[bufIndex++] = tmp[0]; remainder -= toPrint; } //Null-terminate the string buffer[bufIndex] = '\0'; return buffer; } Usage: Code: double x = -1234.5678; char buf[128]; doubleToString(x, 2, buf, 128); Serial0.println(buf);