0

DC motor demo with Circuit Python
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

DC motor demo with Circuit Python

by DanGR on Wed Feb 10, 2021 5:28 pm

I am making some DC motor demonstration test stands for a virtual classroom. The parts used for this setup are:
1) https://www.adafruit.com/product/4600 QT Py controller.
2) https://www.adafruit.com/product/3882 DC motor
3) https://www.adafruit.com/product/3896 propeller for DC motor load
4) https://www.adafruit.com/product/858 5V stepper motor
5) https://www.adafruit.com/product/807 dual H-bridge

I will upgrade the last item to either:
1) https://www.adafruit.com/product/2448 TB6612 1.2A DC/Stepper Motor Driver
2) https://www.adafruit.com/product/3297 DRV8833 DC/Stepper Motor Driver

I just ordered one of each but I am wondering which will suit my purpose the best.

2021-02-10 14.24.30-1.jpg
2021-02-10 14.24.30-1.jpg (87.83 KiB) Viewed 1116 times


The main question I have is where can I find a Circuit Python tutorial that has the code needed to drive a DC motor forward and reverse for one of the breakout boards listed?

The tutorial for the DRV8833 and TB6612 boards shows how to use CP for a stepper motor, but for a DC motor, I can only find Arduino code. I have looked at read the docs: https://circuitpython.readthedocs.io/pr ... or.DCMotor
I checked the source code and I do not see how to define the pins for the controller. The pins are defined for the stepper motor example, so can someone please send me in the correct direction or show me how to define the pins for a DC motor?

Thanks Dan

DanGR
 
Posts: 110
Joined: Thu Oct 16, 2014 10:20 am

Re: DC motor demo with Circuit Python

by adafruit_support_carter on Wed Feb 10, 2021 6:34 pm

Either of those will work. They are both "dual H bridges".

Here's an example using the TB6612. Note that I'm powering the motor from the USB bus, which isn't recommended. I just did that for a quick test. Using a separate dedicated power supply for the motor would be better. For my setup, I had several USB disconnects when running the motor. :(

The TB6612 has a dedicated PWM control pin, which could also be used. But the motor library is setup to use the main AIN pins. So the PWM pin is simply connected to VCC to "enable". And then actual PWM control is done on the other pins. You would use the DRV8833 in a similar way.

Code: Select all | TOGGLE FULL SIZE
import board
import pulseio
from adafruit_motor import motor

AIN1 = pulseio.PWMOut(board.A3, frequency=100)
AIN2 = pulseio.PWMOut(board.A2, frequency=100)

m = motor.DCMotor(AIN1, AIN2)

m.throttle = 0.5


tb6612_example.jpg
tb6612_example.jpg (435.65 KiB) Viewed 1112 times

adafruit_support_carter
 
Posts: 20347
Joined: Tue Nov 29, 2016 2:45 pm

Re: DC motor demo with Circuit Python

by DanGR on Wed Feb 10, 2021 6:42 pm

Thanks so much for that now I see what I was missing. Good point about the USB I will use a proper power supply for the motor tests.

Dan

DanGR
 
Posts: 110
Joined: Thu Oct 16, 2014 10:20 am

Please be positive and constructive with your questions and comments.