I think I need my own forum to post my questions, because as soon as I post a question I manage to fix it!
g=Pin('GP11',mode=Pin.OUT, alt=3) should be g=Pin('GP11',mode=Pin.ALT,alt=3) obvious once you know
so here is some simple code I have used to drive my servo between the zero and 180 position.
Code: Select all
from machine import Timer
from machine import Pin
import time
# set GP11 as an output and specify alternate function 3 for PWM
g=Pin('GP11',mode=Pin.ALT, alt=3)
# now initialse Timer 3 as PWM and it is associated with GP11 automatically
tim = Timer(3, mode=Timer.PWM, width=16)
# now set frequency and duty cycle
zero =200
one80=1200
step=10
cycle=zero
while True:
tim_b = tim.channel(Timer.B, freq=50, duty_cycle=cycle)
cycle+=step
if cycle > one80:
step=-step
cycle=one80
print("180")
elif cycle < zero:
step=-step
cycle=zero
print("0")
time.sleep_ms(100)
not very elegant but it works.
I used ftp to copy it the the flash folder, then logged in via a telnet and used exec file("servo.py") to run it.
My servo is jerky around the 90 deg position, I need to try another servo or put a scope on the signal to see what is going on.
But, progress, that is a led and now a servo I have controlled, stepper motor next!
steve