06-08-2023 01:36 PM
Hi, i have 5 push buttons for which i have to make a GUI to display their states. I have connected 2 Arduino Unos with each other. The sender arduino is connected to the push buttons via pin 2,3 ,4,5 and 6. The Receiver arduino is connected to PC. Both the arduinos are connected via the RS485 TTL module. Have to create a serial RS485 communication prototype. The button status is displayed on the serial monitor and as well as on labview (picture attached) but i need to create labview VI in which there are 5 leds on the front panel and the data received from the arduino should turn on the led in labview. The labview VI is attached as well. I have taken the continuous read and write VI and removed the other blocks.
Arduino code for sender is:
Receiver arduino code is:
Solved! Go to Solution.
06-08-2023 02:24 PM - edited 06-08-2023 02:24 PM
1. Let's simplify things on the data going to the PC. I would recommend changing it to this:
void printButtonStates() {
Serial.print(String(button1 ? "1 " : "0 "));
Serial.print(String(button2 ? "1 " : "0 "));
Serial.print(String(button3 ? "1 " : "0 "));
Serial.print(String(button4 ? "1 " : "0 "));
Serial.println(String(button5 ? "1" : "0"));
}
This will output a simple space delimited string with each button's value corresponding to a single character.
2. You are using all the defaults to the serial port, so get rid of the cluster handling the serial settings.
3. You should be constantly getting data, so no need for the Read button or the wait in the loop.
4. With the format I recommend above, you can just use the Spreadsheet String To Array primitive to get an array of numeric values and the Not Equal To Zero to turn it into an array of Booleans.
06-08-2023 02:24 PM - edited 06-08-2023 02:43 PM
First off I recommend you watch this video: VIWeek 2020/Proper way to communicate over serial
Second I would rethink your approach as you are going to have to parse all that text in LabVIEW to determine the button status.
Unless the serial data must be "human readable" I would just send a 1 or 0 for each button.
10010 would be sw1 closed, sw2 open, sw3 open, sw4 closed, sw5 open.
That would be simple to parse in LabVIEW.
EDIT: forget the commas, look how easy it is to parse this string...
06-09-2023 12:46 PM
Thanks so much crossrulz. Your approach is working like a charm. One more problem that i have is that i have to send 20 bytes of data from sender arduino to receiver arduino. And there are 3 push buttons, 1 three position toggle switch, 1 potentio knob and one 5 position switch. It's basically an aircraft radio control panel (let me attach a picture). the buttons and switches are mapped to specific bits of the 20 bytes sent. the mapping is is attached as well. What approach should i follow for this?
06-09-2023 02:51 PM
The arduino code for the sender is: