I'm trying to make a small remote controlled car with the raspberry pi and attached two small dc motors to it, using the L239D chip. When testing without the remote control (which is a simple android app) the motors work good and the speed is changing. But when I try with the remote control it doesn't work at all. here is the function that receives the remote control params:

def customSpeed(direction,left, right):
    right = int(right)
    left = int(left)
    if direction == "f":
        GPIO.output(Motor1A, GPIO.HIGH)
        GPIO.output(Motor1B, GPIO.LOW)
        GPIO.output(Motor2A, GPIO.HIGH)
        GPIO.output(Motor2B, GPIO.LOW)
        print("Got to forward")
        GPIO.output(Motor1A, GPIO.LOW)
        GPIO.output(Motor1B, GPIO.HIGH)
        GPIO.output(Motor2A, GPIO.LOW)
        GPIO.output(Motor2B, GPIO.HIGH)
        print("Got to back")
    ans = "Going "+ ("Forward" if direction == "f" else "Back") +". Left: "+str(left)+". Right: "+str(right)

The last print, prints the information correct, and when I try to do this methods "offline" they all work properly, but this function does not. Any thoughts?

EDIT: This are my methods for preparing the motors:

Motor1A = 16
Motor1B = 18
Motor1E = 22

Motor2A = 19
Motor2B = 21
Motor2E = 23

GPIO.setup(Motor1A, GPIO.OUT)
GPIO.setup(Motor1B, GPIO.OUT)
GPIO.setup(Motor1E, GPIO.OUT)
GPIO.setup(Motor2A, GPIO.OUT)
GPIO.setup(Motor2B, GPIO.OUT)
GPIO.setup(Motor2E, GPIO.OUT)

motorR = GPIO.PWM(Motor1E,100)
motorL = GPIO.PWM(Motor2E,100)

Is there any problem using the tcp connection with the GPIO at the same time?


1 Answer 1


Essentially if you are using RPI.gpio lib which it looks like you are, (and written in python too) I used to use this lib but sometimes commands didn't correctly setup the pwm and often caused problems due to system access, essentially I could suggest you use pigpio ( http://abyz.me.uk/rpi/pigpio/) as it is a nice and easily usable lib on python, and it has extensive documentation included with it.

The problem using TCP with RPI.gpio too is that as noted before sometimes the pwm doesn't actually reach the servo/motor where as pigpio uses a listener to make sure that the servo/motor receives a smooth signal.

If you have any questions please yell, hope this sheds some light on your problem.

  • All good just make sure before you run your code you run sudo pigpiod to make sure your code works fine (it starts the listener)
    – Pariah
    Oct 3, 2014 at 10:49
  • I'm trying to understand how to use the pigpio library and made this simple python file to try and operate one motor.. Could you take a look and tell me why this isn't working? github.com/javitolin/RPiPigPio Thanks
    – Javi
    Oct 3, 2014 at 12:10
  • While im checking through your code read the last post by me (Subblez) raspberrypi.org/forums/viewtopic.php?f=33&t=88323
    – Pariah
    Oct 3, 2014 at 14:02
  • Because i havent used dc motors (servo's only) this is my interpratation of the code: github.com/GitPariah/RPiPigPio/blob/patch-1/PigpioTest.py
    – Pariah
    Oct 3, 2014 at 14:42
  • so the numbers the pigpio receives is the gpio number and not the gpio pin number? And I didn't saw the gpioPWM function as well.. Thanks! I'll try it.
    – Javi
    Oct 4, 2014 at 12:20

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.