Use raspberry pi connect two or multi grove I2C Motor Driver(1.3b)

Hi,

I have two grove I2C motor driver connect by grove base hat on raspberry pi 3b:

  1. Raspberry pi 3b x 1
  2. Grove base hat x 1
  3. I2C motor driver x 2
  4. DC motor x 3

Case1:

When use a I2C motor driver connect 2 DC motors(default address 0x0f), it can control DC motor speed and direction.

Case2:

When use two I2C motor drivers connect 3 DC motor(one for default, other set to 0x0a), it shows “remote I/O error”

Case3:

When use a I2C motor driver connect 1 DC motor(set address to 0x0a), it shows “remote I/O error” too.

Case4:

when I2C motor driver connect to Grove base hat, the command
i2cdetect -y 1 is not working, even use default address(0x0f)

below is my sample code in python3:

import time
from grove.grove_i2c_motor_driver import MotorDriver
import datetime

def addSecs(tm, secs):
    fulldate = datetime.datetime(100, 1, 1, tm.hour, tm.minute, tm.second)
    fulldate = fulldate + datetime.timedelta(seconds=secs)
    return fulldate.time()

addml = 5  # add 5 ml
addinterval = addml*30

motor1 = MotorDriver(address=0x0f)
motor2 = MotorDriver(address=0x0a)

try:
    print("time Begin = {}".format(time.strftime("%H:%M:%S")))
    t1 = datetime.datetime.now().time()
    t2 = addSecs(t1, addinterval)
    while datetime.datetime.now().time() < t2:
        motor1.set_dir(True,True)
        motor2.set_dir(True,False)
        motor1.set_speed(20,20)
        motor2.set_speed(100,0)
        time.sleep(1)
    print("time End = {}".format(time.strftime("%H:%M:%S")))
except KeyboardInterrupt:
    print("time Interrupt = {}".format(time.strftime("%H:%M:%S")))

error message output:

time Begin = 19:57:52
Traceback (most recent call last):
File “motor.py”, line 31, in
motor2.set_dir(True,False)
File “/usr/local/lib/python3.7/dist-packages/grove/grove_i2c_motor_driver.py”, line 88, in set_dir
self.bus.write_i2c_block_data(self.I2CAddr, self.__DirectionSet, [dir, 0])
File “/usr/local/lib/python3.7/dist-packages/smbus2/smbus2.py”, line 622, in write_i2c_block_data
ioctl(self.fd, I2C_SMBUS, msg)
OSError: [Errno 121] Remote I/O error
Exception ignored in: <function MotorDriver.del at 0x76733b70>
Traceback (most recent call last):
File “/usr/local/lib/python3.7/dist-packages/grove/grove_i2c_motor_driver.py”, line 61, in del
File “/usr/local/lib/python3.7/dist-packages/grove/grove_i2c_motor_driver.py”, line 80, in set_speed
File “/usr/local/lib/python3.7/dist-packages/smbus2/smbus2.py”, line 622, in write_i2c_block_data
OSError: [Errno 121] Remote I/O error

Can someone help me find out the problem?

Thank you.

I think maybe I2c is not turned on by default. Could you check it ? @stanleykao72

Hi Baozhu,

Thanks for the reply, I2C is turned ok when I tested in Case1.

When executed command
i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: – 04 – -- – -- – -- – -- – -- 0f
10: – -- – -- – -- – -- – -- – -- – -- – --
20: – -- – -- – -- – -- – -- – -- – -- – --
30: – -- – -- – -- – -- – -- – -- – -- – --
40: – -- – -- – -- – -- – -- – -- – -- – --
50: – -- – -- – -- – -- – -- – -- – -- – --
60: – -- – -- – -- – -- – -- – -- – -- – --
70: – -- – -- – -- – --

but executed second once, it shows below:
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: – -- – -- – -- – -- – -- – -- –
10: – -- – -- – -- – -- – -- – -- – -- – --
20: – -- – -- – -- – -- – -- – -- – -- – --
30: – -- – -- – -- – -- – -- – -- – -- – --
40: – -- – -- – -- – -- – -- – -- – -- – --
50: – -- – -- – -- – -- – -- – -- – -- – --
60: – -- – -- – -- – -- – -- – -- – -- – --
70: – -- – -- – -- – --

Thanks,
Stanley

It seems that the i2c device has disappeared. Is the power supply working? @stanleykao72

Hi Baozhu,

The power supply is working(see attachment), but when execute “i2cdetect -y 1” the address of “i2c motor driver” will be gone, must press reset button can get address again.

My question is i2c motor driver only working in default adores(0x0f) can’t set to 0x0a?
because I have two motor driver boards.

Thanks!
Stanley

Hi @stanleykao72, Yes you can adjust the I2C address by using the dial switch in the motor driver.

You can find more information at https://wiki.seeedstudio.com/Grove-I2C_Motor_Driver_V1.3/

Hi Salman,

Yes, I had adjusted digital switch and software address in python, but it’s not working.

Thanks!
Stanley

Hi @stanleykao72, Are you getting any error after changing the address? can you please elaborate the ‘it’s not working’?

Hi Salman,

The error message output:

time Begin = 19:57:52
Traceback (most recent call last):
File “motor.py”, line 31, in
motor2.set_dir(True,False)
File “/usr/local/lib/python3.7/dist-packages/grove/grove_i2c_motor_driver.py”, line 88, in set_dir
self.bus.write_i2c_block_data(self.I2CAddr, self.__DirectionSet, [dir, 0])
File “/usr/local/lib/python3.7/dist-packages/smbus2/smbus2.py”, line 622, in write_i2c_block_data
ioctl(self.fd, I2C_SMBUS, msg)
OSError: [Errno 121] Remote I/O error
Exception ignored in: <function MotorDriver. del at 0x76733b70>
Traceback (most recent call last):
File “/usr/local/lib/python3.7/dist-packages/grove/grove_i2c_motor_driver.py”, line 61, in del
File “/usr/local/lib/python3.7/dist-packages/grove/grove_i2c_motor_driver.py”, line 80, in set_speed
File “/usr/local/lib/python3.7/dist-packages/smbus2/smbus2.py”, line 622, in write_i2c_block_data
OSError: [Errno 121] Remote I/O error
[/quote]

Thanks,
Stanley

Hi Stanley,
I’ve tried doing this as well. There is some issue between the hardware or the firmware between the boards. Others have had this issue including me, and I’ve spent some nights trying to figure it out. My assumption has to do with the timings in i2c between boards. Anyhow, I resorted to using an Arduino as a passthrough. It’s not a great fix but works well enough.
Best,
Thavens