A port of Grove Motor Driver TB6612FNG library for python and RaspberryPI

Recently got to use Grove - I2C Motor Driver (TB6612FNG) with my Raspberry Pi.
For this, I wrote and released my own port of Arduino library for this module to Raspberry Pi and python3.

This library also includes easing functions to control your motors with smooth transitions.Easing functions are available for dc motors only.

You can check it out here: https://pypi.org/project/raspberry-i2c-tb6612fng/
And the Wiki page is here: https://github.com/MarkusBansky/raspberry-i2c-tb6612fng/wiki

Please feel free to use and suggest any useful things, thanks.

Thank you very much. Can we write it into our Wiki product? @MarkusBansky

Yes, sure!
I would also improve the project’s Wiki today.

Hi @MarkusBansky
We have tested the library you wrote. But we meet some problem, Using your library we can drive the motor to rotate. But sometimes when typing python3 test.py to run, it will report the error in the picture below.error
I can find I2C address when using
sudo i2cdetect -y 1.

Hi,
Unfortunately I am not able to reproduce this error, this might be because of the i2c bus being busy.
Could you tell me more info about the environment you are running this on?

  1. which Raspberry Pi
  2. python version
  3. pip version
  4. raspberry-i2c-tb6612fng version
  5. your test.py code
  6. listing of i2cdetect -y 1

Thank you

@jiachenglu I suspect, though, that this can be poor wiring.

This error happens if you are trying to contact a not used address or the command is not what the slaves expect.

I would assume that this is hardware related and there might be a problem with the I2C bus connection. Because this does not happen every time.

Hi @MarkusBansky
Thank you for your reply.
1.Raspberry pi 4B
2.Python 3.7
3.pip(18.1-5+rpt1).
4. The raspberry-i2c-tb6612fng I was download in here.
5.

# import default libraries that are used in this example
import time

# import the library
from raspberry_i2c_tb6612fng import MotorDriverTB6612FNG, TB6612FNGMotors

# create an instance of the driver, connected to i2c
driver = MotorDriverTB6612FNG()

# drive both motors forward
driver.dc_motor_run(TB6612FNGMotors.MOTOR_CHA, 200)
driver.dc_motor_run(TB6612FNGMotors.MOTOR_CHB, 200)

# pause for a second
time.sleep(1)

# stop the motors
driver.dc_motor_break(TB6612FNGMotors.MOTOR_CHA)
driver.dc_motor_break(TB6612FNGMotors.MOTOR_CHB)

I2Cdetect

Hi, Unfortunately I don’t have Pi4 to test this on, from searching similar problems, this might be related to the bus connections, not the code itself, as then it won’t work at all.
I would suggest checking all connections or trying different hardware.

As soon as I will get Pi4 I would be able to test this.