String and Float issue

Discussion in 'General Discussion' started by y.seksit, May 11, 2014.

  1. y.seksit

    y.seksit New Member

    Joined:
    May 8, 2014
    Messages:
    17
    Likes Received:
    0
    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
     
  2. peter247

    peter247 New Member

    Joined:
    Mar 10, 2014
    Messages:
    263
    Likes Received:
    2
    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 .
     
  3. bsutton

    bsutton New Member

    Joined:
    May 11, 2014
    Messages:
    8
    Likes Received:
    0
    Remove the quotes.
    float value = 123.456f;
    Serial.println(value);

    I assume that println takes a float.
     
  4. y.seksit

    y.seksit New Member

    Joined:
    May 8, 2014
    Messages:
    17
    Likes Received:
    0
    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);
    }
     
  5. peter247

    peter247 New Member

    Joined:
    Mar 10, 2014
    Messages:
    263
    Likes Received:
    2
    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);
    }
     
  6. y.seksit

    y.seksit New Member

    Joined:
    May 8, 2014
    Messages:
    17
    Likes Received:
    0
    HI peter,

    yest, it must is delay(500) but still freeze at atof()
     
  7. peter247

    peter247 New Member

    Joined:
    Mar 10, 2014
    Messages:
    263
    Likes Received:
    2
    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
     
  8. y.seksit

    y.seksit New Member

    Joined:
    May 8, 2014
    Messages:
    17
    Likes Received:
    0
    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.
     

Share This Page