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.
The channel identifiers are available as module variables eQEP0
,
eQEP1
, eQEP2
and eQEP2b
.
Channel | Pin A | Pin B | Notes |
---|---|---|---|
eQEP0 | P9.27 | P9.92 | |
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 |
Example
To use the module, you can connect a rotary encoder to your Beaglebone
and then simply instantiate the RotaryEncoder
class to read its
position:
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
-
class
Adafruit_BBIO.Encoder.
RotaryEncoder
(eqep_num)¶ 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. -
disable
()¶ Turns the eQEP hardware OFF
-
enable
()¶ Turns the eQEP hardware ON
-
setAbsolute
()¶ Sets the eQEP mode as Absolute: The position starts at zero and is incremented or decremented by the encoder’s movement
-
setRelative
()¶ Sets the eQEP mode as Relative: The position is reset when the unit timer overflows.
-
zero
()¶ Resets the current position to 0
-
enabled
¶ - bool: True if the eQEP channel is enabled, False otherwise.
Type: Returns the enabled status of the module Type: Returns
-
frequency
¶ Sets the frequency in Hz at which the driver reports new positions.
-
mode
¶ 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
-
position
¶ 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.
-
-
Adafruit_BBIO.Encoder.
eQEP0
= 0¶ eQEP0 channel identifier, pin A– P9.92, pin B– P9.27 on Beaglebone Black.
-
Adafruit_BBIO.Encoder.
eQEP1
= 1¶ eQEP1 channel identifier, pin A– P9.35, pin B– P9.33 on Beaglebone Black.
-
Adafruit_BBIO.Encoder.
eQEP2
= 2¶ 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
-
Adafruit_BBIO.Encoder.
eQEP2b
= 3¶ 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