본문 바로가기

작업 일기

아두이노 엔코더 값 받기

- 개발 환경 : Rasberry Pi 4B (Ubuntu 18.04 / ROS melodic)

- 준비물 : 아두이노 메가, 엔코더가 있는 DC 모터(FIT0450) X 2

- 참조 : https://www.youtube.com/watch?v=q1u_cC-5Sac&t=69s 

 

STEP1. 아두이노에 모터드라이버(TB6612FNG) 및 엔코더 모터(FIT0450) 연결

- 아래의 그림과 표를 참조하여 엔코더 모터 및 모터드라이버를 아두이노에 연결합니다.

Motor Driver Arduino Motor 모터 외부전력
A0UT - Motor A -
BOUT - Motor B -
STBY Pin10 - -
PWMA Pin4 - -
AIN1 Pin9 - -
AIN2 Pin8 - -
PWMB Pin5 - -
BIN1 Pin11 - -
BIN2 Pin12 - -
5V VIN - -
GND GND - -
VSEL(외부전력) - - VOUT
- GND - GND
  Pin2 encoderA1  
  Pin3 encoderA2  
  Pin18 encoderB1  
  Pin19 encoderB2  

 

 

* 참고로 엔코더 핀은 반드시 2, 3, 18, 19에 꽃아야합니다. (아두이노 메가 기준)

   https://www.arduino.cc/reference/ko/language/functions/external-interrupts/attachinterrupt/

arduino_encoder.ino
0.00MB

 

 

 

- 아래 링크의 rosserial motor 코드와 합친 버전입니다.

   https://do-9un6.tistory.com/13

ros_motor_encoder.ino
0.01MB

 

 

 

 

- 엔코더 값으로 모터 움직이기

arduino_encoder02.ino
0.01MB

 

 

- 엔코더 코드와 rosserial 코드 합치기

arduino_encoder03.ino
0.01MB

 

 

- 라이브러리

PID-1.2.0.zip
0.01MB
arduino_encoder04.ino
0.01MB