ESP32에서 여러 로터리 엔코더 사용
소개
Arduino ESP32에서 로터리 엔코더를 사용하는 몇 가지 기사가 있습니다.
라이브러리 관리자에서 설치하고 사용하는 기사는 여기
htps : // m / 난부 wks / ms / 1 a 5f881b6 a 84 a 08 e c1
이 도서관에서는 내 소유의 인코더에서 채터링 탓이나 그대로는 잘 계산하지 않았습니다. 또한 여러 인코더를 사용할 수 없었습니다.
이번에는 2개의 인코더를 사용하기 위해 본가 Arduino의 라이브러리
htps //w w. 아르즈이의. ㄷc/레후에렌세/엔/ぃb라리에 s/에 sp32엔코데 r/
를 사용해 보았습니다. Arduion IDE 버전은 1.8.8입니다.
준비
다운로드하여 Arduino의 Libraries 폴더에 저장합니다.
로터리 엔코더를 아래 회로도와 같이 연결합니다. ESP32 보드는 컬러 LCD가있는 TTGO를 사용했습니다.

샘플 스케치
사용한 라이브러리의 examples에 있는 샘플을 수정한 것으로,
표시하는 방법을 모르기 때문에 리스트내의 「#」「< >」는 전각이 되고 있습니다. 복사하여 사용할 때는 반각으로 고쳐 주십시오.
스케치 동작은 포트 설정 후 카운터의 초기 값을
encoder1 = 100
encoder2 = 0
로 설정, 엔코더를 회전 변경이있을 때 직렬 포트에 카운트 값을 출력합니다.
#include <ESP32Encoder.h>
ESP32Encoder encoder1;
ESP32Encoder encoder2;
void setup(){
Serial.begin(115200);
// Enable the weak pull up resistors
ESP32Encoder::useInternalWeakPullResistors=UP;
// use pin 2 and 15 for encoder1
encoder1.attachSingleEdge(2, 15);
// use pin 13 and 12 for encoder2
encoder2.attachSingleEdge(13, 12);
// set starting count value after attaching
encoder1.setCount(100);
// clear the encoder's raw count and set the tracked count to zero
encoder2.clearCount();
Serial.println("Encoder Start = " + String((int32_t)encoder1.getCount()));
}
void loop(){
// Loop and read the count
static int pos1 = 0;
static int pos2 = 0;
int newPos1 = encoder1.getCount();
int newPos2 = encoder2.getCount();
if ((pos1 != newPos1) | (pos2 != newPos2))
{
Serial.print("Encoder count = " + String((int32_t)encoder1.getCount())) ;
Serial.println(" " + String((int32_t)encoder2.getCount()));
pos1 = newPos1;
pos2 = newPos2;
} // if
delay(100);
}
인코더 입력 pullup 정보
일반적으로 아키즈키 등에서 입수 가능한 로터리 엔코더는 입력에 10K 정도의 저항을 접속하는 등 Pullup이 필요합니다. 이 라이브러리에서는
ESP32Encoder::useInternalWeakPullResistors=UP;
내부적으로 Pullup 할 수 있습니다. Pulldown하고 싶을 때는
ESP32Encoder::useInternalWeakPullResistors=DOWN;
됩니다.
엔코더 입력 모드
이 라이브러리에서는 인코더의 입력 모드
HalfQuad
FullQuad
SignalEdge
중에서 선택할 수 있습니다. GPIO PIN 할당시
encoder1.attachSingleEdge(2, 15);
와 같이 설정합니다.
exapmle 에서는 HalfQuad 가 되어 있어 회전시키면 2 개씩 카운트 해, 가끔 미스 카운트 했습니다. 내 소지의 엔코더에서는 SignalEdge 로 설정하는 것으로 안정적으로 카운트 할 수 있게 되었습니다.
라이브러리 설정, 함수 등
소스 등을 확인한 결과 다음 설정과 기능을 사용할 수 있습니다.
Encoder Function
attachHalfQuad(PiNumberA, PinNumberB)
attachFullQuad(PiNumberA, PinNumberB)
attachSingleEdge(PiNumberA, PinNumberB)
Encode.setCount()
Encode.getCount()
Encode.getCountRAW()
Encode.clearCount()
Encode.pauseCount()
Encode.resumeCount()
etc
로터리 엔코더의 사용법으로 회전시켜 수치를 입력하는 것 외에 메뉴를 선택하는 등이 있습니다. 이 때는 카운트치가 아니고 Up/Down 의 방향만을 원할 수 있습니다. 이 라이브러리에서는 그 함수는 없는 것 같습니다.
Reference
이 문제에 관하여(ESP32에서 여러 로터리 엔코더 사용), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/pisamatsu/items/5680253fd910fc02fa09텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)