06-11-2023 04:34 AM
Hi, I have connected 2 Arduino Unos with each other. The sender Arduino is connected to push buttons and the receiver Arduino is connected to PC. Both the arduinos are connected via the RS485 TTL module. I have to create a Labview VI for data acquisition from the push buttons i.e the states of the buttons should be displayed on Labview front panel via the RS485 serial communication protocol. I am able to send 20 bytes of data (160 bits) from the sender to the receiver and the same is displayed on Labview. The push buttons are mapped to specific bits of the 20 bytes, the mapping is as follows:
1st bit of 5th byte |
Numeric push button “1” |
2nd bit of 5th byte |
Numeric push button “4” |
3rd bit of 5th byte |
Numeric push button “7” |
4th bit of 5th byte |
Push button “MAN” |
1st bit of 7th byte |
Numeric push button “2” |
2nd bit of 7th byte |
Numeric push button “5” |
3rd bit of 7th byte |
Numeric push button “8” |
4th bit of 7th byte |
Numeric push button “0” |
1st bit of 9th byte |
Numeric push button “3” |
2nd bit of 9th byte |
Numeric push button “6” |
3rd bit of 9th byte |
Numeric push button “9” |
4th bit of 9th byte |
Push button “ENT” |
1st bit of 11th byte |
SQL Switch -OFF |
2nd bit of 11th byte |
SQL Switch -ACKN |
1st bit of 14th byte |
Mode Selection Switch -SET |
3rd bit of 14th byte |
Mode Selection Switch -ADF |
2nd bit of 15th byte |
Mode Selection Switch -ZRO |
3rd bit of 15th byte |
Mode Selection Switch –OFF |
4th bit of 15th byte |
Mode Selection Switch –TR+G |
In the response window of my VI, the specific bits are changing with the press of the buttons but i need to display LED's on the front panel corrresponding to the buttons. I have converted the incoming string to array but when i attach an LED indicator to the 33, 34th bit then the LED doesn't turn on/off with the button push. Any help would be appreciated.
The arduino code for sender is:
06-11-2023 10:30 AM
Sigh. I got a reputation in the Forums a few years ago for "whining" (yes, I admit it) about Forum posts that had pieces of LabVIEW block Diagrams posted, but no VIs. I remember saying "Suppose I asked you for help with a C++ program and sent you a picture of the 1000 lines of code -- would you say "Thank you", or yell at me and say "Why didn't you send the program, itself" (I don't use C or C++, so I can't remember if its a .c file or what).
Well, you've sent effectively a "picture" of Arduino code, double-spaced, that takes about 150 lines. Why not send the files themselves, which we can print or "condense" (by getting rid of 75 blank lines)?
I looked at your LabVIEW code. Have you read any of the numerous posts on the Forum (or posts on the Web) from @crossrulz on the proper way to set up LabVIEW to do communication using VISA? In response to a command to "Send me some data", your device generally sends a string of characters that you read "all at once" (by reading, say, 500 characters, more than you expect because you have (correctly) configured VISA to use a Termination character), and then parse the String (I suggest using the Scan from String function to locate the "numeric data of interest" and read it as a decimal, a float, a Boolean, whatever it is, and ignore the rest. Your VISA string probably has only 4-8 "real" data elements, probably most of the decimals, so your Scan from String will probably produce 4 I32s. rather than the monstrous Index Array function you used.
Bob Schor
06-11-2023 02:06 PM
@AbdullahWasif wrote:
I have converted the incoming string to array but when i attach an LED indicator to the 33, 34th bit then the LED doesn't turn on/off with the button push. Any help would be appreciated.
Have you confirmed that there is actually a "1" in these two positions?
Can you think of a way to code this that makes it easier to identify what is going on? I guess that solving the problem will be easier when you remove the giant index array block.
06-11-2023 02:35 PM
You have two Posts that have the same poorly-designed sub-VI trying to do the same thing -- get a (text, I presume) response from an Arduino (though you fail to show the commands that, when doing VISA communication, you usually send to a Serial port to get it to send you strings of information that you subsequently parse and interpret).
Why don't you provide us with more information on your Project? Show us the String you expect to get from the Arduino, including what you need to do to get this string (it may be that you "do nothing", it just spits a string out once every N seconds, but do tell us that!). Parsing a String to get out what LEDs it says to turn on should be fairly easy, especially if you learn how to use "Scan from String" -- it would be a single Function following the VISA Read, and would give you (as its output) however many Booleans to tell it to read. No need for Index Array.
But you need to tell us what you are trying to do, and provide examples of your expected data strings.
Bob Schor
06-12-2023 11:34 AM - edited 06-12-2023 11:35 AM
Yes, it does change to a "1" when i press the button. I've attached a screenshot. As you can see in the picture, there are "1" on 33, 34, 36 and 48th bit when i press a button but state of the LED doesn't change
06-12-2023 11:52 AM
Sorry about the arduino code. I don't know what i was thinking. I've attached the arduino codes here (as a zip file) cause .ino format is not supported. I've tried the Scan from string function and set it's scan sequence to scan binary integer. Can't seem to make it work.
06-12-2023 01:29 PM
@AbdullahWasif wrote:
As you can see in the picture ...
I'm sorry, but I can't see it in the picture. I could go out of my way to manually, painstakingly count the zeroes in your screenshot, three times at least to make sure I did not miscount. I am, however, very bad at these kind of tasks and don't like doing them. Can you help me seeing it at a glance, without making me count?
Try adding an indicator to the string-to-array function. I think your string-to-array function does something different to what you think it is doing.