The Arduino USB boards provide an easy way to communicate with an arbitrary electrical hardware by a computer USB port. The attached hardware may include LEDs, motors, sensors, response buttons, etc. Current Arduino models feature an USB interface, analog input pins and digital I/O pins and a programmable processor. Arduino boards can be used as low-cost DAQ cards in many research scenarios. This post describes how to communicate with an Arduino card in EventIDE. Consider, for example, that you want to control a LED attached to the digital pin 13 on an Arduino board.
First, you will need to prepare the following tools:
- An Arduino board, connected to your computer by USB
- The official Arduino IDE and drivers (download from here)
- a LED, attached to the pin 13 and ground pin on the board
Upon installation the Arduino driver creates a new COM port that can be used to communicate with the board. There are no predefined serial commands, but the board can easily programmed to listen and execute custom user commands.
Run the Arduino IDE and select the Arduino serial port in the Tools menu:
Then paste the following script into Arduino editor:
Once you upload this script to the board (via the Upload button), it begins to continuously listen the data arriving via the serial port. The script recognizes two string commands, “ON#” and “OFF#”, that switch the LED on and off. Note the commands must be terminated with ‘#’ character.
Start EventIDE now and add a new Serial Port element. Leave the element properties with default values, except for the Port Name, which has to point to the Arduino port, COM7 in this example.
To test communication, type a command, ON# or OFF#, in a field of the ‘Output Buffer’ property of the Serial port element and press the run button next to the ‘Test Output’ property. The typed command will be send to the Adriano script, which, in turn, will switch the attached LED.
At runtime you can send an instant command to Arduino with a simple code, if you create proxy variables, linked to the ‘Output Buffer’ and ‘Send Now’ properties:
Using a similar approach, you can write an Arduino script that reads pin data from a board and sends it into the Adriano serial port. The Serial port element in EventIDE is also able to read incoming port data, when the element works in the input modes.