LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sending float to arduino uno using VISA

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;

} 

 

0 Kudos
Message 1 of 2
(3,032 Views)