Home        Store        Docs        Blog

Basic ESC with Raspberry Pi


(Lewisporte Collegiate) #1

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!


(Rusty) #2

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


(Lewisporte Collegiate) #3

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!

~Code found in T1001.pdf~~

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 (12.2 KB)

t1001 (12.2 KB)


(Rusty) #4

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: http://raspi.tv/2013/rpi-gpio-0-5-2a-now-has-software-pwm-how-to-use-it

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: https://pythonhosted.org/RPIO/pwm_py.html

You can also use an external PWM generator like the one based on the PCA9685 from Adafruit: https://www.adafruit.com/products/2327. 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


(Lewisporte Collegiate) #5

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


(Lewisporte Collegiate) #6

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 (https://www.adafruit.com/products/815) however we’ve had no success with that either.

Thanks again for your help!


(Rusty) #7

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 (https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library/commit/02ab36e431e4bb612440c8dc2e7f6e8b2133d888), 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


(Lewisporte Collegiate) #8

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)


(Rusty) #9

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


(Lewisporte Collegiate) #10

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)


(Rusty) #11

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

-Rusty