

It is a commonly used component for prototypes and hobbyist projects, as it is easy to use and interface the L298 with a Raspberry Pi or an Arduino. This circuit allows you to control two DC motors independently in either direction.


Special thanks to Alex Wilkinson for providing the basis for this sample code!Ĭertain Pi HATs might make use of some of the pins above-so if you have some sort of HAT/board connected to your Pi's GPIO header, you may need to adjust the pins selected above to output things properly.įor example, I'm using a Pimoroni Speaker pHAT on my motorized Pi I checked the Speaker pHAT pinout and discovered that GPIO pin 12 is in use by the HAT, so I'm using an alternate pin (16) instead. L298 is known as a dual bidirectional motor driver which is based on dual H-Bridge Motor driver IC. GPIO.output(13, GPIO.LOW) # Set STBY Drive two motors: #!/usr/bin/env python # Reset all the GPIO pins by setting them to LOW Paste the following code, save, and exit: Drive a single motor: #!/usr/bin/env python How to Connect to a Raspberry Pi Remotely via SSH The preferred (and most common) method of connecting to your Pi to run commands.
