Raspberry Pi GPIO PWM Servo Motor jyheo0@gmail.com
PWM(Pulse Width Modulation)? Modulation technique used to encode a message into a pulsing signal. Control of the power supplied to electrical devices, especially to inertial loads such as motors. https://en.wikipedia.org/wiki/Pulse-width_modulation
PWM + Servo Motor(SG90) 0도 45도 90도 http://www.piccircuit.com/shop/picture/motor/servo_operation.png
Wiring RPi GPIO18 - PWM RPi 5V - Vcc RPi GND - Ground
Python code $ python3 servo.py 1 $ python3 servo.py 1.5 import RPi.GPIO as GPIO import time import sys GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(18, GPIO.OUT) pwm = GPIO.PWM(18, 50) # 50Hz pwm.start(1) if len(sys.argv) != 2: print('python servo.py 1~3’) else: ms = float(sys.argv[1]) dcycle = ms / 20.0 * 100 # percent pwm.ChangeDutyCycle(dcycle) time.sleep(2) # wait until the device receiving pwm.stop() GPIO.cleanup() Python code $ python3 servo.py 1 $ python3 servo.py 1.5 $ python3 servo.py 2
Exercise 버튼을 3개 연결하고 각 버튼을 누르면 서로 다른 위치로 서보 모터를 동작 시킨다. 서보 모터 대신 LED를 GPIO에 연결해서 결과를 본다.