in data 03-24-2011 07:27 AM
Hi =). Im a beginner working reading serial data from an arduino but im facing... Lets do this step by step
I constructed a voltage divider circuit that gives an output ranging from 0 to 5V. The output of this circuit is sent to an analog input pin 0 of an Arduino Duemilanove board.
1) Firstly I plugged in the cable connecting my laptop USB to the arduino board.
2) I went to start->control panel->system->hardware->device manager. Check out Ports(COM & LPT). In my laptop I can see USB Serial Port (COM4). Now I know in Labview I have to read serial data from COM 4.
3) For the arduino side, here is the code to read voltage variations inputted to analog pin 0. The last line 'delay' determines the sampling rate of how we want to sample the voltage divider output:
int potPin = 0; // select the input pin for the voltage divider output
int val = 0; // variable to store the value coming from the sensor
void setup()
{
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
val = analogRead(potPin); // read the value from the voltage divider
Serial.println(val);
delay(10);
}
I have slightly modified the basic serial read write VI.. I have attached the block diagram used with comments. Basically I tried to read serial data, divide by 1023 and multiply by 5 in order to graph voltage variations from the voltage divider circuit. However Im not getting the correct voltage output values . The voltage value just keeps going to 0 and coming again as shown in the pic.
Could you guys please guide me on what went wrong?
Thanks!
Risolto Andare alla soluzione.
in data 03-24-2011 07:48 AM
- you're reading data, even if there is no data on the port. if 0 bytes are read => ""
- in the false case, you have VISA resource wired to the string output tunnel?
- there is no close VISA resource at the end of the VI
- you're not looping this VI when reading bytes
I've added an addaption of your VI which you should give a try maybe 😉
in data 03-24-2011 08:00 AM
Thanks ABCPrograms. Now I know what I did wrong
in data 03-24-2011 08:30 AM
The VISA ref did not pass through the loop so the close VISA might close the port before it read the bytes.
in data 03-24-2011 08:33 AM
TRUE Omar, thx for adding this. BIG ERROR on my behalf. I should hit myself for missing that 😉
in data 03-24-2011 08:37 AM
I had a similar project. My Arduino continuously sends room temperature readings as part of a text string and I wrote a VI to buffer the text, extract the temp digits, display the value and graph the data.
I've attached my VI for your reference.
Cheers!
in data 03-24-2011 08:43 AM
@drog wrote:
I had a similar project. My Arduino continuously sends room temperature readings as part of a text string and I wrote a VI to buffer the text, extract the temp digits, display the value and graph the data.
I've attached my VI for your reference.
Cheers!
Is there a reason why you use "insert into array" in stead of build array (concatenate)???
in data 03-24-2011 09:19 AM
No real reason. I probably should have used the Build Array function for consistency.
Anyone know if there is an advantage to using the "Build Array" vs. "Insert into Array" functions.
Cheers
in data 03-25-2011 03:29 AM
Insert into array is normally used to "insert" a value into a array at a certain place. not at the end, allthough it does work.
Build array is used to add a value (or array) to an array.
in data 04-05-2011 03:04 PM
Hey, I am using LabVIEW v 8.6 and would like to view this VI but cannot open it... could you upload a copy saved as an 8.6 file? Thanks