Skip to content

Commit aa2221f

Browse files
authored
Merge pull request adafruit#207 from dplanella/patch-3
Encoder: improved usage documentation
2 parents 741c1b2 + 11e0837 commit aa2221f

File tree

1 file changed

+63
-8
lines changed

1 file changed

+63
-8
lines changed

Adafruit_BBIO/README.md

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,68 @@ This module enables access to the Beaglebone Black enhanced Quadrature Encoder P
44

55
## Usage
66

7-
On a recent Beaglebone Debian image, access to the eQEP0 and eQEP2 channels should work out of the box:
7+
On a recent Beaglebone Debian image, access to the eQEP0 and eQEP2 channels should work out of the box, at least as root user. To ensure you can run the code as a regular user, read on the prerequisites section below.
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 = next_position
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.
2864

2965
## Prerequisites
3066

67+
### Kernel and packages
68+
3169
These instructions are based on:
3270

3371
- Linux kernel: 4.4.x or later
@@ -41,6 +79,23 @@ sudo apt update
4179
sudo apt upgrade bb-cape-overlays bb-customizations
4280
```
4381

82+
### User permissions
83+
84+
In order to be able to run code that accesses the eQEP modules as a regular user, as opposed to root, that user must be part of the `eqep` group.
85+
86+
To check which users are part of the `eqep` group:
87+
88+
```
89+
cat /etc/group | grep eqep
90+
```
91+
92+
To add user `userName` to the `eqep` group (run this command as root):
93+
```
94+
usermod -a -G eqep userName
95+
```
96+
97+
### Capes
98+
4499
In order to use all eQEP pins the BeagleBone must boot with the [cape-universal](https://github.com/beagleboard/bb.org-overlays/tree/master/tools/beaglebone-universal-io) enabled, and load the `cape-universal` overlay.
45100

46101
This is the default, thus **no further steps are initially required to use eQEP0 and eQEP2**. Simply double-check that the following line is present and not commented out on your `/boot/uEnv.txt` file:
@@ -51,7 +106,7 @@ enable_uboot_cape_universal=1
51106

52107
Note: Some older documentation recommends using the `cmdline` and `cape_enable` options instead. They are meant to load deprecated kernel-based overlays and it's not recommended to use them. Use the new way of [loading overlays via uboot](https://elinux.org/Beagleboard:BeagleBoneBlack_Debian#U-Boot_Overlays) instead, as instructed above.
53108

54-
### Enabling additional eQEP modules
109+
#### Enabling additional eQEP modules
55110

56111
The `cape-universal` overlay will enable access to the eQEP0 and eQEP2 modules. As it does not expose pins that are shared with the HDMI interface, eQEP1 and eQEP2b will **not** be available.
57112

0 commit comments

Comments
 (0)