Rpi Pico Motor Controllers

How to Use Your Raspberry Pi Pico With DC Motors

By Les Pounder 5 days ago

Make things move with your Raspberry Pi Pico and a DC motor.

 Comments (1)

Raspberry Pi Pico With DC Motors

(Image credit: Tom’s Hardware)

The Raspberry Pi Pico is an enticingly small, yet powerful board that offers users the chance to create projects both great and small. One type of project is robotics and for this we need motors. So how can we control DC motors with a Raspberry Pi Pico? Can we connect them directly to the GPIO? The short answer is no. 

The GPIO pins of the Raspberry Pi Pico cannot deliver the current needed for a DC motor and, if we were to try, there is a good chance that we would damage the Pico. Instead we need a motor controller that acts as a bridge between the Pico and our motor. We turn two Pico GPIO pins on / off and they control the motor controller which will in turn, turn on / off two outputs to make the motor move.

For this project you will need

  • Raspberry Pi Pico running MicroPython (see how to set up Raspberry Pi Pico)
  • Thonny installed on your computer
  • 4 x Male to male jumper wires
  • Half or full-size breadboard
  • Motor controller board. In our case, we used a DRV8833 chip, but L298 or L9110S chips should also work.
  • 5V / 6V DC Motor. We used a micro gear metal motor, but a standard DC hobby motor will also work. Note that the motor will need 2 x male to male jumper wires to connect to the breadboard.
Raspberry Pi Pico With DC Motors
(Image credit: Tom’s Hardware)

Hardware Setup of DC Motor with Raspberry Pi Pico

The chip we are using in this project is a DRV8833 and our particular version is made for breadboards, but there are many other versions including a version designed for embedding in robots. There are also other motor controllers on the market, such as the L298D and L9110S which are simple and affordable components for robotics. All motor controllers share the same input/output conventions. ADVERTISING

Raspberry Pi Pico With DC Motors
(Image credit: Tom’s Hardware)
  1. Place the Raspberry Pi Pico into the breadboard so that the micro USB port hangs over the end of the breadboard.
  2. Place the DRV8833 motor controller into the breadboard so that the pins are either side of the central channel.
  3. Connect the VBUS pin of the Raspberry Pi Pico to the VCC pin of the DRV8833 using a jumper wire. This will power the motor controller directly from the 5V supplied via USB.
  4. Connect the Raspberry Pi Pico GND pin to the GND pin of the DRV8833.
  5. Connect GPIO 14 of the Raspberry Pi Pico to IN1 of the DRV8833.
  6. Connect GPIO 15 of the Raspberry Pi Pico to IN2 of the DRV8833.
  7. Connect OUT1 and OUT2 to the pins of the motor, it doesn’t matter which for this test.
Raspberry Pi Pico With DC Motors
(Image credit: Tom’s Hardware)

Software Setup of DC Motor with Raspberry Pi Pico 

With the circuit built, connect your Raspberry Pi Pico and open the Thonny application.RECOMMENDED VIDEOS FOR YOU…https://www.ultimedia.com/deliver/generic/iframe?mdtk=02657680&zone=2&type_player=0&sendstats=0&src=flkq0f&width=564&height=317&urlfacebook=https%3A%2F%2Fwww.tomshardware.com%2F&ad=1&autoplay=yes&fstart=1&title=The+Tom%27s+Hardware+Show+%28May+28%29%3A+Raspberry+Pi+8GB%2C+Intel+Code+Names%2C+New+VR&endMessage=um_ultimedia_wrapper_ultimediaEndRoll&widgetPrefix=um_ultimedia_wrapper_&tagparam=&tagparamdecoded=&sspParam=&visible=&gdprconsentstring=

import utime
from machine import Pin

2. Create two objects, motor1a and motor1b. These will store the GPIO pin numbers used as outputs to control the DRV8833 motor controller.

motor1a = Pin(14, Pin.OUT)
motor1b = Pin(15, Pin.OUT)

3. Create a function to move the motor “forward”. To do this we need to tell one pin to pull high, the other low. This, in turn, communicates our intended direction to the motor controller and the corresponding output pins will follow suit forcing the motor to move in a set direction.

def forward():

4. Create a function to move “backward.” This sees the GPIO pin states reverse, causing the motor to spin in the opposite direction.

def backward():

5. Create a function to stop the motor. By pulling both pins low, we tell the motor controller to stop all movement of the motor.

def stop():

6. Create a final “test” function that will call the previous functions and run a test sequence that will spin the motor “forward” for two seconds, then “backward” for two seconds. It then stops the motor.

def test():

7. Create a for loop which will run the test function five times.

for i in range(5):

Save the code to the Raspberry Pi Pico as motor.py and click on the green arrow to run the code. The motor will rotate in both directions five times.


Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.