This blog post will explain how to use a motor driver to control two DC motors. The MicroPython code listed below is used to accomplish this task. Functions for directions such as stop, forward, left, and right have to be declared. Pins 21 and 22 have to setup to output voltage needed to power the motor driver and motors. Each pin can be set to high or low voltage. High means the motor driver is spinning the wheel. Low means the motor driver is not spinning the wheel. In order for the robot to turn left or right, one pin has to set to high and the other pin to low.
from time import sleep
from machine import Pin
motor1a=Pin(21, Pin.OUT)
motor1b=Pin(22, Pin.OUT)
def forward():
motor1a.high()
motor1b.high()
motor1a.high()
motor1b.low()
def left():
motor1a.low()
motor1b.high()
def stop():
motor1a.low()
motor1b.low()
forward()
sleep((1))
stop()
left()
sleep((1))
stop()
right()
sleep((1))
stop()