Questions addressed in this Blog
What do you require to setup Raspberry Pi Pico with DC motors?
How do you setup the hardware for connecting Raspberry Pi Pico with DC motors?
How do you setup software for connecting Raspberry Pi Pico with DC motors?
Which Motor Controller should you use?
Which motor to use?
Why Raspberry Pi Pico?

What do you require to set up Raspberry Pi Pico with DC motors?

  1. A Raspberry Pi Pico microcontroller running any programming language (usually people prefer MicroPython as it is the most user friendly but you can also choose other programming languages like C++)
  2. 4 Male to Male jumper wires or solder and metal wires (I would suggest Jumper wires)
  3. A half-sized or a full-sized breadboard according to your requirement.
  4. A Motor controller board (you can use a DRV8833 chip or L298 chip or L9110S chip)
  5. A 5- or 6-Volt DC Motor (you can choose any type of DC motor as long as you can connect 2 male jumper cables to it or solder conducting wires to it. Some of the options are Micro Gear Metal Motor or a standard DC hobby motor) Details on types of motors.
  6. A Battery (9V/5V) acts as a power source. –> add here along with the model name/link.
  • You can use combinations of batteries with respect to correct voltage requirements.
  • As you can see different motors have different power source requirements.
  • It also depends on the amount of motors you are connecting 

You need to note that you cannot connect the Raspberry Pi Pico with the motor directly as it will not provide sufficient current and will wear very soon.

The expansion boards to be used – 

  • SparkFun Motor Driver- Dual TB6612FNG
  • Adafruit TB6612 1.2A DC/ Stepper Motor Driver Breakout Board of Adafruit brand.

How do you setup the hardware for connecting DC motor with Raspberry Pi Pico?

  • Place the Raspberry Pi Pico on the breadboard such that the micro-USB port hangs over the end of the breadboard.
  • You should place the motor controller you are using into the breadboard in a such a manner such that the pins are accessible on either side of the breadboard.
  • Then, to power the motor controller from the 5 or 6 Volts provided by the USB you need to connect the VBUS (Virtual BUS) pin of the Raspberry Pi Pico to the VCC (Voltage at Common Collector) pin of the motor controller you are using. You can use male to male jumper cables to form these connections or use conducting wires and solder.
  • Now connect the GND (Ground) pin of the Raspberry Pi Pico to that of the Motor controller you are using.
  • Then you can connect the (GPIO stands for General-Purpose Input or Output) GPIO 14 of your Raspberry Pi Pico to IN1 (or input 1) of the Motor Controller Board and connect the GPIO 15 of the Raspberry Pi Pico to the IN2 (input 2) of the motor controller.
  • Finally connect the OUT1 (output 1) and OUT2 (output 2) of the Raspberry Pi Pico to the pins of the motor ( here this connection can be in anyway).

How do you setup the software to connect DC Motor with Raspberry Pi Pico?

There are a many possible ways to code it, we are describing the simple one is as follows-

  • After completing the hardware setup (using directions showed above), you should connect it to your Raspberry Pi Pico and open any Integrated Development Environment for any coding language (for example- Thonny for Python, MicroPython, Pycharm which is an open-source platform for Python; Eclipse, Netbeans, Cmake or Visual Studio for Coke for C++ etc.); Usually, the most preferred IDE among beginners is Thonny application.
  • You should create 2 objects that store in the GPIO pin numbers which is used as output and controls the motor controller.
  • Next you have to establish a function to move the motor “forward”. In simplest terms, moving forward in terms of computer code is to tell one pin high and the other pin low at the same time (out of the 2 objects you assigned to these pins). This sends our intended direction to the motor controller and the corresponding pins will make it move in our required direction.
  • After “forward” you have to create a “backward” function. This is the opposite of the above function GPIO pin causes the motor to rotate in reverse direction.
  • Next you need to stop the motor. For that you create a function telling the motor controller to pull both its pins low and thus stop the motors’ movement.
  • Then, you form a “test” function, this function calls all the previous functions and allots them time in seconds for each function to run.
  • Lastly save the code to the Raspberry Pi Pico as dcmotor.py and run the code. So here you can form a for loop and assign the number of times you want the motor to run.

Complete code for connecting Raspberry pi pico with DC Motors

