By Kevin McAleer, 7 Minutes
Page last updated November 24, 2026

By the end of this lesson you will be able to wire an L298N or a DRV8833 to a Pico with a separate motor battery, and spin a motor in both directions from MicroPython.
Time to build. We will wire Scout’s two motors to an L298N driver, test one motor with a few lines of code, then look at the smaller DRV8833 as an alternative. Do the wiring with everything powered off, and check the battery’s positive and negative leads twice before you connect them, because a reversed battery can destroy a driver.
The L298N has two channels. Channel A drives Scout’s left motor, and channel B drives the right. This is the same layout as the MicroPython Robotics course.
| Pico pin | L298N pin | Job |
|---|---|---|
| GP0 | IN1 | Left motor direction |
| GP1 | IN2 | Left motor direction |
| GP2 | ENA | Left motor speed (PWM) |
| GP3 | IN3 | Right motor direction |
| GP4 | IN4 | Right motor direction |
| GP5 | ENB | Right motor speed (PWM) |
| GND | GND | Common ground |
Then the power side:
| Connection | Goes to |
|---|---|
| Battery pack positive | L298N 12V terminal (the motor supply input) |
| Battery pack negative | L298N GND terminal |
| Left motor wires | OUT1 and OUT2 |
| Right motor wires | OUT3 and OUT4 |
This is the whole L298N setup as a picture, with the signal wires from the Pico on one side and the power on the other:
flowchart LR
subgraph PICO["Raspberry Pi Pico"]
P1["GP0, GP1, GP2"]
P2["GP3, GP4, GP5"]
PG["GND"]
end
subgraph DRV["L298N board"]
D1["IN1, IN2, ENA"]
D2["IN3, IN4, ENB"]
DG["GND"]
DV["12V motor supply input"]
OUT["OUT1 to OUT4"]
end
P1 --> D1
P2 --> D2
PG --- DG
BAT["4xAA battery pack"] --> DV
BAT --- DG
OUT --> ML["Left motor: OUT1, OUT2"]
OUT --> MR["Right motor: OUT3, OUT4"]
Three things catch people out:
Left motor only, full speed, one second each way. Because ENA is just a pin set high, this is the plain truth table from lesson 4:
from machine import Pin
from time import sleep_ms
in1 = Pin(0, Pin.OUT)
in2 = Pin(1, Pin.OUT)
ena = Pin(2, Pin.OUT)
try:
ena.value(1) # enable the bridge
in1.value(1); in2.value(0) # forward
sleep_ms(1000)
in1.value(1); in2.value(1) # brake
sleep_ms(500)
in1.value(0); in2.value(1) # reverse
sleep_ms(1000)
finally:
ena.value(0) # coast, whatever happens
in1.value(0); in2.value(0)
Run it. The wheel should go forward, stop, reverse. If it goes the wrong way round, swap the two motor wires on OUT1 and OUT2. That is all “forward” means: whichever direction we decide. Scout’s code will later get an invert option so you never have to rewire.
The try and finally is a habit worth forming. If you stop the program with Ctrl+C partway through, the finally block still switches the motor off.
The DRV8833 is smaller, cooler and wastes far less battery voltage. It has no enable pins, so it needs only four Pico pins. We keep GP0, GP1, GP3 and GP4 so the layout matches the L298N:
| Pico pin | DRV8833 pin | Job |
|---|---|---|
| GP0 | AIN1 | Left motor, PWM |
| GP1 | AIN2 | Left motor, PWM |
| GP3 | BIN1 | Right motor, PWM |
| GP4 | BIN2 | Right motor, PWM |
| 3V3 | SLP (nSLEEP) | Held high to keep the chip awake |
| GND | GND | Common ground |
The battery goes to VM (motor supply) and GND, and the motors go to AOUT1/AOUT2 and BOUT1/BOUT2. Many breakout boards already pull SLP high, so check yours. GP2 and GP5 are not used.
The code is just as short, but now the speed lives on the input pins:
from machine import Pin, PWM
from time import sleep_ms
in1 = PWM(Pin(0))
in2 = PWM(Pin(1))
in1.freq(10000)
in2.freq(10000)
try:
in1.duty_u16(32768) # roughly half speed forward
in2.duty_u16(0)
sleep_ms(1000)
in1.duty_u16(0) # reverse at half speed
in2.duty_u16(32768)
sleep_ms(1000)
finally:
in1.duty_u16(0) # both low: coast
in2.duty_u16(0)
Ratings to remember: the DRV8833 takes 2.7 to 10.8 V and about 1.5 A per channel, which is perfect for TT motors. The L298N takes 5 to 35 V and about 2 A per channel, but it runs warm.
Why: With EN low the bridge is disabled, and with no common ground the inputs are meaningless.
Why: The chip sleeps whenever nSLEEP is low, and under-voltage protection shuts it off.
Teachers: wire with the batteries out. Reversed battery leads and loose wires touching are the usual causes of dead drivers, so have a second learner check each connection against the tables. The L298N heatsink gets hot after a few seconds of running, so remind learners not to grab it. If boards are shared, label them with their jumper settings so the next group knows whether the ENA and ENB jumpers have been removed.
Quick quiz 1 of 3
Why do you remove the ENA and ENB jumpers on the L298N?
Quick quiz 2 of 3
Where does the speed PWM go on an L298N compared with a DRV8833?
Quick quiz 3 of 3
Which three grounds must be joined?
Comments