Carlotta Berry
Published

Lily∞Bot with Raspberry Pi Pico W: Motor Control

This project will describe how to use Raspberry PI Pico W and TB6612 to control motors on the robot.

IntermediateFull instructions provided2 hours554
Lily∞Bot with Raspberry Pi Pico W: Motor Control

Things used in this project

Hardware components

SparkFun Motor Driver - Dual TB6612FNG (with Headers)
SparkFun Motor Driver - Dual TB6612FNG (with Headers)
×1
DC Motor, 12 V
DC Motor, 12 V
×2
Raspberry Pi Pico W
Raspberry Pi Pico W
×1
LilyBot
×1

Software apps and online services

Visual Studio 2015
Microsoft Visual Studio 2015
MicroPython
MicroPython
PlatformIO IDE
PlatformIO IDE

Story

Read more

Custom parts and enclosures

Lily Bot GIT HUB Repository

Lily∞Bot with TB6612 motor driver and 2 motors & Raspberry PI PicoW

Schematics

Lily Bot GIT HUB Repository

Lily Bot with Raspberry PI Pico W with TB6612 motor driver & 2 DC motors

Lily∞Bot with TB6612 motor driver and 2 DC motors with Raspberry PI Pico W

Code

Lily∞Bot motor control code in Raspberry Pi Pico W with MicroPython

MicroPython
#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 LilyBot...")

while True:
    forward()
    sleep_ms(500)
    stop()
    sleep_ms(500)
    reverse()
    sleep_ms(500)
    stop()
    sleep_ms(500)

Lily Bot GIT HUB Repository

Credits

Carlotta Berry
14 projects • 22 followers
Carlotta Berry is a Professor and Dr. Lawrence J. Giacoletto Endowed Chair for Electrical and Computer Engineering at Rose-Hulman.
Contact

Comments

Please log in or sign up to comment.