This project demonstrates how to control motors using the GPIO pins on a Raspberry Pi with the help of the gpiozero
library and the curses
library for keyboard input. This setup allows you to control two motors to move forward, backward, turn left, and turn right based on keyboard inputs.
Before running this script, ensure you have the following:
- A Raspberry Pi with GPIO pins
- Two motors correctly connected to the Raspberry Pi GPIO pins
- Python 3 installed on your Raspberry Pi
gpiozero
andcurses
libraries installed. You can install them using pip:
pip install gpiozero
Hardware Setup
Connect the forward, backward, and enable pins of Motor A to GPIO pins 22, 23, and 17 respectively.
Connect the forward, backward, and enable pins of Motor B to GPIO pins 24, 25, and 27 respectively.
Ensure your motors are powered and can handle the GPIO signal levels.
Software
This script provides the following functionality:
Forward: Both motors will turn in the forward direction.
Backward: Both motors will turn in the backward direction.
Turn Left: Motor A moves forward while Motor B moves backward.
Turn Right: Motor A moves backward while Motor B moves forward.
Stop: Both motors will stop.
Quit: Stops the motors and exits the program.
Running the Script
To run the script, execute the following command in the terminal:
bash
python motor_control.py
Controls
s - Move forward
w - Move backward
d - Turn left
a - Turn right
SPACE - Stop the motors
q - Quit the program
Safety Notice
Always ensure your Raspberry Pi is powered off when connecting or disconnecting motors to avoid any damage to the hardware.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please fork the repository and open a pull request with your improvements.
vbnet
Ensure you replace placeholder texts as necessary based on your project's sp