LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write to Arduino

Solved!
Go to solution

Heu all,

     So I know how to read data from the arduino now I would like to start writing to the arduino I have read several posts on reading and writing but I seem to still be missing something.

 

     In this post the JohnCS suggests using the dimmer example that ships with the arduino I have uploaded this to my arduino I am wondering how I send the byte to the arduino through Labview I figure you use the VISA write.vi but I did not get what JohnCS said  "which wants you to send a single character followed by a carriage control to change the LED"

 

here is the link to the post:

http://forums.ni.com/t5/LabVIEW/How-to-establish-serial-communication-between-Labview-and/m-p/845084...

 

any help would be great thanks

Harold Timmis
htimmis@fit.edu
Orlando,Fl
*Kudos always welcome:)
0 Kudos
Message 1 of 31
(13,442 Views)

Let's say you want to send A and a return.

 

Set the string constant for \ codes display, and type in A\r into it.

Message 2 of 31
(13,432 Views)

is there a document on \ code?

 

here is what I did I am not great with VISA, but I am praticing with this arduino

Harold Timmis
htimmis@fit.edu
Orlando,Fl
*Kudos always welcome:)
0 Kudos
Message 3 of 31
(13,425 Views)

here is my code:

Harold Timmis
htimmis@fit.edu
Orlando,Fl
*Kudos always welcome:)
0 Kudos
Message 4 of 31
(13,397 Views)

Is it working?  If not, what is going wrong?

 

You should show the labels of your two buttons temporarily and rename them to something more meaningful (like Read and Write).  Right now, your write button is wired to your Read case structure and the read button to the write case structure.

 

I would get rid of the shift registers on the error wire of the For Loop and turn them into normal tunnels.  If you have what might be an odd error such as a timeout, then it will never let any of those functions work again because that error will be propagated to later iterations of your For Loop.

Message 5 of 31
(13,390 Views)

And DON'T wire the byte count from the VISA Write to the number of bytes of the VISA Read. There is no relationship.

Message 6 of 31
(13,387 Views)

yeah I realized the buttom problem I also am using the Bytes at Port property instead of wiring the returm count to byte count.

 

nothing happens when I send 255\r to the port it is waiting for a value between 0 - 255 and sends that value out to the digital IO port which turns the LED on none of which happens.

 

also the Bytes at Port Property Node returns a 0 always which gives me no error but also no data and LED does not turn.

 

it seems I can not attach the arduino code so I am pasting it here:

 

const int ledPin = 13;      // the pin that the LED is attached to

void setup()
{
  // initialize the serial communication:
  Serial.begin(9600);
  // initialize the ledPin as an output:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  byte brightness;

  // check if data has been sent from the computer:
  if (Serial.available()) {
    // read the most recent byte (which will be from 0 to 255):
    brightness = Serial.read();
    // set the brightness of the LED:
    analogWrite(ledPin, brightness);
  }
}

Harold Timmis
htimmis@fit.edu
Orlando,Fl
*Kudos always welcome:)
Message 7 of 31
(13,379 Views)

I completely missed the bytes written to bytes to read mistake.

 

Are you expecting something to be written back to your serial port?  In the code you posted, I don't see any Serial.Write() happening.  So it's no surprise that bytes at port would be 0.

 

Are you sure your LED is electrically connected to your output pin properly?  Check the wiring diagram for that port.  Is the pin supposed to source or sink current for the LED?  Are you sure you have the polarity of the LED correct?  Do you need any sort of resistor in series with the LED to limit current?  Also, you say it is a digital IO port, but your code does an AnalogWrite.  In common usage, digital is a completely different thing than analog.

 

If you are concerned about whether your serial code is correct, I would forget about the LED at the moment and just have your basic program read the serial port on the board and turn around and send the data back.  Then you'll know if your LabVIEW to board serial communication is working properly.

 

You should also have some kind of wait statement between the VISA write and the bytes at port property node.  As it is right now, it will execute immediately after the VISA write, which would not be enough time for the board to send any or all of its data (assuming the board is returning any data).  (Look at the basic and advanced examples for the serial port again in the example finder.)

Message 8 of 31
(13,369 Views)

And how are you writing the data. Your c code says to expect a single byte between 0 and 255. Your LabVIEW program is set for '\' Codes Display. You're not sending the text 255 for example, are you? Change to hex display and send a single byte that way.

Message 9 of 31
(13,366 Views)

this is the schematic and code I am using:

 

http://www.arduino.cc/en/Tutorial/Dimmer

 

i see what you mean with the write function needing a wait

 

I also have looked at the advanced and basic examples, but I think I am missing something with VISA (as in knowledge of VISA)

Harold Timmis
htimmis@fit.edu
Orlando,Fl
*Kudos always welcome:)
0 Kudos
Message 10 of 31
(13,356 Views)