Driving DC Motors with Circuit/MicroPython - Adafruit Crickit & Circuit Playground Express

in #programming8 years ago (edited)

cpx-motors.jpg

Driving LED lights is all well and good, and servos are great, but when most people think of robots they think of wheels and DC motors.

Let's make a thing that moves!

Full code

We begin much the same as the previous examples, in that we need I2C, we need the SeeSaw library to speak I2C to the Board, and we need PWM and Timing.

This time we add the Adafruit Motor module, which makes motor driving easy.

The motor pins are 18, 19, 22 and 23. Attach your first motor to 18 and 19, and second to 22 and 23. Doesn't matter which wire goes in where, if it runs backwards just replace the wires or reverse in code.

motor_a = motor.DCMotor(PWMOut(seesaw, 22), PWMOut(seesaw, 23))

Yeah, you could speak to the pins, making one pin low and the other high to drive forwards, or vice versa to reverse, but the motor library has a throttle property for speed and direction.

Full forwards is 1, reverse is -1:

motor_a.throttle = 1

motor_a.throttle = -1

and setting to 0.5 (plus or minus) makes it half speed, with zero being stop.

Powering the Crickit

crickit-power.jpg

The Crickit is powered 5v via 2.1mm barrel connector. I got a USB to barrel cable for USB power, but also have a screw terminal barrel connector so I can use a 4 x NiMH batteries battery case.


makerhacks.png

Sort:  
Congratulations This post has been upvoted by SteemMakers. We are a community-based project that aims to support makers and DIYers on the blockchain in every way possible.

Join our Discord Channel to connect with us and nominate your own or somebody else's posts in our review channel.

Help us to reward you for making it ! Join our voting trail or delegate steem power to the community account.

Your post is also presented on the community website www.steemmakers.com where you can find other selected content.

If you like our work, please consider upvoting this comment to support the growth of our community. Thank you.

Hi @makerhacks!

Your post was upvoted by utopian.io in cooperation with steemmakers - supporting knowledge, innovation and technological advancement on the Steem Blockchain.

Contribute to Open Source with utopian.io

Learn how to contribute on our website and join the new open source economy.

Want to chat? Join the Utopian Community on Discord https://discord.gg/h52nFrV

Coin Marketplace

STEEM 0.05
TRX 0.29
JST 0.043
BTC 67874.24
ETH 1971.99
USDT 1.00
SBD 0.38