Motor controller based on the TB6612 Dual H-Bridge capable of 1.2A with 3.2A peek with a maximum of 15V.
This is an I2C device to control two DC motors or any high power requirement. In addition it has and interface and commands for 2 IR slot switches to count pulses or to provide end stops.


Physical Layout


This has duplicate connections for easy daisy chaining of other I2C devices. Power for the logic is supplied through this connector and can be from 3.3V to 5V


Power is supplied to drive the motors via the bottom two pins of the motor connector. VM is the positive supply and can be from 4.5V to 15V


There are 2 input sensors marked S1 and S2, by default these are held high by a pull up resistor, this value can be read directly by an I2C command. The pin layout is designed for a standard 3D type printer end stop, for example:

However a standard micro-switch can be used if connected from S1 or S2 to Ground.

Pulse Counting: It is possible to use the slotted IR switch for pulse counting and there is a command that will stop the motor after a specified count. However, there are some restrictions to this and that is the IR switch must swing below 500mV in order to register a count. In practice some IR detectors of the type above did not get to below 900mV (0.9V). This coud be due to the detector itself or that the optical disk was not black enough.


The example is a written in python, put the four files:


Into a directory and run from the terminal "python testi2c.py"

This will run motor B for 50 pulses, of course this assumes that the endslot is set up to detect pulses, if not simply edit the i2ctest.py and select function t1() instead of t2()


This uses exactly the same library as Python, as there is no python version 2 only three files need to be on the device.


*** Pull up resistors will be required if used with the UNO or Nano ***

Please not that this is intended as a staring point, it is not intended as a full blown library. I has also only been tested on the UNO

(see example for constructor, default i2c address is 0x29)

Applies to all Motors

        void en(uint8_t on); // global enable 1=enable 0 = disable
        uint8_t status(void); // returns status
        void mreset(void); // resets motor

Applies to specific motor = 10 = A, 20 = B

        void power(uint8_t motor, uint8_t value); // sets power to motor 0-255
        void direction(uint8_t motor, uint8_t value); // set direction 0,3 = off 1=fwd, 2=bwk
        void pow_dir(uint8_t motor, uint8_t power, uint8_t dir); // set both power and direction
        uint8_t get_power(uint8_t motor); // gets current set power
        uint8_t slot(uint8_t motor); // gets end stop value
        void clr_count(uint8_t motor); // clears end stop (slot) counter
        uint16_t get_count(uint8_t motor); // gets end stop counter
        void endstop(uint8_t motor, uint8_t dir, uint8_t hl); // run until end stop
        void steps(uint8_t motor, uint16_t value, uint8_t dir); // run until end stop count reached


        void EEreset(); // reset default eeprom values
        void change_i2c(uint8_t new_address); // changes i2c address
        void EEwrite(uint8_t adr, uint8_t value); // write to eeprom
        uint8_t EEread(uint8_t adr); // read from eeprom
        uint16_t ID(); // return device id
        void Version(uint8_t *b); // return firmware version 3 bytes
        void reset(void); // global reset