Home        Store        Docs        Blog

Basic ESC Raspberry Pi


I am using an Adafruit Servo Hat to control the Basic ESC (the old one). I heard somewhere that plugging in an ESC will fry a raspberry pi, and if you remove the red wire it will be fine. I do not know if this applies to the servo hat. Could I do this?

(Jacob) #2

You should consult the adafruit documentation/support for the servo hat to see if you can leave the red wire connected.

Otherwise, it won’t hurt to disconnect it. You don’t need it either if you already have a power supply for the Pi.


So now that I have that working, I can not find any example code that I can modify to control the ESC, the Adafruit Examples on github would not work, the motor would just beep at me and no lights would turn on. Where can I find some decent example code for this library?

(Patrick José Pereira) #4

@NIW Maybe this can help: bluerobotics/br-esc-examples
Can you check the output signal with an oscilloscope or a logic analyzer ?
Paste the code that you have in gist or pastebin, maybe we can find something wrong.


I am using this code.
It is the Adafruit example code but modifed to have the correct values for the ESC.

Now after thinking about this, I forgot about the dead band (1475-1525 us). Would the ESC ignore 1500 us?

 # Simple demo of of the PCA9685 PWM servo/LED controller library.
 # This will move channel 0 from min to max position repeatedly.
 # Author: Tony DiCola
 # License: Public Domain
 from __future__ import division
 import time
 # Import the PCA9685 module.
 import Adafruit_PCA9685

# Uncomment to enable debug output.
#import logging

# Initialise the PCA9685 using the default address (0x40).
pwm = Adafruit_PCA9685.PCA9685()

# Alternatively specify a different address and/or bus:    
#pwm = Adafruit_PCA9685.PCA9685(address=0x41, busnum=2)

# Configure min and max servo pulse lengths
servo_min = 1500  # Min pulse length out of 4096
servo_max = 1900  # Max pulse length out of 4096

# Helper function to make setting a servo pulse width simpler.
def set_servo_pulse(channel, pulse):
    pulse_length = 1000000    # 1,000,000 us per second
    pulse_length //= 60       # 60 Hz
    print('{0}us per period'.format(pulse_length))
    pulse_length //= 4096     # 12 bits of resolution
    print('{0}us per bit'.format(pulse_length))
    pulse *= 1000
    pulse //= pulse_length
    pwm.set_pwm(channel, 0, pulse)

# Set frequency to 60hz, good for servos.

#I am using channel 8 because I broke channel 0 while soldering. rip. luckily nothing else is broke though.
pwm.set_pwm(8,0, servo_min)
#gives time for ESC to recogize signal.

while True:

    pwm.set_pwm(8, 0, servo_min)
    pwm.set_pwm(8, 0, servo_max)

(Patrick José Pereira) #6

Yes, you can see in performance charts the value between 1475-1525 is a deadband, if you send a value between this range the motor will not ignore, it will set the rotation to zero.

Just to test, try to change the time.sleep(30) for time.sleep(1) and servo_max = 1900 to servo_max = 1700, like you can see in this example.


Sorry It took me so long to reply, I had a lot to do and I could not work on my ROV.

So, I tried what you said, but the ESC stops beeping for a few seconds and then starts up again.
Is this an error with the code or is it with the ESC?


Alright, after looking about, I found this. So I set the min length to 370 and the max to 390.
It worked. the ESC made a long beep and then the motor spun.
I thought the ESC’s stop should be 1500 not 370. If it is 370 for stop would 0 be full reverse and 740 be max?

what would the deadband be?

Can the Hat do reverse values, I tried going down to 350, but nothing happened.

(Patrick José Pereira) #9

Take a look here about deadband.

Test your setup first to see if your ESC + motor work with the arduino code, if yes, try to contact the Adafruit library developers.


I did test it with 1700 as the max and 1500 as the stop, It did not work. I think this is an issue with the board not the ESC, but if I can figure out the min and max values, there will be no need to fix it.