02-02-2015 08:25 PM
HI I amhaving trouble with getting my arduino cummunicationg with labview over bluetooth, And I cannot quite pin point the root cause of the problem, please read on.
Aim: To simultaneously read the values from pin A0 and pin D8 on the Arduino UNO over Bluetooth to LabVIEW. And display them on the front panel.
It is important to note I achieved this many weeks ago but an intermittent problem has crept in somewhere and now I’m trying to debug it.
Method: I have uploaded the LIFA base firmware to my Arduino. The Bluetooth device I am using is the SparkFun Bluetooth Mate Silver module (https://www.sparkfun.com/products/12576), I then followed the instructions on the on to connect it: http://digital.ni.com/public.nsf/allkb/D86D6E2927F9C37A8625788E0077E86B
My Laptop is a Toshiba Satellite L755 with built-in Bluetooth
Code
I took the Arduino Analog read pin example from labview and reconfigured it to work over Bluetooth so all I changed when moving to the Bluetooth connection was the following setting;
I have also built a similar loop to read the input to pin D8.
Please see labview VI below and attached the file below.
The Problem: It works quite well for a period of time (up to 20minutes sometimes will give erroneous readings from the outset) i.e. A0 reads the values correctly (somewhere between 0V-5V) from the potentiometer which I am varying and D8 will read either depending on the into I give it. But then the values displayed on the front panel may jump to anything between 0-500 in some cases and will fluctuate in that range even when I am not varying the potentiometer. (Please note everything works fine when wired). And the values read from displayed from pin D8 will no longer read 0 or 1 but will be reading up in the hundreds like the A0 values. Sometimes it will come back and read correctly again but more often than not it won’t. See the below image the waveform graph should display the digital pin output but it is seeing values up to 200V apparently!
The area circled in red in the picture below seems to be where I can see these excessively high values occurring from. As can been seen there is a warning message (ok 1073676294), which on this link (http://digital.ni.com/public.nsf/3efedde4322fef19862567740067f3cc/c96c84c922dc3f978625632500482f78?O... ) I am told it is a good warning as it is a positive number!.
The block indicted with the green arrow above is an Index array function and the block to the right joins (concatenates) the numbers in the array, at some point the values in the Index array function seem to get swapped around and the value outputted will be very high i.e. a lot higher than 5V for the digital input.
Attempts to fix:
Any suggestions would be greatly appreciated at stage.
I will do my best to answer any questions.
Thanks in advance
Also below is code to read data over bluetooth from pin A0 on the arduino IDE.
/* Example Bluetooth Serial Passthrough Sketch by: Jim Lindblom SparkFun Electronics date: February 26, 2013 license: Public domain This example sketch converts an RN-42 bluetooth module to communicate at 9600 bps (from 115200), and passes any serial data between Serial Monitor and bluetooth module. */ #include <SoftwareSerial.h> int bluetoothTx = 2; // TX-O pin of bluetooth mate, Arduino D2 int bluetoothRx = 3; // RX-I pin of bluetooth mate, Arduino D3 int analogPin = A0; // potentiometer wiper (middle terminal) connected to analog pin 3 int val = 0; // variable to store the value read SoftwareSerial bluetooth(bluetoothTx, bluetoothRx); void setup() { Serial.begin(9600); // Begin the serial monitor at 9600bps bluetooth.begin(115200); // The Bluetooth Mate defaults to 115200bps bluetooth.print("$"); // Print three times individually bluetooth.print("$"); bluetooth.print("$"); // Enter command mode delay(100); // Short delay, wait for the Mate to send back CMD bluetooth.println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity // 115200 can be too fast at times for NewSoftSerial to relay the data reliably bluetooth.begin(9600); // Start bluetooth serial at 9600 } void loop() { if(bluetooth.available()) // If the bluetooth sent any characters { // Send any characters the bluetooth prints to the serial monitor // Just informational Serial.print((char)bluetooth.read()); } // Simply read the value and print it out via println. This will send the value as ASCII int analogValue = analogRead(analogPin); bluetooth.println(analogValue); // Also prints it to the serial monitor, just informational Serial.println(analogValue); }
02-03-2015 06:02 PM
I don't have your bluetooth module, but it seems odd to me that you have 2 connections to your VI over the bluetooth module, and run them over 2 separate loops to get your analog and digital reads. Wouldn't it make more sense to use one connection and combine your loops into one and poll the analog and digital pins sequentially? Then you can read errors on your digital pin reads too.
02-03-2015 06:02 PM - edited 02-03-2015 06:03 PM
I don't have your bluetooth module, but it seems odd to me that you have 2 connections to your VI over the bluetooth module, and run them over 2 separate loops to get your analog and digital reads. Wouldn't it make more sense to use one connection and combine your loops into one and poll the analog and digital pins sequentially? Then you can read errors on your digital pin reads too.
sorry - my mouse is faster than the internet today!
02-06-2015 03:31 AM
Hi Dan_bmg,
Have you tried looking into using LINX for Arduino ?
"LINX - LVH"
http://sine.ni.com/nips/cds/view/p/lang/en/nid/212478
I believe it was relased recently and is available in the VIPM.
It will be a more up to date version Arduino of drivers.
Regards
Art
02-10-2015 07:41 PM
Hi qzerror , thanks for your reply.
I was not entirely sure "poll the analog and digital pins sequentially". I have attached a VI of what I think you meant for me to try.
However the error still presists with this VI, see image below.
However my forementioned setup did work previously and I'am in the debugging process. (With no end in sight!)
Any further suggestions/ help you could provide would be much appreciated.
Thanks.
02-10-2015 08:14 PM
Hi ArtG
Thanks for your help,
I am looking into LINX, I set it up to read an analog pin (A0) over USB.
This seems to work fine.
But do you have any information on how to communicate this pin reading over bluetooth?
I have uploaded the firmware for serial commnication (the only option) to my arduino.
I have the bluetooth module( https://www.sparkfun.com/products/12576 ) connected to my arduino and paried with my PC, it shows as COM40 in device manager.
I assumed AI channel corresponds to the Analog pin on the arduino (A0 in my case)
But I get the following errror.
Do you know how to ensure labview can read the data from com40?
Is there a change to be made ot firmware?
Any further suggestions or help will be much appreciated.
Thanks
02-11-2015 09:28 AM
Yep, that's what I was suggesting except the configure digital pin VI should be moved to before the while loop -- you only need to configure this once.
Does this spurious data issue happen to both the analog and digital signals together? If that's the case, it would seem your reads are getting mixed up bits and that messes up your conversion. Perhaps a small delay will help settle the port between reads, or you need to flush the serial buffer to get rid of the bad data.
02-19-2015 03:24 AM
Hi Dan,
Did you set up the firmware the following way?
"Getting Started with LINX"
https://labviewhacker.com/doku.php?id=learn:libraries:linx:getting_started
Have you seen this Knowledge Based article?
"Why Do I Get Error 5003 When Using the LabVIEW Interface for Arduino?"
http://digital.ni.com/public.nsf/allkb/8D47D6C48D0ABA0A86257884007035F1
This may occur due to different reasons, including using the abort button.
Regards,
11-03-2015 05:46 AM
can you convert vi 2013 to 2012. thankyou verymuch
12-02-2015 02:14 PM
Someone know how to connect bluetooth with arduino??