I'm trying to follow this tutorial on how to build a buggy with a Raspberry Pi. I'm using all the same parts except for the Pi and the battery. I am using a Raspberry Pi 4B and an 8.4v battery from Pololu. My wiring is exactly as the tutorial says, with In1 going to GPIO pin 7, In2 going to GPIO pin 8, In3 going to GPIO pin 9, and In4 going to GPIO pin 10. I have a wire going from the ground pin in my motor controller to a ground pin on the Pi, and my motor controller lights up when I connect the battery. All my wires on both the motor controller and the Pi are secure, nothing is loose.

However, when I run the sample code in the tutorial,

from gpiozero import Robot
robby = Robot(left=(7,8), right=(9,10))

the motors do not turn. I only get a message "program exited with code: 0". This is odd because code 0 means the program ran successfully but clearly it did not if my motors didn't run when I ran code telling them to run. I've tried switching the wires thinking I might have bad wires, I've tried plugging the wires into different GPIO pins on the Pi, I've uninstalled and reinstalled Python, and I've even hard reset the entire Pi, but the motors still do not turn and I still get the same code 0 message every time. Any help would be much appreciated.

  • You should post details of connections etc. into your question NOT a link. The code is probably doing exactly what you told it do viz. tell robot to move forward (assuming you have a suitable motor driver) which it will do for <1µSec then exit and reset the GPIO to initial state.
    – Milliways
    Commented Jun 20 at 1:50
  • code 0 means the program ran successfully but clearly it did not if my motors didn't run ... yes it did, it did exactly what you told it to do ... the program has no knowledge of the existence of motors
    – jsotola
    Commented Jun 20 at 4:09
  • So, the code has run successfully but the motors are not running. Please check if your power supply is sufficient for running the motors that you are using. Check the voltage of the battery you're using. Here is also a basic tutorial on running DC motors with Raspberry Pi. You can check this out: theengineeringprojects.com/2022/04/…
    – liaifat85
    Commented Jun 20 at 16:01

1 Answer 1


Try reading the gpiozero documentation.

Putting a pause() at the end of your code will prevent the program from exiting until you close it.

https://gpiozero.readthedocs.io/en/latest/recipes.html#robot provides more realistic examples.

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.