Skip to content

Commit cfe05ed

Browse files
authored
Encoder: improved usage documentation
1 parent 773f9bd commit cfe05ed

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

Adafruit_BBIO/README.md

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,57 @@ This module enables access to the Beaglebone Black enhanced Quadrature Encoder P
77
On a recent Beaglebone Debian image, access to the eQEP0 and eQEP2 channels should work out of the box:
88

99
```python
10-
import Adafruit_BBIO.Encoder as Encoder
10+
from Adafruit_BBIO.Encoder import RotaryEncoder, eQEP2
1111

1212
'''
1313
Each channel can be accessed and initialized using its corresponding
1414
channel name constants:
1515
16-
Encoder.eQEP0
17-
Encoder.eQEP1 # Pins only available when video is disabled
18-
Encoder.eQEP2
19-
Encoder.eQEP2b # Pins only available when video is disabled
16+
eQEP0
17+
eQEP1 # Pins only available when video is disabled
18+
eQEP2
19+
eQEP2b # Pins only available when video is disabled
2020
'''
2121

2222
# Instantiate the class to access channel eQEP2, and only initialize
2323
# that channel
24-
myEncoder = Encoder.RotaryEncoder(Encoder.eQEP2)
24+
myEncoder = RotaryEncoder(eQEP2)
25+
26+
# Get the current position
27+
cur_position = myEncoder.position
28+
29+
# Position can also be set as a property
30+
next_position = 15
31+
myEncoder.position = 15
32+
33+
# Reset position to 0
34+
myEncoder.zero()
35+
36+
# Change mode to relative (default is absolute)
37+
# You can use setAbsolute() to change back to absolute
38+
# Absolute: the position starts at zero and is incremented or
39+
# decremented by the encoder's movement
40+
# Relative: the position is reset when the unit timer overflows.
41+
myEncoder.setRelative()
42+
43+
# Read the current mode (0: absolute, 1: relative)
44+
# Mode can also be set as a property
45+
mode = myEncoder.mode
46+
47+
# Read the current frequency of update
48+
# Returned value is in Hz
49+
# If you want to set the frequency, specify it also in Hz
50+
freq = myEncoder.frequency
51+
52+
# Disable your eQEP channel
53+
myEncoder.disable()
54+
55+
# Check if the channel is enabled
56+
# The 'enabled' property is read-only
57+
# Use the enable() and disable() methods to
58+
# safely enable or disable the module
59+
isEnabled = myEncoder.enabled
60+
2561
```
2662

2763
If you need to use further channels, read on the prerequisites in the following section.

0 commit comments

Comments
 (0)