STBY = Pin 13 (GPIO #21)
 
Motor A:
PWMA = Pin 7 (GPIO #4)
AIN2 = Pin 11 (GPIO #17)
AIN1 = Pin 12 (GPIO #18)
 
Motor B:
BIN1 = Pin 15 (GPIO #22)
BIN2 = Pin 16 (GPIO #23)
PWMB = Pin 18 (GPIO #24)
( In case of one motor BIN1,BIN2 and PWMB connections.
FOR A SINGLE MOTOR CODE IS AS FOLLOWS-
#!/usr/bin/env python
 
# Import required modules
import time
import RPi.GPIO as GPIO
 
# Declare the GPIO settings
GPIO.setmode(GPIO.BOARD)// what does this do?
 
# set up GPIO pins
GPIO.setup(7, GPIO.OUT) # Connected to PWMA
GPIO.setup(11, GPIO.OUT) # Connected to MOTOR INPUT 2
GPIO.setup(12, GPIO.OUT) # Connected to MOTOR INPUT 1
GPIO.setup(13, GPIO.OUT) # Connected to STBY
 
# Drive the motor clockwise
GPIO.output(12, GPIO.HIGH) # Set MOTOR INPUT 1
GPIO.output(11, GPIO.LOW) # Set MOTOR INPUT 2
 
# Set the motor speed
GPIO.output(7, GPIO.HIGH) # Set PWMA
 
# Disable STBY (standby)
GPIO.output(13, GPIO.HIGH)
 
# Wait 5 seconds
time.sleep(5)
 
# Drive the motor counterclockwise
GPIO.output(12, GPIO.LOW) # Set MOTOR INPUT 1
GPIO.output(11, GPIO.HIGH) # Set MOTOR INPUT 2
 
# Set the motor speed
GPIO.output(7, GPIO.HIGH) # Set PWMA
 
# Disable STBY (standby)
GPIO.output(13, GPIO.HIGH)
 
# Wait 5 seconds
time.sleep(5)
 
# Reset all the GPIO pins by setting them to LOW
GPIO.output(12, GPIO.LOW) # Set MOTOR INPUT 1
GPIO.output(11, GPIO.LOW) # Set MOTOR INPUT 2
GPIO.output(7, GPIO.LOW) # Set PWMA
GPIO.output(13, GPIO.LOW) # Set STBY

FOR USING 2 MOTORS AT ONCE THE CODE IS AS FOLLOWS-
#!/usr/bin/env python
 
# Import required modules
import time
import RPi.GPIO as GPIO
 
# Declare the GPIO settings
GPIO.setmode(GPIO.BOARD)
 
# set up GPIO pins
GPIO.setup(7, GPIO.OUT) # Connected to PWMA
GPIO.setup(11, GPIO.OUT) # Connected to MOTOR INPUT 2
GPIO.setup(12, GPIO.OUT) # Connected to MOTOR INPUT 1
GPIO.setup(13, GPIO.OUT) # Connected to STBY
GPIO.setup(15, GPIO.OUT) # Connected to BIN1
GPIO.setup(16, GPIO.OUT) # Connected to BIN2
GPIO.setup(18, GPIO.OUT) # Connected to PWMB
 
# Drive the motor clockwise
# Motor A:
GPIO.output(12, GPIO.HIGH) # Set MOTOR INPUT 1
GPIO.output(11, GPIO.LOW) # Set MOTOR INPUT 2
# Motor B:
GPIO.output(15, GPIO.HIGH) # Set BIN1
GPIO.output(16, GPIO.LOW) # Set BIN2
 
# Set the motor speed
# Motor A:
GPIO.output(7, GPIO.HIGH) # Set PWMA
# Motor B:
GPIO.output(18, GPIO.HIGH) # Set PWMB
 
# Disable STBY (standby)
GPIO.output(13, GPIO.HIGH)
 
# Wait 5 seconds
time.sleep(5)
 
# Drive the motor counterclockwise
# Motor A:
GPIO.output(12, GPIO.LOW) # Set MOTOR INPUT 1
GPIO.output(11, GPIO.HIGH) # Set MOTOR INPUT 2
# Motor B:
GPIO.output(15, GPIO.LOW) # Set BIN1
GPIO.output(16, GPIO.HIGH) # Set BIN2
 
# Set the motor speed
# Motor A:
GPIO.output(7, GPIO.HIGH) # Set PWMA
# Motor B:
GPIO.output(18, GPIO.HIGH) # Set PWMB
 
# Disable STBY (standby)
GPIO.output(13, GPIO.HIGH)
 
# Wait 5 seconds
time.sleep(5)
 
# Reset all the GPIO pins by setting them to LOW
GPIO.output(12, GPIO.LOW) # Set MOTOR INPUT 1
GPIO.output(11, GPIO.LOW) # Set MOTOR INPUT 2
GPIO.output(7, GPIO.LOW) # Set PWMA
GPIO.output(13, GPIO.LOW) # Set STBY
GPIO.output(15, GPIO.LOW) # Set BIN1
GPIO.output(16, GPIO.LOW) # Set BIN2
GPIO.output(18, GPIO.LOW) # Set PWMB

(The PWM or Pulse-Width Modulation is used to describe a type of a digital signal. PWM is a method of decreasing the average power of an electrical signal, by effectively separating it up into different individual parts.)

You can also refer to the following video to connect a DC Motor to Raspberry pi pico using L298N Motor Driver.

Which motor controller should I use?

SOME OF THE COMMON OPTIONS ARE –

L293D Motor Driver IC – 

  • Voltage supply range is 4.5 V to 36 V.
  • Output Current 600mA per channel.
  • Peak Output Current 2A per channel
  • High-Noise-Immunity Inputs
  • Internal ESD protection
  • Separate Input-Logic supply
  • 16 pins chip
  •  (Additional heat sink might be required )
  • You can connect 2 motors to it at the same time

TB6612FNG

  • Power supply voltage is 15 V max
  • It has an Average Output Current of 1.2 A 
  • Its peak Output Current is 3.2A
  • Consists of a standby (power save) system
  • It has a built-in thermal shutdown circuit and low voltage detecting circuit.
  • It consists of CW/CCW/short brake/ stop function modes
  • Motor voltage preferred is in range 4.5V to 13.5V
  • You can connect 2 motors to it at the same time
  • 16 pins chip

DRV8825

  • It is a Stepper Driver Module
  • Its operating voltage range is from 8.2V to 45V
  • Its peak current per phase is 2.5A
  • It has an adjustable output current via potentiometer.
  • Consists of an over temperature shutdown circuit 
  • Consists of undervoltage lockout
  • It also consists of over voltage shutdown
  • 28 pins chip
  • You can connect 2 motors to it at the same time ( but the voltages must be lesser than the others)

4. L9110S

  • Motor Voltage range is 2.5 V to 12 V
  • Logic Voltage range is 2.5 V to 12 V
  • Current provided is 800mA
  • Peak current performance is 2A
  • The circuit does invert for that you might require TLP281 module which with help of its added transistors un-inverts the signal.
  • You can connect 2 motors to it at the same time

Which motor to use?

SOME OF THE COMMON OPTIONS ARE-

DC Motors

  • It is a mechanism that converts DC power (electrical energy) to mechanical power. 
  • This DC power can be produced by magnetic fields. These change the current direction periodically in the motor causing the rotary motion.
  • There are various types of DC motors of different voltages and different currents. The ones commonly used in small experiments are 5V or 6V DC motors. 
  • Standard 130 type DC Motor has an operating voltage range from 4.5V to 9V. But recommended or rated voltage 6V
  • Current at no load is 70 mA (at max)
  • Loaded current is approximately 250mA 
  • Its no-load speed is 9000rpm

Micro Metal Gear Motors

  • Micro Metal Gear motors are small DC gear motors
  • They are accessible in a vast variety of gear ratios from 5:1 to 1000:1
  • They can be of High Power (HP), Medium Power (MP) and Low Power (LP) depending on whether they have precious metal brushes or longer life carbon brushes.
  •  A DC gear motor has gear assembly attached to DC motor as shown in the name. This gear assembly provides the advantage of increase in torque (also known as gear reduction) and reduction in the speed.
  • For a standard DC gear motor, the voltage range is 3V to 12 V (gear ratio 30:1)
  • Its stall torque is 45.6 oz-in at 12V performance
  • It is DC Reversible and has a Dielectric strength of 300VDC
  • It has a no-load current of 95mA at 12 V
  • Its insulation resistance is 10 MOhm
  • Its stall current is 0.5A at 12V.

Why Raspberry Pi Pico?

Before the launch of Raspberry Pi Pico, Arduino ( an open-source electronics platform based on simple hardware and software to make interactive projects like the one showed above) was the one used.

Raspberry Pi Pico offers you a series of PIO pins which can be arranged to imitate different interfaces or protocols. They can also be used diverse different tasks to a background procedure.

Raspberry Pi Pico is more cost effective compared to any of Arduino’s products. It is just a $4 chip.

Raspberry Pi Pico comes with options of using C, C++ and MicroPython. It suggests MicroPython for beginners but for the high-level functions C and C++ can be used.

Raspberry Pi Pico comes as an unsoldered microcontroller whereas Arduino comes as soldered, this is useful in case of applying jumper cables. If you still want to solder your cables it is not very difficult.

0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments