Skip to content

Instantly share code, notes, and snippets.

@rahulbot
Created February 20, 2024 19:26
Show Gist options
  • Save rahulbot/fdd69dbb568aea4babef2f2c276778b1 to your computer and use it in GitHub Desktop.
Save rahulbot/fdd69dbb568aea4babef2f2c276778b1 to your computer and use it in GitHub Desktop.
Simple example of using motor driver QWIIC board from SparkFun
#include <Arduino.h>
#include <stdint.h>
#include "SCMD.h"
#include "SCMD_config.h" //Contains #defines for common SCMD register names and values
#include "Wire.h"
SCMD myMotorDriver; //This creates the main object of one motor driver and connected peripherals.
void setup()
{
Serial.begin(9600);
Serial.println("Starting sketch.");
//***** Configure the Motor Driver's Settings *****//
// .commInter face is I2C_MODE
myMotorDriver.settings.commInterface = I2C_MODE;
// set address if I2C configuration selected with the config jumpers
myMotorDriver.settings.I2CAddress = 0x5D; //config pattern is "1000" (default) on board for address 0x5D
// set chip select if SPI selected with the config jumpers
myMotorDriver.settings.chipSelectPin = 10;
//*****initialize the driver get wait for idle*****//
while ( myMotorDriver.begin() != 0xA9 ) //Wait until a valid ID word is returned
{
Serial.println( "ID mismatch, trying again" );
delay(500);
}
Serial.println( "ID matches 0xA9" );
// Check to make sure the driver is done looking for peripherals before beginning
Serial.print("Waiting for enumeration...");
while ( myMotorDriver.ready() == false );
Serial.println("Done.");
Serial.println();
while ( myMotorDriver.busy() );
myMotorDriver.enable(); //Enables the output driver hardware
}
#define MOTOR_NUM 1
void loop()
{
//pass setDrive() a motor number, direction as 0(call 0 forward) or 1, and level from 0 to 255
myMotorDriver.setDrive( MOTOR_NUM, 0, 255);
delay(2000);
myMotorDriver.setDrive( MOTOR_NUM, 0, 0); //Stop motor
delay(2000);
myMotorDriver.setDrive( MOTOR_NUM, 1, 255);
delay(2000);
myMotorDriver.setDrive( MOTOR_NUM, 0, 0); //Stop motor
delay(2000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment