How Do You Define Duplicate Qwiic Modules?

Hi

I am working on a projects which involves running 8 DC motors. I have 4 Qwiic motor drivers which I can daisy chain up to my ResBoard Artemis, but can’t figure out how I define each of these motor drivers in my code.

Every Qwiic related example I can find, only uses a single copy of each module (one motor driver, one joystick module etc).

When I call out

SCMD myMotorDriver;

How do I know which one it is talking to?

Thanks

Max

Hookup guide has some info that might. E helpful.

https://learn.sparkfun.com/tutorials/se … okup-guide

So the Hookup guide for SCMD is helpful, but I still haven’t got it fully working yet.

I have added in some of the code that the hookup guide has in it’s examples but whenever myMotorDriver.setDrive(0,1,255) runs, it will run the first motor on both controllers simultaneously. Same goes for myMotorDriver.setDrive(1,1,255). When I use a motor number greater than 1, nothing runs

//This example drives a robot in left and right arcs, driving in an overall wiggly course.

// It demonstrates the variable control abilities. When used with a RedBot chassis,

// each turn is about 90 degrees per drive.

//

// Pin 8 can be grounded to disable motor movement, for debugging.

#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()

{

pinMode(8, INPUT_PULLUP); //Use to halt motor movement (ground)

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;

delay(2500);

// initialize the driver and enable the motor outputs

uint8_t tempReturnValue = myMotorDriver.begin();

while ( tempReturnValue != 0xA9 )

{

Serial.print( “ID mismatch, read as 0x” );

Serial.println( tempReturnValue, HEX );

delay(500);

tempReturnValue = myMotorDriver.begin();

}

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();

// Report number of peripherals found

uint8_t tempAddr = myMotorDriver.readRegister(SCMD_SLV_TOP_ADDR);

if ( tempAddr >= START_SLAVE_ADDR )

{

Serial.print("Detected ");

Serial.print(tempAddr - START_SLAVE_ADDR + 1); //Top address minus bottom address + 1 = number of peripherals

Serial.println(" peripherals.");

}

else

{

Serial.println(“No peripherals detected”);

}

while ( myMotorDriver.busy() );

myMotorDriver.enable(); //Enables the output driver hardware

}

void loop()

{

Serial.println(“Now stepping through the motors.”);

for (int i = 0; i < 6; i++)

{

Serial.print("Driving motor ");

Serial.println(i);

myMotorDriver.setDrive( i, 1, 255); //Drive motor i forward at full speed

delay(1000);

myMotorDriver.setDrive( i, 0, 255); //Drive motor i backward at full speed

delay(1000);

myMotorDriver.setDrive( i, 1, 0);

}

}

I suspect you need to follow the [TwoMasterMotorTest example where you have two variables of type SCMD and each is assigned a different I2C address. You’ll also have to change the address of one of the QWIIC modules (see Config Bits Table in hookup guide).](SparkFun_Serial_Controlled_Motor_Driver_Arduino_Library/examples/TwoMasterMotorTest/TwoMasterMotorTest.ino at master · sparkfun/SparkFun_Serial_Controlled_Motor_Driver_Arduino_Library · GitHub)