0

I recently made a thread where I read BLE data that has three different numbers/values. The data changes but it typically looks something like this: 0,5 -0,1 0

I successfully store the three numbers in a unique char* but when I try to convert the char* to a double I get the value 0.0 in return.

This is my code:

        while (tok)
        {
            if (currentRow == 0)
            {
              currentRow = currentRow +1;
              double a = atof(tok);
              Serial.println (a);
            }

            else if (currentRow == 1)
            {
              currentRow = currentRow+1;
              double b = strtod(tok, NULL);
              Serial.println (b);
            }

            else {
              currentRow = 0;
              double c = atof (tok);
              Serial.println (c);
            }

            tok = strtok(NULL, " "); 
        }
  • Comments are not for extended discussion; this conversation has been moved to chat. Comments are for clarifying the question - not answering it. – Nick Gammon Mar 28 '17 at 4:54
1

The value that was being sent used a comma "," instead of a dot "." that was needed in order to convert the number.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.