Hi,
I am having difficulty sending serial data from LabVIEW to my mega from my PC through USB.
A little bit of background to what I am trying to achieve: I would like to send a ASCII character (w, x, y, z) from the PC through serial to the mega, to move a servo.
I am able to send serial data through my terminal program (Putty) and interface with the mega. Everything works fine when I do this. When I try to do this in LabVIEW the RX Led blinks (So I know the mega is receiving data) but my servo does not move, Why?
Please may some one shed some light on this issue
Kind Regards
Kev
attached and below is my arduino sketchCode
#include <Servo.h>
Servo Pan;
Servo Tilt;
//int inByte = 0;
int panPos = 90;
int tiltPos = 90;
byte inByte = 0;
void setup(){
//initialize Serial
Serial.begin(115200);
delay(2000);
//Servo pins
Pan.attach(13);
Tilt.attach(12);
//Center Servos
Pan.write(panPos);
Tilt.write(tiltPos);
}
void loop(){
Serial.flush();
if (Serial.available() > 0){
inByte = Serial.read();
switch (inByte){
case 'w':
if (panPos >= 180){
Pan.write(180);
}
else{
panPos= panPos + 15; //move servo Left
Pan.write(panPos);
}
break;
case 'x':
if (panPos <= 0){
Pan.write(0);
}
else{
panPos= panPos - 15; //Move servo right
Pan.write(panPos);
}
break;
case 'y':
if(tiltPos >= 180){
Tilt.write(180);
}
else{
tiltPos = tiltPos + 15;
Tilt.write(tiltPos);
}
break;
case 'z':
if(tiltPos <= 0){
Tilt.write(0);
}
else {
tiltPos = tiltPos - 15;
Tilt.write(tiltPos);
}
break;
default:
Tilt.write(tiltPos);
Pan.write(panPos);
}
}
}
Pan_and_Tilt.ino (1.05 KB)

