Read Digital Inputs
The Behavior board has one digital input that is accessible without extra hardware: DI3 on the Input connector (hardware v2.0 or later boards only). Each peripheral port also carries a general-purpose DI line, and a DIO line that can be used as an active-low digital input. Refer to the connections article to set up the hardware connection on DI3 or DIO0, which we will use for the rest of these examples.
This article covers how to visualize the digital input events and read the peripheral port DIO lines as a digital input in Bonsai.
The complete workflow is shown below. Copy and paste it into Bonsai or build each section by following the step-by-step instructions below.
Note
If you need more digital inputs or outputs, the Breakout extension board makes the peripheral ports' pins available as regular screw-terminal inputs and outputs.
Visualize Digital Input Events
The Behavior board broadcasts changes on its digital input lines as DigitalInputState event messages. In addition to DI3, this register also reports events from the DI lines on the peripheral ports P0–P2 (represented as DIPort0–DIPort2 in Bonsai), such as poke events from the Mice Poke peripheral or other digital inputs connected to the Breakout board. The workflow below subscribes, parses, and displays them in a visualizer window.
- Insert a
SubscribeSubjectoperator namedBehavior Events. - Insert a
Parseoperator and configure theRegisterproperty toTimestampedDigitalInputState. - Insert a
VisualizerWindowoperator.
Run the workflow and drive the DI3 line high. The visualizer will display:
DI3@12.001504
None@12.301823
The first value is the payload, listing the digital inputs that are currently active, and the second value is the timestamp on the device clock. Both rising and falling edges generate an event, so None marks the moment the line returned low.
Note
The PokeInputFilter debounce applies only to the peripheral port inputs; DI3 events are not filtered.
Visualize Port DIO Events
In the current firmware (v3.3) the DIO line acts only as an active-low digital input. It idles high at 5 V through onboard pull-ups, and the connected device must actively drive it low. Changes on the DIO lines are broadcast in a different register, PortDIOStateEvent, which can be visualized in the same way as the digital inputs:
- Insert a
SubscribeSubjectoperator namedBehavior Events. - Insert a
Parseoperator and configure theRegisterproperty toTimestampedPortDIOStateEvent. - Insert a
VisualizerWindowoperator.
Run the workflow and drive the DIO line on P0 low. The visualizer will display:
DIO0, DIO1, DIO2@20.154016
DIO1, DIO2@20.575872
The payload lists the DIO lines that are currently high. Since the lines idle high, driving DIO0 low removes it from the list, and releasing the line adds it back.
Last updated with:
Hardware v2.1
Firmware v3.3
Bonsai Package v0.2