I2c Multiple Motor Drivers

I'm trying to figure out how to control two Grove i2c Motor Drivers.
I am using the i2c hub and have configured drivers to use different addresses.
But how do you program them?
The "Grove_I2C_Motor_Driver.h" exposes Motor.speed to control the speed om motor1 or 2.
To start the communication you would do Motor.begin(I2C_ADDRESS); but how do you start both i2c addresses and how to control the speed of the 4 motors seperately?

Hello yanlu

Welcome to the worldbest Arduino forum ever.

Follow the example code that comes with the library or
run some tutorials for the hardware selected.
If you are happy with the results of the tutorials you can merge these to your project.

Have a nice day and enjoy coding in C++.

I think you need an I2C multiplexer here.

It looks like that grove library creates the Motor object for you (dumb) so you can use the predefined one and also create your own.

#include <Grove_I2C_Motor_Driver.h>  // creates Motor object

I2CMotorDriver Motor2;  // create your second object

#define address1 = 0x0f;  // i2c address of Motor
#define address2 = 0x01;  // i2c address of Motor2

void setup() {
...
    Motor.begin(address1);
    Motor2.begin(address2);
...
}

Still seems that calling

Motor.speed(MOTOR1, -100)

will set speed to both MOTOR1 of Motor and Motor2

UPDATE
looks like if you define both Motors (not using the default one) it works

I2CMotorDriver Motor1;
I2CMotorDriver Motor2;

Motor1.begin(address1);
Motor2.begin(address2);

still testing

That does not make sense to me. You are basically doing the same thing - defining two instances of I2CMotorDriver. The first way is by using the one defined in the library plus an additional one. The second way is by defining two instances yourself (so you actually have 3 since the library still has one, but unused)

Are you sure you have different i2c addresses for each driver? What does the i2cscanner sketch tell you?

1 Like

Can you show the sketch ? Did you try a minimal sketch ? It is normal to have a number of test-sketches when making a project.

Could you use I2C addresses that differ with more than one dip switch ? For example 0x05 and 0x0A.
Then run a I2C Scanner sketch to be sure. Then try to move a single MOTOR1 of one board.

The class in the library is a normal class. Each object is completely independent of each other.
The ATmega8L on the board can only react to one I2C address.

But I agree with blh64, it does not make sense. If we can not solve this puzzle and if two new objects "Motor1" and "Motor2" work, then it is okay with me if you just ignore the already created object "Motor".

May I take a guess ? Then it is either the wiring of the motors or writing outside an array that overwrites the "Motor" object, or something is broken.

I think I've narrowed it down to it "forgetting" its hardware set i2c address on reset...
This means that I have to press "reset" on the driver itself after disconnecting/connecting power to arduino (which I did not do in-between program changes thus my variant worked...)
Now it is most likely a different question but I am not sure if something wrong in the wiring or it is meant to work this way or one must programaticaly reset it somehow.

The ATmega8L on the board reads the DIP-switches after power-on or after a reset, not during runtime.

Does that solve the problem ?
So my guesses were wrong, and you found the problem. Well done :smiley:
The Wiki does not tell to press reset each time the DIP switch is changed.

For some reason during a power-on they both assume default address and only after you physically press reset on the driver (with a faulty assumed address) it reads the correct address :upside_down_face:

It is a bug. Similar Issue that requires to press the reset button: https://github.com/Seeed-Studio/Grove_I2C_Motor_Driver_v1_3/issues/2

Maybe you have a older version of the firmware. Maybe they fixed it for the Raspberry Pi and introduced it for the Arduino Uno.

You need a programmer to put the new firmware into the ATmega8L.

It does not seem to be possible to read something via I2C from a board. They could have added something to allow the Arduino board to read the status and the version of the firmware, but they didn't.

There is always trouble on the I2C bus when one I2C device is powered and another I2C device not. Try to avoid that situation.

What are you going to do ?
The L298 is an old motor driver chip. Today we have mosfet drivers. Here are a few modern motor drivers:

Sorry that it took so long for me to read the Issues for the board.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.