Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 10 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
- include "mbed.h"
Serial Bt(p9,p10);
PwmOut myled(LED4);
int main ()
{
Bt.baud(9600);
char K[3];
while(1)
{
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
10 years, 10 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.
10 years, 10 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.
10 years, 10 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