• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

components/rotary_encoder/11-Mar-2024-321170

main/11-Mar-2024-4520

CMakeLists.txtD11-Mar-2024238 75

MakefileD11-Mar-2024185 92

README.mdD11-Mar-20243.2 KiB7957

README.md

1| Supported Targets | ESP32 | ESP32-S2 |
2| ----------------- | ----- | -------- |
3
4# Rotary Encoder Example
5
6(See the README.md file in the upper level 'examples' directory for more information about examples.)
7
8The PCNT peripheral is designed to count the number of rising and/or falling edges of an input signal. Each PCNT unit has two channels, which makes it possible to extract more information from two input signals than only one signal.
9This example shows how to make use of the HW features to decode the differential signals generated from a common rotary encoder -- [EC11](https://tech.alpsalpine.com/prod/e/html/encoder/incremental/ec11/ec11_list.html).
10
11The signals a rotary encoder produces (and what can be handled by this example) are based on a 2-bit gray code available on 2 digital data signal lines. The typical encoders use 3 output pins: 2 for the signals and one for the common signal usually GND.
12
13Typical signals:
14
15```
16A      +-----+     +-----+     +-----+
17             |     |     |     |
18             |     |     |     |
19             +-----+     +-----+
20B         +-----+     +-----+     +-----+
21                |     |     |     |
22                |     |     |     |
23                +-----+     +-----+
24
25 +--------------------------------------->
26                CW direction
27```
28
29## How to Use Example
30
31### Hardware Required
32
33* An ESP development board
34* EC11 rotary encoder (or other encoders which can produce quadrature waveforms)
35
36Connection :
37
38```
39      +--------+              +---------------------------------+
40      |        |              |                                 |
41      |      A +--------------+ GPIO_A (internal pull up)       |
42      |        |              |                                 |
43+-------+      |              |                                 |
44|     | |  GND +--------------+ GND                             |
45+-------+      |              |                                 |
46      |        |              |                                 |
47      |      B +--------------+ GPIO_B (internal pull up)       |
48      |        |              |                                 |
49      +--------+              +---------------------------------+
50```
51
52### Build and Flash
53
54Run `idf.py -p PORT flash monitor` to build, flash and monitor the project.
55
56(To exit the serial monitor, type ``Ctrl-]``.)
57
58See the [Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html) for full steps to configure and use ESP-IDF to build projects.
59
60## Example Output
61
62```
63I (181323) example: Encoder value: 0
64I (182323) example: Encoder value: 0
65I (183323) example: Encoder value: -12
66I (184323) example: Encoder value: -18
67I (185323) example: Encoder value: -24
68I (188323) example: Encoder value: 4
69I (189323) example: Encoder value: 8
70I (190323) example: Encoder value: 8
71I (191323) example: Encoder value: 8
72```
73
74This example enables the 4X mode to parse the rotary signals, which means, each complete rotary step will result PCNT counter to increase/decrease by 4, depending on the direction of rotation.
75
76## Troubleshooting
77
78For any technical queries, please open an [issue] (https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.
79