Encoder — Quadrature Encoder interface (eQEP)¶
Quadrature Encoder Pulse interface.
This module enables access to the enhanced Quadrature Encoder Pulse (eQEP) channels, which can be used to seamlessly interface with rotary encoder hardware.
|Channel||Pin A||Pin B||Notes|
|eQEP1||P8.33||P8.35||Only available with video disabled|
|eQEP2||P8.11||P8.12||Only available with eQEP2b unused (same channel)|
|eQEP2b||P8.41||P8.42||Only available with video disabled and eQEP2 unused|
To use the module, you can connect a rotary encoder to your Beaglebone
and then simply instantiate the
RotaryEncoder class to read its
from Adafruit_BBIO.Encoder import RotaryEncoder, eQEP2 # Instantiate the class to access channel eQEP2, and initialize # that channel myEncoder = RotaryEncoder(eQEP2) # Get the current position cur_position = myEncoder.position # Set the current position next_position = 15 myEncoder.position = next_position # Reset position to 0 myEncoder.zero() # Change mode to relative (default is absolute) # You can use setAbsolute() to change back to absolute # Absolute: the position starts at zero and is incremented or # decremented by the encoder's movement # Relative: the position is reset when the unit timer overflows. myEncoder.setRelative() # Read the current mode (0: absolute, 1: relative) # Mode can also be set as a property mode = myEncoder.mode # Get the current frequency of update in Hz freq = myEncoder.frequency # Set the update frequency to 1 kHz myEncoder.frequency = 1000 # Disable the eQEP channel myEncoder.disable() # Check if the channel is enabled # The 'enabled' property is read-only # Use the enable() and disable() methods to # safely enable or disable the module isEnabled = myEncoder.enabled
Rotary encoder class abstraction to control a given QEP channel.
Parameters: eqep_num (int) – determines which eQEP pins are set up. Allowed values: EQEP0, EQEP1, EQEP2 or EQEP2b, based on which pins the physical rotary encoder is connected to.
Turns the eQEP hardware OFF
Turns the eQEP hardware ON
Sets the eQEP mode as Absolute: The position starts at zero and is incremented or decremented by the encoder’s movement
Sets the eQEP mode as Relative: The position is reset when the unit timer overflows.
Resets the current position to 0
- bool: True if the eQEP channel is enabled, False otherwise.
Type: Returns the enabled status of the module Type: Returns
Sets the frequency in Hz at which the driver reports new positions.
Returns the mode the eQEP hardware is in.
Returns: 0 if the eQEP channel is configured in absolute mode, 1 if configured in relative mode. Return type: int
Returns the current position of the encoder. In absolute mode, this attribute represents the current position of the encoder. In relative mode, this attribute represents the position of the encoder at the last unit timer overflow.
eQEP0 channel identifier, pin A– P9.92, pin B– P9.27 on Beaglebone Black.
eQEP1 channel identifier, pin A– P9.35, pin B– P9.33 on Beaglebone Black.
eQEP2 channel identifier, pin A– P8.12, pin B– P8.11 on Beaglebone Black. Note that there is only one eQEP2 module. This is one alternative set of pins where it is exposed, which is mutually-exclusive with eQEP2b
eQEP2(b) channel identifier, pin A– P8.41, pin B– P8.42 on Beaglebone Black. Note that there is only one eQEP2 module. This is one alternative set of pins where it is exposed, which is mutually-exclusive with eQEP2