Control Poke Peripheral
The Mice Poke is a specialized nose poke peripheral for the Behavior board which combines an infrared beam sensor for poke detection, cue LEDs, and a solenoid valve for reward delivery. Refer to the connections article to set up the hardware connection on peripheral port P0, which we will use for the rest of these examples.
This article covers how to visualize poke events, debounce noisy inputs, drive the cue LED, and deliver rewards with the Mice Poke peripheral 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 Poke Events
Beam breaks in the Mice Poke peripheral are reported as digital input events. The three peripheral ports P0–P2 are represented as DIPort0 - DIPort2 in the DigitalInputState event register.
- Insert a
SubscribeSubjectoperator namedBehavior Events. - Insert a
Parseoperator and configure theRegisterproperty toTimestampedDigitalInputState. - Insert a
VisualizerWindowoperator.
Run the workflow and block the infrared beam on the Mice Poke peripheral. The visualizer will display:
DIPort0@3.213504
None@3.513823
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 beam breaks and beam restores generate an event, so None marks a poke exit.
Configure Input Filter
A single poke can generate a burst of rapid transitions, for example, when the snout hovers at the edge of the infrared beam. Use the PokeInputFilter register to set a refractory period in milliseconds. After each reported transition, further transitions on that port are ignored for the set time.
- Insert a
KeyDownoperator and set theFilterproperty toA. - Insert a
CreateMessageoperator and configure the following properties:Payload- SelectPokeInputFilterPayload.PokeInputFilter- Set the filter time to the refractory period in ms (e.g.5).
- Insert a
MulticastSubjectoperator namedBehavior Commands.
Run the workflow and press A. Rapid repeated transitions within 5 ms of a poke event no longer generate events. Set the value to 0 to disable the filter. The default filter time is 1 ms.
Tip
The filter is blind to the cause of a transition, so values much longer than the animal's fastest re-entry will also ignore genuine consecutive pokes.
Drive the Poke LED
Each peripheral port carries an LED drive line (DOPort0 - DOPort2). The LED is controlled like any other digital output. For instance, you can turn it on and off with the OutputSet and OutputClear registers:
- Insert a
KeyDownoperator and set theFilterproperty toS. - Insert a
CreateMessageoperator and configure the following properties:Payload- SelectOutputSetPayload.OutputSet- Select the line to turn on (e.g.DOPort0).
- Insert a
MulticastSubjectoperator namedBehavior Commands.
In a separate branch:
- Insert a
KeyDownoperator and set theFilterproperty toD. - Insert a
CreateMessageoperator and configure the following properties:Payload- SelectOutputClearPayload.OutputClear- Select the line to turn off (e.g.DOPort0).
- Insert a
MulticastSubjectoperator namedBehavior Commands.
Run the workflow, then press S to turn the P0 poke LED on and D to turn it off. See Control Digital Outputs for other methods to control the LED.
Deliver Rewards on Poke
Each peripheral port carries a 12 V valve drive line for a solenoid valve that gates liquid reward delivery. The workflow below enables pulse mode on the valve output and configures the pulse duration, which can be calibrated to adjust the reward volume. It then closes the loop in Bonsai where every poke at P0 immediately triggers a reward at the same port.
- Insert a
KeyDownoperator and set theFilterproperty toF. - Insert a
CreateMessageoperator and configure the following properties:Payload- SelectOutputPulseEnablePayload.OutputPulseEnable- Select the valve output to enable pulse mode on (e.g.SupplyPort0).
- Insert a
MulticastSubjectoperator namedBehavior Commands. - Insert a
CreateMessageoperator and configure the following properties:Payload- SelectPulseSupplyPort0Payload.PulseSupplyPort0- Set the valve opening duration in ms (e.g.15).
- Insert a
MulticastSubjectoperator namedBehavior Commands.
In a separate branch:
- Insert a
SubscribeSubjectoperator namedBehavior Events. - Insert a
Parseoperator and configure theRegisterproperty toDigitalInputState. - Insert a
HasFlagoperator and set theValueproperty toDIPort0. This operator will generate a boolean value (e.g.True) if it detects a beam break that matches that pin. - Insert a
Conditionoperator, leaving its inner workflow at the default. This operator lets through onlyTrueelements corresponding to beam breaks at P0, which are used to trigger the next command. - Insert a
CreateMessageoperator and configure the following properties:Payload- SelectOutputSetPayload.OutputSet- Select the valve delivery line to turn on (e.g.SupplyPort0on P0).
- Insert a
MulticastSubjectoperator namedBehavior Commands.
Run the workflow, press F once to configure the valve pulse, then block the infrared beam on the P0 poke. The valve will open for 15 ms and close on its own, delivering one reward per poke.
Warning
OutputPulseEnable is a selection mask over all digital outputs. Any output not selected in the payload has its pulse mode disabled. Make sure to list every output that should keep pulse mode (e.g. DO0, SupplyPort0).
Last updated with:
Hardware v2.1
Firmware v3.3
Bonsai Package v0.2