The Raspberry Pi Pico is an enticingly thin, but powerful board that allows users to build both large and small projects. Robotics is one form of project that requires motors. So, how do we use a Raspberry Pi Pico to power DC motors? Can we bind them to the GPIO directly? The simple answer is no.
The Raspberry Pi Pico's GPIO pins cannot deliver the current required for a DC motor, and attempting to do so risks damaging the Pico. Instead, we need a motor controller to serve as a link between the Pico and our motor. We toggle two Pico GPIO pins on and off, which controls the motor controller, which toggles two outputs to make the motor run.
Also Read:
You will need:
- Raspberry Pi Pico running MicroPython (see how to set up a Raspberry Pi Pico),
- Thonny mounted on your device,
- 4 x Male to Male jumper wires for this project.
- half or full size breadboard or Raspberry Pi Pico Breadboard Kit
- Motor controller board, (in this project we used DRV8833 but I'll recommend you to use recently launched Pico Motor Driver HAT by SB Components) We used a DRV8833 chip in our case, but L298 or L9110S chips should also work.
- DC Motor 5V / 6V We used a micro gear metal motor, but a standard DC hobby motor would work just as well. It should be noted that the motor would need two male to male jumper wires to attach to the breadboard.
Image credit: Tom's Hardware
Hardware Setup of DC Motor with Raspberry Pi Pico
Image credit: Tom's Hardware |
- Insert the Raspberry Pi Pico into the breadboard so that the micro USB port protrudes beyond the breadboard's edge.
- Insert the DRV8833 motor controller into the breadboard so that the pins are on opposite sides of the central tube.
- Using a jumper cable, connect the Raspberry Pi Pico's VBUS pin to the DRV8833's VCC pin. This will directly fuel the motor controller from the 5V supplied by USB.
- Connect the Raspberry Pi Pico GND pin to the DRV8833 GND pin.
- Connect the Raspberry Pi Pico's GPIO 14 to the DRV8833's IN1.
- Connect the Raspberry Pi Pico's GPIO 15 to the DRV8833's IN2.
- For this test, connect OUT1 and OUT2 to the motor's pins, it doesn't matter which.
Image credit: Tom's Hardware
DC Motor Software Configuration Using the Raspberry Pi Pico
import utime
from machine import Pin
motor1a = Pin(14, Pin.OUT)
motor1b = Pin(15, Pin.OUT)
def forward():
motor1a.high()
motor1b.low()
def backward():
motor1a.low()
motor1b.high()
def stop():
motor1a.low()
motor1b.low()
def test():
forward()
utime.sleep(2)
backward()
utime.sleep(2)
stop()
for i in range(5):
test()
Project Credit & Author: Les Pounder
The lifeblood of the Raspberry Pi and maker communities is the first and third component accessories. They provide new features and make it easier to complete projects.
SB Components, a UK-based official Raspberry Pi Reseller, was the first to market. They have launched 17 new Pico accessories, ranging from basic breakout boards that allow several addons to be utilised for DIY projects to exploring the potential of the Raspberry Pi Pico, and a Pico LoRa™ Expansion board, which comes with an onboard CH340 USB TO UART converter, Voltage Level Translator(74HC125V), E22-900T22S SMA antenna connector that covers 868MHz & 433MHz frequency band. We have shared the products below:
- Pico LoRa Expansion 868MHz : Pico LoRa™ Expansion is a low-power consumption data transmission board that includes an onboard CH340 USB TO UART converter, a Voltage Level Translator (74HC125V), an E22-900T22S SMA antenna connector that covers the 868MHz frequency band, an onboard 1.14" LCD, an IPEX antenna connector, and LoRa™ Spread Spectrum Modulation technology with auto multi-level repeating. Pico LoRa™ Expansion is developed to enable data transmission up to 5 KM through serial port. Pico LoRa™ Expansion was created to allow data transfer up to 5 kilometres through serial interface. 433MHz LoRa Expansion for Pico also Available.
- 1.28” Round LCD HAT for Pico : 1.28-inch display HAT with 240 x 240 resolution, 65K RGB colours, crisp and colourful display effect, and joystick, developed for the Raspberry Pi Pico to broaden its engagement through SPI connection by offering a standard 40 pin Pico GPIO interface.
- 1.14” LCD HAT For Pico : 1.14-inch display expansion board module with a joystick and a resolution of 240135, 65K RGB colours, clean and colourful presenting effect, created specifically for Raspberry Pi Pico to increase its involvement through SPI connection by offering a standard 40 pin GPIO interface.
- Pico Motor Driver HAT : DC motor control module supplied by one H-bridge IC L293D with a motor input supply voltage range of 6 V to 12 V. It is intended to link two DC motors at the same time or one stepper motor, allowing the user to create projects with a small footprint and great efficiency.
- Pico RTC (Real Time Clock) HAT : Real-Time clock extension module with the powerful IC DS3231, backup battery holder, 3.3 V working voltage, and Fast (400kHz) I2C Interface that detects time and aligns the device's time with the "Real-Time".
- Pico RFID Expansion : RFID Reader with a 125KHz frequency and a small design that includes a programmable 0.91” Oled screen and an improved UART/I2C interface that is compatible with the Raspberry Pi Pico Board.
- Pico Dual Channel Relay HAT : Relay HAT is a two-channel high-quality relay with loads up to 250V AC/ 7 A, 30V DC/ 10A to control high voltage/current devices.
- Pico Single Channel Relay HAT : It can handle loads of up to 250V AC/ 7A and 30V DC/ 10A, allowing you to manage high voltage/current devices. It has a Female Pin Header for easy connection to the Raspberry Pi Pico through stacking.
- Pico 3V Relay HAT : High-quality two-channel relay with a switching voltage (VAC) of up to 2A/120V (Max), a switching voltage (VDC) of up to 2A/24V (Max), and an operating voltage of 3.3V.
- Pico 2 Channel Expander : Pico 2 CH Expander is intended specifically for use as a GPIO extender, having 2 sets of 2 x 20 pin headers for connecting to HATs or Breadboards.
- Pico 4 Channel Expander : Pico 4 Channel Expander is intended to function as a GPIO extender by offering 4 sets of two 20-pin headers for use with HATs or breadboards.
- Pico HAT Expansion : HAT Expansion is a Raspberry Pi Pico input/output expansion board that includes one set of 2x20 pin headers in the form of a Raspberry Pi Header and one set of 2 x 20 pin. This implies that any HAT developed for the Raspberry Pi Board can be plugged in.
- Pico GPIO Expansion Board : Pico GPIO Expansion Board with 3.3 V output voltage. Pico GPIO Expansion Board is designed to split off all of the Raspberry Pi Pico development board's pins and power in two ways (male or female header). It enables the user to connect it to other components via a jumper wire.
- Pico Breadboard Kit : A multi-purpose Kit with a "400 points half-size breadboard" on top, a Programmable Buzzer, 4 Programmable LEDs, 4 Push buttons, and dedicated 5V, 3v3, and GND pins all in one spot. It contains sophisticated features like as individually controlled LEDs, switches, and a 400-point half-size breadboard that allows users to efficiently prototype their ideas using the Raspberry Pi Pico.
- Pico Relay Board : Up to four appliances and loads of up to 250V AC at 7A and 30V DC at 10A can be controlled. It allows users to control high-voltage/high-current devices. It has a “Optocoupler,” which enables the circuit to convey an electrical signal between two separated circuits using light energy.
- Pico Zero Board : Pico Zero Board is a useful and well-labelled board with a 6x20 grid of 2.54mm spacing mounting holes that allows users to quickly solder the Pico pins. With properly connecting bespoke circuits, the Pico Zero Board provides a secure, compact, and long-term safe housing for your breadboard project!
- Pico Zero Expansion : cleanly labelled expansion, with a 6x20 grid in the centre for the Raspberry Pi Pico and an 8x20 grid on both sides to connect peripherals, 2.54mm spacing mounting holes suited for users to simply solder the Pico pins
Also Check:
- How to Install Wi-Fi and Internet on a Raspberry Pi Pico
- Pico Projects For Beginners - Raspberry Pi
- How to connect a Raspberry Pi Pico to LoRaWAN
- Best Raspberry Pi Pico Breakout And Pico HAT
- How to use I2C Pins in Raspberry Pi Pico | I2C Scanner Code
- Raspberry Pi Pico Launched Globally With Pico Add-On & Pico Expansions.
- Raspberry Pi Pico 2 Channel Expander | GPIO Expander For Pico