05-21-2021 08:41 AM
I'm working on a project using an Arduino (well more specifically Elegoo Mega 2560 R3) and NI Windows CVI. I used OpenComConfig() to enable the device, but I don't know how to proceed. Is there a guide to CVI and Arduino? I see that there's an example project for serial transmission, but this doesn't really explain how things are done and why. If there isn't a guide, could someone explain how the board functions in general? Things like how data is stored, how messages are transmitted, and how to provide power to different ports.
Solved! Go to Solution.
05-23-2021 05:07 AM
An Arduino is simply an computer device too. Your Windows PC doesn’t do much if you don’t install specific applications or write them in one of the many possible IDEs. Arduino is not different. You typically write an INO program in a C style syntax in the Arduino IDE. This program calls functions to control the different IO and also monitor the serial port for commands and respond to them.
There is no specific standardized format like in an off the shelf measurement device that you can buy but the protocol is whatever your Arduino program implements.
05-24-2021 07:59 AM
Thank you for your reply. If I wanted to have an Arduino operated by a CVI GUI, how would the Arduino code interact with the CVI code?
05-24-2021 08:52 AM
By receiving commands over the serial port and sending answers to them. So your Ardiuno program will open the serial port and wait for data on it. When something comes in it decodes the command, does the according action and then sends the response back.
In your CVI program you open the COM port to which your Arduino is connected, send commands (that your Arduino program must be programmed to understand) and then wait for the answer.
05-24-2021 09:07 AM
I think I follow, but I'd appreciate specifics if you can as I'm new to both Arduino and CVI. What would the commands to the COM port look like and how might the Arduino be programmed to understand them?
05-25-2021 09:48 AM
This is not an easy question to reply to!
Basically you need to develop a communications protocol between the Arduino box and a PC which runs a CVI application: the are no specifics on how to develop this and as many valid solutions as the persons that may think to it! You could think to this as an exchange of messages between the parts involved: one possible framework maybe that the CVI app asks for a measurement with a message formatted some way and the Arduino replies with the measurements using a message formatted some other way.
Just as an example, take an instrument that uses SCPI and look at the manual: this is probably one of the easiest protocols that you may want to take suggestions from.
Basic elements:
- both parts must use the same serial parameters (speed and so on)
On the PC/CVI side:
- You must design proper query message(s) considering if you want to ask one or more measurements
- Once the query is sent:
- Wait for the reply (define a proper timeout)
- Validate and interpret an incoming reply
On the Arduino side:
- You must validate the incoming message
- You must prepare a valid response depending on the query
- Then you must write out the reply
As per the code involved, the basic serial example will show you how to handle the serial communications on the PC. On the Arduino side I'm sure you can find several equivalent examples in the specialized sites.
05-26-2021 02:35 AM
Also, while not directly relevant on the PC side, you can also look for the Additional NI Products->Hobbyist Toolkit forum on here. It is for Lynx for LabVIEW, a LabVIEW Toolkit to use Raspberry Pi, Beaglebone Black and Arduino based devices, but there are some examples out there that also show how to do custom firmware on the Arduino to directly communicate from LabVIEW with them. The LabVIEW side won't be really relevant for you but the Arduino side works exactly the same no matter if you use LabVIEW, Visual Basic, Python or LabWindows/CVI on the host side.