You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Adafruit_BBIO/README.md
+63-8Lines changed: 63 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,30 +4,68 @@ This module enables access to the Beaglebone Black enhanced Quadrature Encoder P
4
4
5
5
## Usage
6
6
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.
8
8
9
9
```python
10
-
import Adafruit_BBIO.Encoder as Encoder
10
+
from Adafruit_BBIO.Encoder import RotaryEncoder, eQEP2
11
11
12
12
'''
13
13
Each channel can be accessed and initialized using its corresponding
14
14
channel name constants:
15
15
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
20
20
'''
21
21
22
22
# Instantiate the class to access channel eQEP2, and only initialize
23
23
# 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
+
25
61
```
26
62
27
63
If you need to use further channels, read on the prerequisites in the following section.
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
+
44
99
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.
45
100
46
101
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
51
106
52
107
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.
53
108
54
-
### Enabling additional eQEP modules
109
+
####Enabling additional eQEP modules
55
110
56
111
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.
0 commit comments