Basic Design

We'll be using CircuitPython for this project. Are you new to using CircuitPython? No worries, there is a full getting started guide here.

Adafruit suggests using the Mu editor to edit your code and have an interactive REPL in CircuitPython. You can learn about Mu and its installation in this tutorial.

We'll be making use of the CRICKIT robot add on board. New to CRICKIT, we have a guide to get introduce you to its capabilities. There are several other guides that deal with specific aspect of CRICKIT and a growing number of projects. Just search for CRICKIT on learn.adafruit.com.

Start by mounting your Circuit Playground Express on the CRICKIT, and making sure your CRICKIT has up-to-date firmware. See the CRICKIT guide for details.

The wiring is simple for this build: connect a couple motors to the CRICKIT. Do notice that they are wired in opposite polarity to each other. That let's us use a positive throttle value for both to get forward motion (and both negative for reverse).

The bot starts with a simple rectangular piece of cardboard for the chassis/base. It has to be wide enough to contain the battery pack and the two TT motors. If you use the yellow TT motors (as opposed to the blue ones), remember that they have a drive shaft on both sides which needs to be considered when deciding how much room is needed. Make it longer than you think you'll need for now; it can always be trimmed as desired. You'll want to leave about 4cm in front on the motors.

I decided to mount everything on the top of the chassis. This lets the chassis ride closer to the ground which makes attaching the tail and bumpers somewhat easier. However, whatever method you use to attach the motors will be holding up the weight of everything else (the batteries being the heaviest item) so use something strong.

Here is it with the 3xAA weatherproof battery holder.

The battery holder can be secured to the cardboard with some double sided tape, as can the motors. If you use this battery holder, slip the hex nuts in place before taping the holder cover in place. That way you can remove the cover to replace the batteries. 

Place tape on the bottom side of the two motors and finalize there positions. You'll probably want to position them with the wires on the inside.

Carefully position and secure the motors. Be sure to get them as straight as possible. You'll want them along the outside edges of the base anyway, so it can be used to align the sides of the motors.

Now use double-sided tape to secure the Circuit Playground Express to the top of the motors. If you have foam double-sided tape you can use it to accommodate the uneven underside of the Circuit Playground Express. To use thin tape, consider using a 3D printed CRICKIT mount. Not only does it provide a smooth bottom surface, but it adds a bit of width that helps secure it to the motors.

To keep the back end from dragging, you can simply add a binder clip to give it something smooth to glide on.

Code

The code for this build is simple. Set up the motors then run one fast and the other slow, repeat, alternating which runs faster.

There's one wrinkle in this. Because motors seldom behave identically, we need to compensate in order to maintain a roughly straight path. Having the bot tack back and forth rather than try to move in a straight line helps disguise the difference but if one motor runs consistently faster than the other the overall course will veer to one side.

One way to deal with this is to monitor the rotation of each motor and adjust the throttle to make their rotations match. We're not doing that in this build, and will use a far simpler, yet less dynamic, solution. That's what the set_left/right functions are for: they incorporate a factor into the throttles for each wheel. You can figure out the factors by uncommenting the lines below them to run the bot straight. Adjust the factors until a straight path is achieved. Then remove or comment out those lines.

Here's the code. Save it as code.py on your Circuit Playground Express.

import time
from adafruit_crickit import crickit

ss = crickit.seesaw

left_wheel = crickit.dc_motor_1
right_wheel = crickit.dc_motor_2


# These allow easy correction for motor speed variation.
# Factors are determined by observation and fiddling.
# Start with both having a factor of 1.0 (i.e. none) and
# adjust until the bot goes more or less straight
def set_right(speed):
    right_wheel.throttle = speed * 0.9

def set_left(speed):
    left_wheel.throttle = speed


# Uncomment this to find the above factors
# set_right(1.0)
# set_left(1.0)
# while True:
#     pass

while True:
    # tack left
    set_left(0.25)
    set_right(1.0)
    time.sleep(0.75)

    # tack right
    set_left(1.0)
    set_right(0.25)
    time.sleep(0.75)
This guide was first published on Jul 30, 2018. It was last updated on Jul 30, 2018. This page (Basic Design) was last updated on Jul 16, 2019.