04-10-2015 06:22 PM
Hi guys,
Basically i am trying to send a float to arduino uno.
I use for that a string .I send at first its length then i send the numbers.
For the arduino side ,here is the code.I can see that the board Rx/tx leds blinks when i start the Vi.Unfortunately, the led which doesn"t blink as it should be.
Here is a quick look at my arduino code.
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
pinMode(13,OUTPUT);
// Serial.flush();
// prints title with ending line break
}
int i=0;
int j=0;
int longu=0;
char data='F';
String data2="";
float val=0;
int posVir=0;
void loop()
{
if (i==0)
{
delay(10);
data=Serial.read();
longu=(int)data;
while (j<longu+1)
{data=Serial.read();
data2=data2+data;
delay(10);
j=j+1;
}
}
val=data2.toFloat();
i=1;
delay(50);
if (val==22.5)
{
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(1000);
}
if (val==315)
{
digitalWrite(13,HIGH);
delay(4000);
digitalWrite(13,LOW);
delay(4000);
}
val=0;
}
04-10-2015 08:02 PM