05-02-2011 06:56 AM
Hello All,
I am trying to communicate with my arduino through a serial port (COM 3). I am using Labview 7.0. I opened the Basic Read and Write through Serial Communication Example on Labview. What I want to do is send a byte to my arduino and turn the LED on. I am using the Physical Pixel Example from the arduino. Unfortunately, when using the example in Labview it does not do what i want it to do. The LED lights simply blink and do not stay on. The ultimate goal is have labview automatically send a byte to the arduino (if possible?) and as a result execute a function that will be programmed into the arduino. But first I need to ensure that it is able to communicate properly.
Arduino Code:
const int ledPin = 13; // the pin that the LED is attached to
int incomingByte; // a variable to read incoming serial data into
void setup() {
// initialize serial communication:
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
// if it's a capital H (ASCII 72), turn on the LED:
if (incomingByte == 'H') {
digitalWrite(ledPin, HIGH);
}
// if it's an L (ASCII 76) turn off the LED:
if (incomingByte == 'L') {
digitalWrite(ledPin, LOW);
}
}
}
05-02-2011 08:31 AM
*UPDATE*
I was able to get the program working. I uploaded the Arudino code which I pasted above. The program in LAbview is simple. I first confirgure the serial port then use the VISA Write VI to write a value through the port. I do no close the session out though. I think this was the problem I was having. Now what I want to do is automatically send a numerical value to turn the LED on. I will use a for loop from 0-4. Does anyone know how to convert the number to the correct type of imformation (HEX, Binary etc.) that the VISA write VI uses??
Thank you!
05-03-2011 05:48 PM
Hi EngineeringEE,
Based on the information in the LabVIEW help for the NI VISA write, the information to be written is in string format. What type of numeric information are you trying to send? I saw in your code above that you are using H and L. Is that what you would like to send in numeric form?
05-03-2011 08:20 PM
Hello,
I figured it out. Please refer to this thread. I am able to send the Arduino a value automatically with no user input.
Thank you!