bpod rotary encoder tutorial

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
bpod rotary encoder tutorial
Hi guys 
I am a bit lost with the rotary encoder module. I am currently trying to set up thresholds for left and right movement and trigger specific states for this threshold, but so far no luck.

Can I define both +ticks and -ticks for left and right?

Does anybody have a more detailed guide or a script that I can use as a guide and if yes can you point me in the right direction?

Best regards Max
Hi Max,

The RotaryEncoderModule class (documented here) has a field for thresholds. Units are exposed in degrees, which are mapped to tics behind the scenes. Setting thresholds of - and + 20 degrees with respect to the starting position is then:

R.thresholds = [-20 20];

These threshold crossings generate RotaryEncoder1_1 and RotaryEncoder1_2 events respectively.
Once thresholds have been crossed, they need to be reset before they can be crossed again.
You can set them from MATLAB with the enableThresholds() method of the RotaryEncoderModule class, or directly from the state machine by putting {'RotaryEncoder1', 'E'} in the desired state's output actions (also see the serial interface documentation, here).

Please let me know if you run into any issues.

Hi Thanks for the reply, I should have mentioned that I am trying to get it to work with python, which seems to be a bit more complicated.

So far I could manage to initialize the rotary encoder and set the thresholds, but I am not sure, if they are set correctly and I have no idea of knowing how to check it.
If I try to access the two set thresholds as a state change condition

           "RotaryEncoder1_1": "next_state",
, I don't get any changes. 

This is my code:

from pybpodapi.bpod import Bpod

from pybpodapi.state_machine import StateMachine

#from rotary_encoder import MyRotaryEncoder
from pybpod_rotaryencoder_module.module_api import RotaryEncoderModule

#import inspect

bpod = Bpod()


rotary_encoder.set_thresholds([-5, 5])

rotary_encoder.enable_thresholds([True, True, False, False, False, False, False, False])





#print("\n \n \n")

for trial in range(trials):
  sma = StateMachine(bpod)

# sart state blink green two times




       state_change_conditions={"Tup": "start2"},

       output_actions=[("BNC1", 1)],

# detect rotary encoder movement left -> blink red light





           "RotaryEncoder1_1": "blink_green_3x",

           "RotaryEncoder1_2": "blink_red_2x",

           #"Tup": "blink_red_2x"


       output_actions=[("BNC1", 1)],


Any idea where in the code my error is caused Smile
Hi Max,

I don't see anything wrong with the code, but perhaps the PyBpod experts will see something I didn't.
I requested to have you added to the pyBpod slack channel, which is the current forum for PyBpod issues.
Once we have a public link, I'll add it here - but for now, the invitation should arrive by Email.


Forum Jump:

Users browsing this thread: 1 Guest(s)