I'm trying to build a quadcopter and I have one ESC, one brushless motor and one Raspberry Pi B+. I find many tutorials on internet to see how to connect these components but it doesn't work. I'm using RPi lib in Python to program. I would like to be sure about my connectics and the code I use to control the ESC. I find a tutorial who has the same components as I. (solenerotech1.wordpress.com/2013/09/09/tutorialhow-to-control-a-brushless-motor-with-raspberry-pi/)
That is how I connect the components :
and the code I try to execute :
But the motor doens't work. Need I setup the Raspberry to use GPIO ?
I installed RPi correctly on the Raspberry, the code don't have any errors and if this turorial is correct I have correctly connect my components. Do you see where I'm wrong ?

from motor import motor

mymotor = motor('m1', 17, simulation=False)
#where 17 is  GPIO17 = pin 11

print('***Disconnect ESC power')
print('***then press ENTER')
res = raw_input()

#NOTE:the angular motor speed W can vary from 0 (min) to 100 (max)
#the scaling to pwm is done inside motor class
print('***Connect ESC Power')
print('***Wait beep-beep')

print('***then press ENTER')
res = raw_input()
print('***Wait N beep for battery cell')
print('***Wait beeeeeep for ready')
print('***then press ENTER')
res = raw_input()
print ('increase > a | decrease > z | save Wh > n | set Wh > h|quit > 9')

cycling = True
    while cycling:
        res = raw_input()
        if res == 'a':
        if res == 'z':
        if res == 'n':
        if res == 'h':
        if res == '9':
            cycling = False
    # shut down cleanly
    print ("well done!")

class motor(object):
    """Manages the currect Angular rotation
    Implements the IO interface using the RPIO lib
    __init_(self, name, pin, kv=1000, RPMMin=1, RPMMax=100, debug=True, simulation=True):
    More info on RPIO in http://pythonhosted.org/RPIO/index.html"""

    def __init__(self, name, pin, kv=1000, WMin=0, WMax=100, debug=True, simulation=True):
        self.name = name
        self.powered = False
        self.simulation = simulation
        self.__pin = pin
        self.__kv = kv
        self.setWLimits(WMin, WMax)

        self.__W = self.__WMin
        self.__Wh = 10

            from RPIO import PWM
            self.__IO = PWM.Servo()
        except ImportError:
            self.simulation = True

    def setDebug(self, debug):
        self.__debug = debug
        #if self.__debug:

    def getDebug(self):
        return self.__debug

    def setPin(self, pin):
        "set the pin for each motor"
        self.__pin = pin

    def setKv(self, kv):
        "set the kv for each motor"
        self.__kv = kv

    def setWLimits(self, WMin, WMax):
        "set the pin for each motor"
        if WMin < 0:
            WMin = 0
        self.__WMin = WMin
        if WMax > 100:
            WMax = 100
        self.__WMax = WMax

    def saveWh(self):
        "Save Wh = current W%"
        self.__Wh = self.__W

    def setWh(self):
        "Sets current W% =Wh"
        self.__W = self.__Wh

    def getWh(self):
        "returns current W% =Wh"
        return self.__Wh

    def start(self):
        "Run the procedure to init the PWM"
        if not self.simulation:
                from RPIO import PWM
                self.__IO = PWM.Servo()
                self.powered = True
                #TODO Decide How to manage the WMax < 100
                #to keep anyhow the throttle range 0-100
            except ImportError:
                self.simulation = True
                self.powered = False

    def stop(self):
        "Stop PWM signal"

        if self.powered:
            self.powered = False

    def increaseW(self, step=1):
        "increases W% for the motor"

        self.__W = self.__W + step

    def decreaseW(self, step=1):
        "decreases W% for the motor"

        self.__W = self.__W - step

    def getW(self):
        "retuns current W%"
        return self.__W

    def setW(self, W):
        "Checks W% is between limits than sets it"

        PW = 0
        self.__W = W
        if self.__W < self.__WMin:
            self.__W = self.__WMin
        if self.__W > self.__WMax:
            self.__W = self.__WMax
        PW = (1000 + (self.__W) * 10)
        # Set servo to xxx us
        if self.powered:
            self.__IO.set_servo(self.__pin, PW)

EDIT : Oh RPIO instead of RPi... that stupid... I installed RPIO too, the motor works during 1/2 second when I set it to 10. It don't works other times. Is that a new stupid error ?

  • You mention RPi.GPIO but the code uses RPIO.GPIO (they are different Python modules). Anyhow see raspberrypi.stackexchange.com/questions/25973/…. I expect you'll be better off using my pigpio. – joan Aug 24 '15 at 22:32
  • Please add the quote to the question so that's it's easier for someone to review it as opposed to have to download the zip file and the view the code – evolutionizer Aug 25 '15 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.