Reading Negative Float Through Serial Port

Hello,

After reading through http://forum.arduino.cc/index.php?topic=396450.0 I realized that Example 4 applied to my needs, except it reads only integers, where I need to read a float. After viewing Example 5 it was somewhat as to what I need, except I only want to read a single float from the port, where Robin has a mix of strings, integers and floats. In such I thought to slightly modify his fourth example changing “atoi” to “atof” however no luck as it is only giving me integers.

// Example 4 - Receive a number as text and convert it to an int

const byte numChars = 32;
char receivedChars[numChars];   // an array to store the received data

boolean newData = false;

int dataNumber = 0;             // new for this version

void setup() {
    Serial.begin(9600);
    Serial.println("<Arduino is ready>");
}

void loop() {
    recvWithEndMarker();
    showNewNumber();
}

void recvWithEndMarker() {
    static byte ndx = 0;
    char endMarker = '\n';
    char rc;
    
    if (Serial.available() > 0) {
        rc = Serial.read();

        if (rc != endMarker) {
            receivedChars[ndx] = rc;
            ndx++;
            if (ndx >= numChars) {
                ndx = numChars - 1;
            }
        }
        else {
            receivedChars[ndx] = '\0'; // terminate the string
            ndx = 0;
            newData = true;
        }
    }
}

void showNewNumber() {
    if (newData == true) {
        dataNumber = 0.0;             // new for this version
        dataNumber = atof(receivedChars);   // new for this version
        Serial.print("This just in ... ");
        Serial.println(receivedChars);
        Serial.print("Data as Number ... ");    // new for this version
        Serial.println(dataNumber);     // new for this version
        newData = false;
    }
}

I have been at this for some time now and really would appreciate the help as to what the problem is.

Declare dataNumber as float may help.

Lol wow. It was that simple. Guess I just needed a new pair of eyes at it. Thanks a lot!