Control poke peripheral
The Mice Poke is a nose poke peripheral for the Behavior device which uses an infrared beam sensor for poke detection. It also includes cue LEDs and an optional solenoid valve for controlled liquid delivery, typically used for rewards. Refer to the connections article to set up the hardware connection on poke port P0, which we will use for the rest of these examples.
This article covers how to visualize poke events, debounce noisy inputs, control the cue LEDs, and dispense liquid rewards with the Mice Poke peripheral in Bonsai.
The complete workflow is shown below. Copy and paste it into Bonsai to get started immediately, or build each section by following the step-by-step instructions in the following sections.
Visualize poke events
Beam breaks in the Mice Poke peripheral are reported as digital input events. The three poke 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, block and unblock the infrared beam on the Mice Poke peripheral briefly. 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 nose 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.
Note
PokeInputFilter applies only to the poke port inputs; DI3 events are not filtered.
Control poke LEDs
Each poke port carries an LED control line (DOPort0 - DOPort2) that controls the two onboard LEDs, and the additional LED output on the screw terminal block. The LED line 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 LEDs on and D to turn it off. See Control digital outputs for other methods to control the LEDs, such as with a toggle, pulse mode, or timer.
Deliver rewards on poke
Each poke port carries a 12 V valve supply line for a solenoid valve that gates liquid delivery. The workflow below enables pulse mode on the valve output and configures the pulse duration, which can be calibrated to adjust the volume of liquid dispensed. The second branch of the workflow implements closed-loop reward delivery in Bonsai: for every poke at P0, a liquid reward is immediately delivered 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 acts on every output of the Behavior device. Any output not specified in the payload will have its pulse mode disabled. Make sure to list every output that should keep pulse mode (e.g. DO0, SupplyPort0).
Documentation for release v3.4.0