Arduino Drives

The Drives port provides the ability to drive higher current devices.

 

The functionality is identical on all versions of Crickit shown at left.

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!
  • PWM values can be anywhere between 0 (0% duty cycle or always off) and 65535 (100% duty cycle or always on). A value of 32768 would be 50% duty cycle, or on for half of the period and then off for half the period.

This example will show turning the drive output fully on and off once a second. The macros CRICKIT_DUTY_CYCLE_OFF and CRICKIT_DUTY_CYCLE_MAX correspond to 0 and 65535 respectively and are used for readability:

#include "Adafruit_Crickit.h"

Adafruit_Crickit crickit;

void setup() {
  Serial.begin(115200);
  Serial.println("1 Drive demo!");
  
  if(!crickit.begin()){
    Serial.println("ERROR!");
    while(1);
  }
  else Serial.println("Crickit started");

  //our default frequency is 1khz
  crickit.setPWMFreq(CRICKIT_DRIVE1, 1000);
}

void loop() {
  //turn all the way on
  crickit.analogWrite(CRICKIT_DRIVE1, CRICKIT_DUTY_CYCLE_OFF);
  delay(500);
  
  //turn all the way off
  crickit.analogWrite(CRICKIT_DRIVE1, CRICKIT_DUTY_CYCLE_MAX);
  delay(500);
}

More Drivers!

OK that was fun but you want MORE drives right? You can control up to four! The four drive outputs are on the seesaw pins 13 (CRICKIT_DRIVE1), 12 (CRICKIT_DRIVE2), 43 (CRICKIT_DRIVE3), 42 (CRICKIT_DRIVE4)

#include "Adafruit_Crickit.h"

Adafruit_Crickit crickit;

#define NUM_DRIVES 4
int drives[] = {CRICKIT_DRIVE1, CRICKIT_DRIVE2, CRICKIT_DRIVE3, CRICKIT_DRIVE4};

void setup() {
  Serial.begin(115200);
  Serial.println("4 Drive demo!");
  
  if(!crickit.begin()){
    Serial.println("ERROR!");
    while(1);
  }
  else Serial.println("Crickit started");

  //our default frequency is 1khz
  for(int i=0; i<NUM_DRIVES; i++)
    crickit.setPWMFreq(drives[i], 1000);
}

void loop() {
  for(int i=0; i<NUM_DRIVES; i++){
    //turn all the way on
    crickit.analogWrite(drives[i], CRICKIT_DUTY_CYCLE_OFF);
    delay(100);
    
    //turn all the way off
    crickit.analogWrite(drives[i], CRICKIT_DUTY_CYCLE_MAX);
    delay(100);
  }
}

This example is similar to the 1 drive example, but instead of using just 1 PWM driver, we'll make an array called drives that contains the pin numbers of 4 PWM drivers. Then we can assign them using crickit.analogWrite(drives[0], CRICKIT_DUTY_CYCLE_MAX); 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 drivers at once!

This guide was first published on May 16, 2018. It was last updated on May 16, 2018. This page (Arduino Drives) was last updated on Dec 12, 2018.