Easiest Way to to Run DC Motor with Raspberry Pi Pico - Raspberry Pi Projects, Tutorials, Learning DIY Electronics - Makergenix

Breaking

 


Easiest Way to to Run DC Motor with Raspberry Pi Pico

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.

Easiest Way to to Run DC Motor with Raspberry Pi Pico

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

UHF HAT for Raspberry Pi

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.
    Easiest Way to to Run DC Motor with Raspberry Pi Pico
    Image credit: Tom's Hardware

Hardware Setup of DC Motor with Raspberry Pi Pico

The chip in this project is a DRV8833, and our specific version is designed for breadboards, but there are several other models available, including one designed for embedding in robots. Other motor controllers on the market, such as the L298D and L9110S, are simple and inexpensive components for robotics. The input/output conventions of all motor controllers are the same.
Place the Raspberry Pi Pico into the breadboard
Image credit: Tom's Hardware
  1. Insert the Raspberry Pi Pico into the breadboard so that the micro USB port protrudes beyond the breadboard's edge.
  2. Insert the DRV8833 motor controller into the breadboard so that the pins are on opposite sides of the central tube.
  3. 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.
  4. Connect the Raspberry Pi Pico GND pin to the DRV8833 GND pin.
  5. Connect the Raspberry Pi Pico's GPIO 14 to the DRV8833's IN1.
  6. Connect the Raspberry Pi Pico's GPIO 15 to the DRV8833's IN2.
  7. For this test, connect OUT1 and OUT2 to the motor's pins, it doesn't matter which.
    Connect OUT1 and OUT2 to the pins of the motor
    Image credit: Tom's Hardware

Raspberry Pi Pico Products Collection

DC Motor Software Configuration Using the Raspberry Pi Pico

Attach your Raspberry Pi Pico to the circuit and launch the Thonny programme.
import utime
from machine import Pin
Make two things called motor1a and motor1b. These will be used to store the GPIO pin numbers that will be used as outputs to power the DRV8833 motor controller.
motor1a = Pin(14, Pin.OUT)
motor1b = Pin(15, Pin.OUT)
Make a feature that moves the motor "in." To do this, we must instruct one pin to pull high and the other to pull low. This, in essence, signals our desired direction to the motor controller, and the resulting output pins will follow suit, causing the motor to drive in a predetermined direction.
def forward():
   motor1a.high()
   motor1b.low()
Make a feature that moves “backward.” The GPIO pin states are reversed as a result, allowing the motor to rotate in the opposite direction.
def backward():
   motor1a.low()
   motor1b.high()
Make a feature that will shut down the engine. By pulling both pins low, we instruct the motor controller to halt all motor activity.
def stop():
   motor1a.low()
   motor1b.low()
Establish a final "test" function that calls the earlier functions and runs a test sequence that moves the motor "forward" for two seconds, then "backward" for two seconds. Then motor is turned off.
def test():
   forward()
   utime.sleep(2)
   backward()
   utime.sleep(2)
   stop()
Make a for loop that runs the test function five times.
for i in range(5):
test()
Save all the code to the Raspberry Pi Pico as motor.py and then run it by clicking on the green arrow. Five seconds, the engine will spin in both directions.

Project Credit & Author: Les Pounder

Hf HAT for Raspberry Pi

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:

  1. 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. 
  2. 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.
  3. 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. 
  4. 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. 
  5. 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". 
  6. 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
  7. 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. 
  8. 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. 
  9. 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. 
  10. 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.
  11. 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. 
  12. 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. 
  13. 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. 
  14. 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. 
  15. 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.
  16. 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!
  17. 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

 


Most Viewed Posts

Write For Us

Name

Email *

Message *

All Blogs