-
Notifications
You must be signed in to change notification settings - Fork 0
/
NOTES
113 lines (93 loc) · 4.06 KB
/
NOTES
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
encoder datasheet (from GRobotronics)
-----------------
EC12E20-24P24C-SW.pdf
https://grobotronics.com/rotary-encoder-12mm-24p-r-with-switch.html
usual connectivity
------------------
http://community.axoloti.com/t/rotary-encoders/2681
basically:
1. hold encoder in front of your eyes with the 3 pins side facing down.
Then the 3 pins from left to right are A , C , B .
A = signal 1
C = common
B = signal 2
On the top side are 2 more pins S1 and S2. These are for the push button switch.
2.Connections
______________
| |
---------A-| |
| | |-S1----------------- SW (push button)
| ---C-| |
| | | |-S2-- -------------- CLK (signal A)
| ---|--B-| | | |
| | | |______________| | | ----------- DT (signal B)
| | | | | |
| | -------------------------*--|--|---------- GND
| | | |
| -------------------------------|--*--10K--*-- +3V3
| | |
----------------------------------*----10K----
resistors
---------
https://raspberrypi.stackexchange.com/a/39314/113877
They can be omitted since rpi3b+ model has configurable pull up / pull down
internal resistors for almost all pins! Only I2C pins (SDA,SCL are permanently pulled up)
So: should connect SW, CLK and DT to 3 GPIOs configured to be pulled up!
development:
-----------
https://www.raspberrypi.org/documentation/usage/gpio/
c/c++ : libgpiod or (3rd party) pigpio
python: pigpio , gpiozero
if using then here is some minimal C/C++ code examples
http://abyz.me.uk/rpi/pigpio/examples.html#Misc_code
to build libgpiod using tag v.1.4.2 did not work for me but the tar of the same version did.
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git
kernel encoder driver:
https://www.kernel.org/doc/html/v4.16/input/devices/rotary-encoder.html
pinout:
------
https://pinout.xyz/#
also "pinout" cli cmd , to view gpio pin layout in cli
can also change pin names in gpioinfo, see :
https://microhobby.com.br/blog/2020/02/02/new-linux-kernel-5-5-new-interfaces-in-gpiolib/
test1 - connect single encoder:
------------------------------
connect GND to pins 9 & 14 (pin 1 is 3v3 and pin 2 is 5v just for ref)
connect ENC A & B to pin 11 & 13 (GPIO: BCM 17 & 27)
connect push BUTTON to pin 15 (GPIO: BCM 22)
enable GPIO 17,27,22 as pull up
(https://raspberrypi.stackexchange.com/a/36582/113877)
basically :
gpio -g mode 22 up
check all pin states with
gpio -g readall
finally monitor some triggers on the pins while playing with the encoder using
gpiomon -n 100 gpiochip0 17 27 22
NOTE: it seems you cannot set pull up states from cli , using gpioset. But you
should be able to through some code. BUT:
https://microhobby.com.br/blog/2020/02/02/new-linux-kernel-5-5-new-interfaces-in-gpiolib/
with libgpiod v1.5 and kernel >=5.5 the option -B enables setting pull-up/down
state of the input, thus allows using gpiomon fully.
this is a python example using the kernel rotary encoder driver:
https://blog.ploetzli.ch/2018/ky-040-rotary-encoder-linux-raspberry-pi/
Task breakdown:
--------------
1. find c code that reads from encoder.
notes: not sure which lib to prefer libgpiod, pigpio, ... ? Hmmm maybe use
libgpiod which is more basic/closer to kernel provided stuff
2. read up on jack header and find how to generate midi messages
3. incorporate midi messages generation lib
4. include jack midi to push the midi messages through jack
encoderController:
-----------------
enc1: pins 15,13,11(button) - BCM 22,27,17
enc2: pins 22,18,16(button) - BCM 25,24,23 #CAUTION not adjacent !!!
enc3: pins 37,36,31(button) - BCM 26,16,06 #CAUTION not adjacent, not even on same side !!!
typical midi msg to be assembled
----------------
CC (control change) msgs:
"b0 68 63 : control change (channel 0): ctrl 104, value 99"
"b0 68 64 : control change (channel 0): ctrl 104, value 100"
0xb0 : control change midi event, at channel 0
0x68 : ctrl # (dec=104)
0x63 : value # (decimal=99)