Seamless instrument control with ArCOM

Share this on: 

Friday, 10-Jun-16 09:29:27 PDT


Introducing ArCOM.

If you are developing a custom electronic device to study some aspect of brain function, an Arduino has probably made its way into your assay. In fact, it is not uncommon for an advanced custom setup to have 5 or 6 Arduinos working in concert, to interface different sensors and actuators with computers and neural data acquitision hardware.

Arduino typically exchanges data with other computers using a UART serial interface. When sending via USB, the UART stream is formatted for USB transfer, and unpacked by software on the receiving end. However, Arduino's built-in functions for sending and receiving data are limited to byte-wise transfer. This creates a problem - if you want to send a 32-bit unsigned integer (for instance, a timestamp captured with microsecond precision), you first have to convert the integer into an array of 4 bytes, and send them in the correct order expected by the receiving computer. When receiving the same value over UART, you have to write a loop to read 4 bytes, and do bit-shifting and type-casting operations to recreate the original 32-bit value. More often, new programmers use string-wise serial print functions (Serial.println, and fprintf, fscanf in MATLAB), incurring a speed penalty and making port settings more difficult to configure for cross-platform deployment.

On the MATLAB or Octave side, this operation is supposed to be much simpler - a single MATLAB built-in command allows you to read and write almost any datatype (or even an array of data) to the serial port. Unfortunately, MATLAB's built-in serial port interface communicates through a Java abstraction layer, adding significantly to latency and decreasing transfer speed. To improve on this, as part of their open-source software toolset for psychophysics, PsychToolbox provides a low-latency serial interface: IOPort. Unfortunately, both IOPort and the Octave serial interface only have byte-wise transfer functions, making them more challenging for beginners to use.

Enter Sanworks ArCOM. ArCOM is a free and open library for Arduino, with a counterpart .m file interface for MATLAB and GNU Octave. It provides single line commands to send and receive 8, 16 or 32 bit signed and unsigned integers and char types. On both sides, one line of code sends or receives either a single value, or an array of data. On the MATLAB side, ArCOM provides a single syntax to send data through MATLAB/Java, Psychtoolbox or Octave serial interfaces, increasing cross-platform usability of your code. On the Arduino side, it uses a union data structure for type conversion, outperforming bit-shifting strategies.

We intend future updates to add support for Python, and to wrap Arduino's SPI and I2C interfaces. Our first attempt to add floating point types (single, double) proved challenging, and may require a more complex type conversion algorithm to ensure correct representation in Arduino. When possible, we recommend converting floats to ints for transfer (multiply by 10^yourprecision and divide by the same on the other side).

As an Arduino/MATLAB developer, ArCOM is the best thing since sliced bread. It is minimal, light-weight and designed to accelerate your research. We hope you find it useful! Please report any bugs or feature requests to admin@sanworks.io





Comments (0)