Table of Contents

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.

Detect Pokes

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.

Detect Pokes Visualize Events

  • Insert a SubscribeSubject operator named Behavior Events.
  • Insert a Parse operator and configure the Register property to TimestampedDigitalInputState.
  • Insert a VisualizerWindow operator.

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.

Detect Pokes Input Filter

  • Insert a KeyDown operator and set the Filter property to A.
  • Insert a CreateMessage operator and configure the following properties:
    • Payload - Select PokeInputFilterPayload.
    • PokeInputFilter - Set the filter time to the refractory period in ms (e.g. 5).
  • Insert a MulticastSubject operator named Behavior 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:

Detect Pokes Drive LED

  • Insert a KeyDown operator and set the Filter property to S.
  • Insert a CreateMessage operator and configure the following properties:
    • Payload - Select OutputSetPayload.
    • OutputSet - Select the line to turn on (e.g. DOPort0).
  • Insert a MulticastSubject operator named Behavior Commands.

In a separate branch:

  • Insert a KeyDown operator and set the Filter property to D.
  • Insert a CreateMessage operator and configure the following properties:
    • Payload - Select OutputClearPayload.
    • OutputClear - Select the line to turn off (e.g. DOPort0).
  • Insert a MulticastSubject operator named Behavior 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.

Detect Pokes Deliver Rewards

  • Insert a KeyDown operator and set the Filter property to F.
  • Insert a CreateMessage operator and configure the following properties:
    • Payload - Select OutputPulseEnablePayload.
    • OutputPulseEnable - Select the valve output to enable pulse mode on (e.g. SupplyPort0).
  • Insert a MulticastSubject operator named Behavior Commands.
  • Insert a CreateMessage operator and configure the following properties:
    • Payload - Select PulseSupplyPort0Payload.
    • PulseSupplyPort0 - Set the valve opening duration in ms (e.g. 15).
  • Insert a MulticastSubject operator named Behavior Commands.

In a separate branch:

  • Insert a SubscribeSubject operator named Behavior Events.
  • Insert a Parse operator and configure the Register property to DigitalInputState.
  • Insert a HasFlag operator and set the Value property to DIPort0. This operator will generate a boolean value (e.g. True) if it detects a beam break that matches that pin.
  • Insert a Condition operator, leaving its inner workflow at the default. This operator lets through only True elements corresponding to beam breaks at P0, which are used to trigger the next command.
  • Insert a CreateMessage operator and configure the following properties:
    • Payload - Select OutputSetPayload.
    • OutputSet - Select the valve delivery line to turn on (e.g. SupplyPort0 on P0).
  • Insert a MulticastSubject operator named Behavior 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