-1

I am using an L298N board and two pi yellow pi servos and a program on my pi to control everything:

# Driving One Motor Using GpioZeo and L298N v0.01  tlfong01  2019jun11hkt1156
# rpi3B+ python 3.5.3 gpiozero 1.5.0 L298N
# wiring -  GPIO17, GPIO18, GPIO2, GPIO3, GND
# Equipment: Raspberry Pi, 4AA pwr src, pi motor 1, pi motor 2, 5 pi wires
# https://projects.raspberrypi.org/en/projects/build-a-buggy/3

from time import sleep
from gpiozero import Motor

motor = Motor(17, 18)
motor2 = Motor(2, 3)

motor.forward()
motor2.forward()
sleep(2)
motor.backward()
motor2.backward()
sleep(2)
motor.reverse
motor2.reverse
sleep(2)
motor.stop()
motor.stop()

the first motor starts, reverses and stops, but the second motor starts, reverses and then continues running until I remove the power. I added the declaration of 'motor2' and all of the motor2 commands to the working program for a single motor from tlfong01, I guess I adapted this program incorrectly. What is wrong with the code that is making the second motor run forever?

1 Answer 1

2

I suspect that the second line should read motor2.stop():

motor.stop()
motor.stop() # <-- change to motor2.stop()
1
  • yea it was just that little typo. Thanks I'll read the code a little more closely next time Commented Jun 12, 2019 at 1:34

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.