Matha Goram
Published © GPL3+

Spin Your DC Motors

DC Motors are simplest of motors to drive a robot car as a beginner. The precision can be extended through additional circuitry & sensors.

BeginnerFull instructions provided1 hour142
Spin Your DC Motors

Things used in this project

Hardware components

Cytron Technologies Maker Pi RP2040
×1
Cytron Technologies Two wheel robot car kit
×1
Raspberry Pi 3 or 4
×1
Cytron Technologies USB-A Micro USB cable (generic)
×1
AA Batteries
AA Batteries
×4

Software apps and online services

Cytron Technologies CircuitPython
Thonny or mu IDE, as appropriate
Available on Raspberry Pi OS (previously known as Raspbian) platform
Raspbian
Raspberry Pi Raspbian

Story

Read more

Schematics

Maker Pi RP2040 Robotics Controller Board

The controller has an on-board RP2040 chip whose functionality is extended by several supplementary circuits.

Code

Test_DCmotor_01.py

Python
Test the robot car for linear movement
# Test_DCmotor_01.py
# Run basic linear movement test for robot car with two DC motors
# v0.1 2021-08-12 Initial DRAFT
# required libraries
import board
import time
import pwmio
from adafruit_motor import motor
# initialize DC motors using Cytron Maker Pi pin assignments for mxy where x={1,2} & y={a,b}
m1a = pwmio.PWMOut(board.GP8, frequency=25)
m1b = pwmio.PWMOut(board.GP9, frequency=25)
motor_right = motor.DCMotor(m1a, m1b)
m2a = pwmio.PWMOut(board.GP10, frequency=25)
m2b = pwmio.PWMOut(board.GP11, frequency=25)
motor_left = motor.DCMotor(m2a, m2b)
# pause for manual placement of robot car
time.sleep(5)
# set both DC motors to move forward
motor_right.throttle = 0.5
motor_left.throttle = 0.5
# set duration of forward movement
time.sleep(1)
# stop both motors
motor_right.throttle = 0
motor_left.throttle = 0
# pause
time.sleep(5)
# set both DC motors to move backward
motor_right.throttle = -0.5
motor_left.throttle = -0.5
# set duration of backward movement
time.sleep(1)
# stop both motors
motor_right.throttle = 0
motor_left.throttle = 0

Test_DCmotor_02.py

Python
Test the robot car for turn movements
# Test_DCmotor_02.py
# Run basic angular movement test for robot car with two DC motors
# v0.1 2021-08-12 Initial DRAFT
# required libraries
import board
import time
import pwmio
from adafruit_motor import motor
# initialize DC motors using Cytron Maker Pi pin assignments for mxy where x={1,2} & y={a,b}
m1a = pwmio.PWMOut(board.GP8, frequency=25)
m1b = pwmio.PWMOut(board.GP9, frequency=25)
motor_right = motor.DCMotor(m1a, m1b)
m2a = pwmio.PWMOut(board.GP10, frequency=25)
m2b = pwmio.PWMOut(board.GP11, frequency=25)
motor_left = motor.DCMotor(m2a, m2b)
# pause for manual placement of robot car
time.sleep(5)
# set only right motor to rotate
motor_right.throttle = 0.5
motor_left.throttle = 0
# set duration of forward movement
time.sleep(1)
# stop right motor
motor_right.throttle = 0
# pause
time.sleep(5)
# set both DC motors to rotate backward
motor_right.throttle = -0.5
# set duration of backward movement
time.sleep(1)
# stop right motors
motor_right.throttle = 0
# pause for next test
time.sleep(5)
# set both DC motors to rotate in opposite directions
motor_right.throttle = 0.5
motor_left.throttle = -0.5
# set duration of forward movement
time.sleep(1)
# stop both motors
motor_right.throttle = 0
motor_left.throttle = 0
# pause
time.sleep(5)
# set both DC motors to move backward
motor_right.throttle = -0.5
motor_left.throttle = 0.5
# set duration of backward movement
time.sleep(1)
# stop both motors
motor_right.throttle = 0
motor_left.throttle = 0

Credits

Matha Goram

Matha Goram

27 projects • 22 followers
Working with discrete electronic components for a very long time but still suffering from the occasional dry soldering results.
Thanks to Sufy Isma.

Comments