9 years, 12 months ago.

Serial mbed - labview problem

Im trying to control my mbed with serial communications using lab view, i manage already to sen teh information for the pwm led value, but im reading the combination of the number im sending , for example i sen '1.0' thats a 3 value string and i recieve 0.1 .01 10. 1,0 , etc, each time is random. Here is my code in the mbed

  1. include "mbed.h"

Serial Bt(p9,p10);

PwmOut myled(LED4);

int main ()



char K[3];



Bt.scanf ("%3s",&K);

pc.printf ("%s\n\r",K); }}

and here is the lab view program with the pc serial readings


after i solve this i will need to save that char number as a float so the led change his brightness

3 Answers

9 years, 11 months ago.

Hi Daniel,

In my wifly project i used a terminator like '*' so wen labview sends data it wil add a '*' after the data so you can know when the data is ready to use.

include the mbed library with this snippet

string str = "";
char c;    

int main()
    int value =0;                                           

    while(1) {
        while(wifi.readable()) {                       //wifi is serial port
            c = wifi.getc();                                //read the characters
            if(c == '*') {                                     //whencharacter is '*' make 
                value = (double)atof(str.c_str());          //string to double
                str = "";                                   //empty string
            } else {
                str = str + c;                              //fill string

I hope you can use this tip.

Accepted Answer
9 years, 12 months ago.

%s will also null-terminate the string, so you should put it in a 4-byte buffer instead of 3, but I am not sure that is your problem. If you want it as float it is easy, just replace %s with %f and you get it as float.

9 years, 12 months ago.

i tried i already converted to a float with "atoi" , but the number keep moving to every position 0.1 - 10,- ,10 - 0,1