1

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.

2
  • Your comments say that you are expecting a beep. which command causes this beep?
    – NomadMaker
    Jun 18, 2022 at 0:44
  • 1
    @NomadMaker There's no command, the ESC makes the motor give a certain beep when it detects a proper signal. Lets me know that the ESC is armed.
    – zapshe
    Jun 18, 2022 at 22:48

1 Answer 1

0

Well, I figured out what was wrong, was able to get the Pico to run my ESC! The issue is that I had no idea what frequency was being used with the pigpio library. The frequency and duty cycle had to be just right in order for the ESC to detect it.

Setting the frequency to 200 and minimum duty cycle to 12000 let the ESC detect it (it was a complete shot in the dark, but I noticed certain values stopped the motor from shaking, meaning the ESC knew something was sending signals, but could never get it to spin). Then above 12000 duty cycle it starts to spin.

I messed with it and tried setting the frequency to 100, but that made the motor spin extremely fast (the motor is so powerful it scared the sht out of me). I'd of thought it would make it go slower, but I'm still learning.

But, I'm really glad I can get the motor spinning without needing to rely on an pi running an OS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.