Basic ESC with Raspberry Pi

Hello,

we are having trouble using the Basic ESC with a Raspberry Pi 2 Model B. We have successfully used the ESC with an Arduino to control a T100 motor. However, our design plans make the Raspberry Pi necessary. Any help with the PWM and software would be greatly appreciated!

Hi,

Can you guys share your code or the libraries that you are trying to use? It’s difficult to provide much help without that.

Thanks!

-Rusty

Hello Rusty,

Thanks for the reply, here is the code we’ve come up with. It uses PWM at a frequency of 50Hz, and we’ve calculated the duty cycles for forward, reverse, and stopped at 9.5%, 5.5%, and 7.5%. Let us know what you think!


import time
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)

GPIO.setup(7, GPIO.OUT)

t1 = GPIO.PWM(7, 50)

t1.start(0)


t1.ChangeDutyCycle(7.5)
time.sleep(3)

try:
    while True:
        t1.ChangeDutyCycle(9.5)
        time.sleep(3)
        t1.ChangeDutyCycle(5.5)
        time.sleep(3)
        t1.ChangeDutyCycle(7.5)
        time.sleep(3)
        
except KeyboardInterrupt:
    print("User Cancelled")

finally:
    t1.stop()
    GPIO.cleanup()
    quit()

[t100|attachment](upload://vVi9wU6sD69TQ6lOiQnYScm8aMG) (12.2 KB)

[t1001|attachment](upload://3iAuVhobGXanmSWXkGwSAgTZksP) (12.2 KB)

Hello,

Thanks for sharing your code. I’ve been looking in the GPIO library that you are using, “RPi.GPIO”, and it looks like that might be the issue. That library uses “software PWM” meaning that the timing for the PWM signal is managed by the main processor instead of a dedicated timer. That makes it relatively inaccurate.

There are a few place that mention that the library won’t work well for servos (and ESCs) like this one: RPi.GPIO 0.5.2a now has software PWM – How to use it – RasPi.TV

If you have an oscilloscope, I’d recommend checking the outputs. Most likely they are not exactly what they are supposed to be. When the ESC starts, it needs to be initialized at 1500 µs (+/- 25 µs) and it might not be in that range.

There’s another PWM library that uses the DMA on the Raspberry Pi and can generate more accurate pulses: RPIO.PWM, PWM via DMA for the Raspberry Pi — RPIO 0.10.0 documentation

You can also use an external PWM generator like the one based on the PCA9685 from Adafruit: Adafruit 16-Channel PWM / Servo HAT for Raspberry Pi - Mini Kit : ID 2327 : $17.50 : Adafruit Industries, Unique & fun DIY electronics and kits. That was also seems to have some PWM accuracy issues so I’d recommend trying the library above first.

I hope that helps! Let us know how it goes!

Best,

Rusty

Thanks Rusty! We’ll try and use the other PWM library you linked to and get back to you with the results.

Hello again Rusty,

Our results are not great. We tried using the other library you linked, and had little success with operating the ESC. It would initiate, and we were able to send forward/reverse signals to operate the T100, but the library is very unreliable. Any quick changes to the pulse would cause glitchy movement in the T100; we never encountered this erratic movement using Arduino. Also we do have a spare PCA9685 Board from Adafruit (Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface [PCA9685] : ID 815 : $14.95 : Adafruit Industries, Unique & fun DIY electronics and kits) however we’ve had no success with that either.

Thanks again for your help!

Hi guys,

Do you have access to an oscilloscope? That would really help to verify what’s going on here. I can give your code a shot early next week and see how it looks.

What have you tried with the Adafruit board? I believe there is a scaling issue in there that causes the pulses to be a little wider than expected. I think you should be able to get a decent pulse from the Adafruit board but you might have to multiple the input by a factor like 0.9. In fact, in their Arduino version of the library, they added the scaling factor in (Fix #11 by scaling frequency by 0.9. · adafruit/Adafruit-PWM-Servo-Driver-Library@02ab36e · GitHub), but that seems to be missing from the Raspberry Pi version. You might try that and see if it works.

Let us know how it goes.

Best,

Rusty

Hey Rusty,

Unfortunately, we do not have access to an oscilloscope in our local area (Although it would be cool!!). We didn’t have much luck with multiplying the signal by a factor of 0.9 either. Still no initiation of the Basic ESC. Tell us what you think of the code we’ve attached.

Thanks!

t100_ada (12.5 KB)

Hi guys,

Okay. If you have an Arduino available you can use the “pulseIn” function to check the pulse width that’s being output and make sure it is correct. Here’s an example: https://www.arduino.cc/en/Reference/PulseIn

I looked at your code and the Adafruit library. The 0.9 correction is actually for the frequency, not the input signal. You might try pwm.setFreq(int(60*0.9)) instead and see if that helps.

If that doesn’t work, I have the same board sitting at the office and I can try your code our tomorrow with an oscilloscope.

I’m sure we can get this working!

Best,

Rusty

Hi Rusty,

It works!! Using the pulseIn() function on the Arduino was a great help; we used it to more accurately pinpoint the correct signal we needed to send from the Adafruit board. We’ve uploaded a copy of the code if you want to take a look.

Thanks so much for helping, we are really grateful for your support!

Lewisporte Collegiate ROV Club

t100_ada_2 (13.5 KB)

Fantastic! Glad to hear that it is working well and thanks for sharing your code.

-Rusty