I have a DC motor I can spin via ESC connected with a Raspberry Pi 4, but I want to use a Raspberry Pi Pico instead.
Using GPIO4, that has the clock, I have this code that works for spinning the motor with the Pi 4:
pi = pigpio.pi()
ESC = 4
# Motor Calibrated Using These Values
max_value = 2500
min_value = 900
pi.set_servo_pulsewidth(ESC, min_value)
print ("Connect the battery and press Enter")
inp = input()
pi.set_servo_pulsewidth(ESC, 1000)
#Motor Will Spin Here
I've tried a lot of ways to get equivalent MicroPython code for the Pico using PWM, but it acts no differently then if I didn't have the Pico sending signals at all.
PWM has a frequency and duty_u16 setting. I'm not sure how those should be setup to be equivalent to the Pi 4 code. I've tried frequencies from 50hz-19.2Mhz and duty_u16 from 100-65500.
set_servo_pulsewidth work perfectly with the Pi 4, how do I get PWM to act the same?
I'm doing something dumb I'm sure, any advice?
MicroPython Code I've Been Messing With:
from machine import Pin, PWM
from time import sleep
pwm = PWM(Pin(2))
pwm.freq(50)
pwm.duty_u16(500)
#Should Beep Here, Never Does
sleep(2)
print("Start!")
pwm.duty_u16(1000)
#Should Spin Here, Never Does
sleep(2)
I know the pins are outputting, can connect to LED and change its brightness.