Interfacing L298N H-bridge motor driver with raspberry pi

First things first, if you have not checked out my previous blog about how to set up a raspberry pi with out an HDMI cable and monitor, then have a quick read this blog.

  1. Software Program and testing
L298N — H Bridge Motor Driver.
Red light glowing once power is ON.
Connections of L298N with Pi
import RPi.GPIO as gpio
import time
def init():
gpio.setmode(gpio.BCM)
gpio.setup(17, gpio.OUT)
gpio.setup(22, gpio.OUT)
gpio.setup(23, gpio.OUT)
gpio.setup(24, gpio.OUT)
def forward(sec):
init()
gpio.output(17, False)
gpio.output(22, True)
gpio.output(23, True)
gpio.output(24, False)
time.sleep(sec)
gpio.cleanup()
def reverse(sec):
init()
gpio.output(17, True)
gpio.output(22, False)
gpio.output(23, False)7
gpio.output(24, True)
time.sleep(sec)
gpio.cleanup()
def left_turn(sec):
init()
gpio.output(17, True)
gpio.output(22, False)
gpio.output(23, True)
gpio.output(24, False)
time.sleep(sec)
gpio.cleanup()
def right_turn(sec):
init()
gpio.output(17, False)
gpio.output(22, True)
gpio.output(23, False)
gpio.output(24, True)
time.sleep(sec)
gpio.cleanup()
seconds = 3time.sleep(seconds)
print("forward")
forward(seconds)
time.sleep(seconds-2)
print("right")
right_turn(seconds)
time.sleep(seconds-2)
time.sleep(seconds)
print("forward")
forward(seconds)
time.sleep(seconds-2)
print("right")
right_turn(seconds)
time.sleep(seconds-2)
Testing
Photo by Lavi Perchik on Unsplash
Photo by Anna Louise on Unsplash

Autonomous Vehicles Algorithm Developer