Build the Circuit
Wire the Code
Read more- Use the following steps to wire the TB6612 motor driver to the Raspberry PI Pico W and two DC Motors
- Put the TB6612 motor driver in one end of the breadboard with the USB connection at the end near the end of the breadboard.
- Connect the left motor to motor A (red, blk) on the TB6612
- Connect the right motor to motor B (red, blk) on the TB6612
- Use two wires to connect VCC and VM on the TB6612 to VBUS on the Raspberry PI Pico W. One option is to put VBUS on a row of the breadboard and use wires to connect there.
- Use a wire to connect PWMA on the TB6612 motor controller to pin 28 on Raspberry PI Pico W
- Use a wire to connect AIN2 on the TB6612 motor controller to pin 27 on Raspberry PI Pico W
- Use a wire to connect AIN1 on the TB6612 motor controller to pin 26 on Raspberry PI Pico W
- Use a wire to connect BIN1 on the TB6612 motor controller to pin 22 on Raspberry PI Pico W
- Use a wire to connect BIN2 on the TB6612 motor controller to pin 21 on Raspberry PI Pico W
- Use a wire to connect PWMB on the TB6612 motor controller to pin 20 on Raspberry PI Pico W
Breadboard Nodes
Raspberry PI Pico W pinout
Fritzing wiring diagram for Raspberry PI Pico W, 2 DC motors and TB6612 motor driver
- In PlatformIO Visual Studio create a.py file and configure it as a MicroPico project
- Paste the following code in the file and save it
- Right click on the file name and select "Run current file on the Pico"
#motor.py CAB 9.14.23
#This code will drive the LilyBot using the TB6612 motor drive
#https://www.noiresteminist.com/shop
#Carlotta Berry 9.14.23
from machine import Pin, PWM
from time import sleep_ms
#define inputs and outputs
PWMA = PWM(Pin(28))
AIN2 = Pin(27, Pin.OUT)
AIN1 = Pin(26, Pin.OUT)
PWMA.freq(60)
BIN1 = Pin(22, Pin.OUT)
BIN2 = Pin(21, Pin.OUT)
PWMB = PWM(Pin(20))
PWMB.freq(60)
motorSpeed = 65535
def reverse():
AIN1.value(1)
AIN2.value(0)
BIN1.value(1)
BIN2.value(0)
PWMA.duty_u16(motorSpeed)
PWMB.duty_u16(motorSpeed)
def forward():
AIN1.value(0)
AIN2.value(1)
BIN1.value(0)
BIN2.value(1)
PWMA.duty_u16(motorSpeed)
PWMB.duty_u16(motorSpeed)
def stop():
AIN1.value(0)
AIN2.value(0)
BIN1.value(0)
BIN2.value(0)
print("Motor control on Lily∞Bot...")
while True:
forward()
sleep_ms(500)
stop()
sleep_ms(500)
reverse()
sleep_ms(500)
stop()
sleep_ms(500)
Verify It Works- Watch the following video to confirm that everything is working as it should be
- If it is not, try to debug and trouble shoot the wiring and code.
14 projects • 22 followers
Carlotta Berry is a Professor and Dr. Lawrence J. Giacoletto Endowed Chair for Electrical and Computer Engineering at Rose-Hulman.
Comments
Please log in or sign up to comment.