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) motorR.ChangeDutyCycle(right) motorL.ChangeDutyCycle(left) print("Got to forward") else: GPIO.output(Motor1A, GPIO.LOW) GPIO.output(Motor1B, GPIO.HIGH) GPIO.output(Motor2A, GPIO.LOW) GPIO.output(Motor2B, GPIO.HIGH) motorR.ChangeDutyCycle(right) motorL.ChangeDutyCycle(left) print("Got to back") ans = "Going "+ ("Forward" if direction == "f" else "Back") +". Left: "+str(left)+". Right: "+str(right) print(ans)
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:
GPIO.setmode(GPIO.BOARD) 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) motorR.start(0) motorL.start(0)
Is there any problem using the tcp connection with the GPIO at the same time?