Skip to content

Modules

Beyond solenoid valves, LEDs and TTL pulses, it's hard to anticipate what kinds of outputs Bpod will need to control in future experiments.

As a general expansion framework, 3 (or more) of the serial ports of the state machine's microcontroller are exposed to enable Sanworks and users to build Arduino-based modules.

Module documentation

Each module has three pieces of documentation.

  1. Hardware: located in Assembly > Modules, hardware specifications and the bill of materials required for construction.
  2. Serial interface: located in Modules > Serial Interfaces, USB/serial port communication specifications
  3. Plugin: located in Modules > Plugins, plugins/class/API for programmatic module interaction

In most cases, configuration of a module at the start of a session involves the use of the plugin, while actions performed during a trial are triggered using serial messages from the state machine.

General explanation of module architecture

flowchart

subgraph MATLAB
arcom(ArCOM Object)
modulefunction(Module Object)
end

statemachine(Bpod State Machine\nUART Serial Port)

subgraph Module

moduleserial(ArCOM interface)
arduino(Arduino-based processor)
end

modulefunction <--> arcom
statemachine <-- Serial message via CAT5e --> moduleserial
arcom <-- Serial message via USB --> moduleserial
moduleserial <-- Information exchange --> arduino

ArCOM is a library for Arduino developed by Sanworks to simplify data transaction between Arduinos with other Arduinos and computers. Rather than working directly in binary, ArCOM makes it easy to send and receive bytes from a module. The rationale for its development can be found here.

For example, modules that play a stimulus are often sent two bytes, byte 'P' to signify that the instruction is to play, and a second byte to specify which pre-loaded stimulus to play (e.g. ['P' 1]). Communication of all forms is performed using ArCOM, and the plugins (which are classes) are used to make this easily accessible within the protocol file's programming language.

Bytes can be sent to the module using both the USB connection with the plugin (which is actually just utilising the ArCOM object), and via the state machine serial port.

To understand this sequence more closely, read the example in-depth explanation for the Rotary Encoder Module.

UART communication description

  • The UART serial ports are indicated on the enclosure as RJ45 ethernet jacks labeled "Modules" 1-N.
  • The ports are configured to communicate with other microcontrollers at 1.3125Mb/s
  • The state machine sends UART serial transmissions to modules using an RS485 IC at each end of the ethernet cable. This employs differential signaling over the Ethernet cable's twisted wire pairs, to make the digital messages more robust against noise.

Building your own module/integrating existing Arduino system

The Bpod Arduino Shield is a simple circuit board used to interface the serial ports on the state machine and the UART on Arduino boards (M0, Zero, Due, Leonardo, Adafruit MetroM4).

General pointers for building a module can be found in the guide to building your own module. It will help to become familiar with the Arduino language, an excellent intro for which is located here.