For a long time I have had a RPI running python that adjusts a servo directly connected to its GPIO to press buttons on a remote, as part of my home assistant implementation I would like to replace the old RPI with my HA RPI, I don’t want to use ESP if I can avoid it as three wires from the pins to the servo has worked for nearly five years on a stock RPI!
It seems like the closest I can get to doing this is via rpi_gpio_pwm as I’ve read here but that seems an LED focussed implementation.
I don’t know if it helps, but this is the python code I use currently (apologies if it’s overly verbose, I’m no dev…). I have tried to implement this using pyscript already but failed miserably…would very much appreciate any help out there!
# Servo Control
import time
import wiringpi
# use 'GPIO naming'
wiringpi.wiringPiSetupGpio()
# set #18 to be a PWM output
wiringpi.pinMode(18, wiringpi.GPIO.PWM_OUTPUT)
# set the PWM mode to milliseconds stype
wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)
# divide down clock
wiringpi.pwmSetClock(192)
wiringpi.pwmSetRange(2000)
delay_period = 0.01
for pulse in range(235, 275, 1):
wiringpi.pwmWrite(18, pulse)
time.sleep(delay_period)
for pulse in range(275, 235, -1):
wiringpi.pwmWrite(18, pulse)
time.sleep(delay_period)