The Crickit with Circuit Playground Express is shown at left.

 

All the red wires connect to the Drives 5V terminal and the other wire connected to individual Drive terminals.

Using Drives with the Feather-based Crickit is shown at left.

 

Note: For CircuitPython, you need to use a CircuitPython-compatible Feather board.

Crickit HAT for Raspberry Pi can also drive four devices via the Drive ports.

Test Drive

Lets start by controlling a drive output. You'll need to plug something into the 5V and DRIVE1 terminal blocks. I'm just using a simple LED with resistor but anything that can be powered by 5V will work.

  • Note that the drive outputs cannot have 5V output so you must connect the positive pin of whatever you're driving to 5V. Don't try connecting the positive pin to the drive, and the negative pin to GND, it wont work!
  • Drive outputs are PWM-able!

This example will show turning the drive output fully on and off once a second:

import time
from adafruit_crickit import crickit

print("1 Drive demo!")

crickit.drive_1.frequency = 1000

while True:
    crickit.drive_1.fraction = 1.0  # all the way on
    time.sleep(0.5)
    crickit.drive_1.fraction = 0.0  # all the way off
    time.sleep(0.5)
    crickit.drive_1.fraction = 0.5  # half on/off
    time.sleep(0.5)
    # and repeat!

We start by importing the libraries that we need to have time delays ( import time ) and then the main crickit python library that will make it super easy to talk to the motors and sensors on crickit (from adafruit_crickit import crickit)

The crickit object represents the drive outputs available for control. The drives are available on the sub-objects named drive_1, drive_2, drive_3, drive_4

Note that for the Feather Crickit, these are feather_drive_1, feather_drive_2, feather_drive_3, and feather_drive_4.

Set PWM Frequency

Drive outputs are all PWM outputs too, so not only can they turn fully on and off, but you can also set it half-way on. In general, the default frequency for PWM outputs on seesaw is 1000 Hz, so set the frequency to 1 KHz with crickit.drive_1.frequency = 1000. Even if you aren't planning to use the PWM output, please set the frequency!

Note that all the Drive outputs share the same timer so if you set the frequency for one, it will be the same for all of them.

Control Drive Output

Now that we have a drive pwm object, we can simply assign the PWM duty cycle with the fraction property!

  • crickit.drive_1.fraction = 0.0 turns the output completely off (no drive to ground, no current draw).
  • crickit.drive_1.fraction = 1.0 turns the output completely on (fully drive to ground)
  • And, not surprisingly crickit.drive_1.fraction = 0.5 sets it to 1/2 on and 1/2 off at the PWM frequency set above.

More Drivers!

OK that was fun but you want MORE drives right? You can control up to four!

import time
from adafruit_crickit import crickit

print("4 Drive demo!")

drives = (crickit.drive_1, crickit.drive_2, crickit.drive_3, crickit.drive_4)

for drive in drives:
    drive.frequency = 1000

while True:
    for drive in drives:
        print("Drive #", drives.index(drive)+1)
        drive.fraction = 1.0  # all the way on
        time.sleep(0.25)
        drive.fraction = 0.0  # all the way off
        time.sleep(0.25)
        # and repeat!

This example is similar to the 1 drive example, but instead of accessing the crickit.drive_1 object directly, we'll make a list called drives that contains 4 drive objects with

drives = (crickit.drive_1, crickit.drive_2, crickit.drive_3, crickit.drive_4)

Then we can access the individual using drives[0].fraction = 0.5 or iterate through them as we do in the loop. You don't have to do it this way, but its very compact and doesn't take a lot of code lines to create all 4 drives at once!

This guide was first published on Dec 14, 2018. It was last updated on Mar 25, 2024.

This page (CircuitPython Drives) was last updated on Mar 08, 2024.

Text editor powered by tinymce.