From d7c2b215f71c8f1106ada79af8dcad3bae21b69f Mon Sep 17 00:00:00 2001 From: Georgios Gerontakis Date: Sat, 11 Jan 2020 03:00:58 +0200 Subject: [PATCH] first simple servo tilt driving. Signed-off-by: Georgios Gerontakis --- camera module/main.py | 4 ++++ camera module/servo.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 camera module/main.py create mode 100644 camera module/servo.py diff --git a/camera module/main.py b/camera module/main.py new file mode 100644 index 0000000..1bea7ea --- /dev/null +++ b/camera module/main.py @@ -0,0 +1,4 @@ +import servo + +servo.SetAngleUp(180) +servo.SetAngleDown(180) \ No newline at end of file diff --git a/camera module/servo.py b/camera module/servo.py new file mode 100644 index 0000000..e30a23d --- /dev/null +++ b/camera module/servo.py @@ -0,0 +1,34 @@ +import RPi.GPIO as GPIO #import GPIO Module +from time import sleep #sleep command + +def SetAngleUp(angle): + GPIO.setmode(GPIO.BOARD) #pins naming + GPIO.setup(03, GPIO.OUT) #PWM signal output (GPIO2) + pwm=GPIO.PWM(03, 50) #50Hz PWM on pin + pwm.start(0) # start with 0 duty ccle (sets no angles on startup) + duty = angle / 18 + 2 + GPIO.output(03, True) + pwm.ChangeDutyCycle(duty) + sleep(1) + GPIO.output(03, False) + pwm.ChangeDutyCycle(0) + pwm.stop() + GPIO.cleanup() + +def SetAngleDown(angle): + GPIO.setmode(GPIO.BOARD) #pins naming + GPIO.setup(05, GPIO.OUT) #PWM signal output (GPIO3) + pwm=GPIO.PWM(05, 50) #50Hz PWM on pin + pwm.start(0) # start with 0 duty ccle (sets no angles on startup) + duty = angle / 18 + 2 + GPIO.output(05, True) + pwm.ChangeDutyCycle(duty) + sleep(1) + GPIO.output(05, False) + pwm.ChangeDutyCycle(0) + pwm.stop() + GPIO.cleanup() + + +SetAngleDown(100) +SetAngleUp(100) \ No newline at end of file