I posted this question in stackoverflow but this might be a better forum.
Being new to code and python, I have trouble integrating buttons to control Pimoroni pan tilt hat in the Motioneye surveillance software. I found code for adafruit PCA9685 servo controller. The code will call a bash script when a button is pressed. The bash script will then call a python script that will pan or tilt the servo continously as long as the buttons is pressed which is something I would like to do. Unfortunately I don´t know what to change to make it work with the Pimoroni servo.
Script for controlling pan tilt in motioneye with the adafruit PCA9685 servo controller https://github.com/luetzel/motion_eye_servo_action
I have tried to change GPIO pins in the code, and imported pantilthat into the code. However, that doesnt seem to work. That will get me
Remote I/O error
If anyone could help me get this working with pimoroni the pan tilt hat or point me in the right direction, I would be very grateful!
Kind regards Kirst
Below is an example code for tilt down. Again this is for the Adafruit PCA9685 driver.
/usr/bin/env python from __future__ import division import time # Import the PCA9685 module. import Adafruit_PCA9685 import RPi.GPIO as GPIO GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) # power-up servo controller GPIO.setup(18, GPIO.OUT) GPIO.output(18, 0) time.sleep(.5) # Initialise the PCA9685 using the default address (0x40). pwm = Adafruit_PCA9685.PCA9685() # Configure min and max servo pulse lengths (450 total, 25 corresponds to 10 degrees) servo_min = 225 # Min pulse length out of 4096 servo_max = 725 # Max pulse length out of 4096 with open('/etc/motioneye/vert_pos', 'r') as f: vert_pos = int(f.readline()) print vert_pos f.close() # Set frequency to 60hz, good for servos. pwm.set_pwm_freq(60) if ( vert_pos != servo_max ): vert_pos += 25 pwm.set_pwm(0, 0, vert_pos) with open('/etc/motioneye/vert_pos', 'w') as f: f.write(str(vert_pos)) f.close() # power-up servo controller time.sleep(.5) GPIO.output(18, 1) raise SystemExit