Refer to problem of string and float from http://www.udoo.org/arduino-ide-serial-and-float-issue I want to convert string to float look like code below, but got run-time error, Have anyone suggest how to convert ? void setup(){ Serial.begin(9600); } char value[20] = "1234.567"; void loop(){ float float_value = atof(value); Serial.println(float_value); Delay(500); } Thanks
I`m more of a python person myself . but shouldn`t that be :- double value = 1234.567; because you are trying to assigning a string to a double .
Remove the quotes. float value = 123.456f; Serial.println(value); I assume that println takes a float.
I still have problem with Arduino sketch with atof() function. it nothing print out and loop freeze at function atof(). How can to fix it? NOTE: i using Auduino Sketch run on Linaro Ubuntu 12.04 LTS void setup(){ Serial.begin(9600); } char value[20] = "1234.567"; void loop(){ float float_value = atof(value); Serial.println(float_value); Delay(500); }
You are not taking the big hint on the debug window . sketch_may15a.ino: In function 'void loop()': sketch_may15a:10: error: 'Delay' was not declared in this scope delay(500); is not the same as Delay(500)'; c and c++ is case sensitive TRY Code: void setup(){ Serial.begin(9600); } char value[20] = "1234.567"; void loop(){ float float_value = atof(value); Serial.println(float_value); delay(500); }
Sorry , but the above code is now good, no freeze I`ve uploaded the code with the result of 1234.567 been displayed on the monitor , repeated every 1/2 a second ( 500 milliseconds ). No problem with your code now it works like I guessed it would . Try using your p.c to compile your code and try download the lastest version of arduino for the due . ( 1.5.6 ) pc / mac
Thanks Peter I found problem, above code good for Debian Wheezy but the same code it doesn't work on Linaro Ubutu (both linux I download from Udoo website) both OS installed Arduino 1.5.4 version, may i will try to update Arduino for Ubuntu.