Today, I propose to discover the Shield Motor I2C for Wemos D1 Mini. This small shield built around the Toshiba TB6612FNG driver allows to control 2 DC motors. The Shield is capable of independently controlling the speed and direction of each motor (A, B). The maximum permissible power is 1.2A per motor. It supports a power peak at 3.2A.
By default, the shield is located at address 0x30 on the I2C bus. The board comes with a library in C ++ as well as 4 examples of Arduino code. The firmware of the STM32F030 to control the shield via the I2C bus is not installed (or properly installed) on some clones. It is best to buy the Shield Motor directly on the official Wemos store on Aliexpress. In addition the board does not cost more.
Unpacking the Shield Motor I2C TB6612FNG for Wemos D1 mini
The Shield Motor I2C comes in an anti-static pouch with a simple connector set. It is therefore planned to close the Shields stack. This is quite logical considering the wiring to be made.
Communication with the shield is via the I2C bus. By default, pins D1 and D2 are used. The official page of the shield can be found here.
The Shield is built around Toshiba’s TB6612FNG circuit. The complete technical data sheet can be found here.
- I2C interface (see next paragraph to change the default address 0x30)
- Maximum supply voltage (VM pin): 15Vdc max
- Output current (Iout Pin): 1.2A (average) – 3.2A (in peak)
- Standby function for energy saving
- CW / CCW / short brake / stop motor control modes
- VM: Power supply + (max 15Vdc)
- GND: negative motor terminal –
- A1 A2: Engine A
- B1 B2: Motor B
- S: standby control
- Standby control
- I2C mode: Controls the standby function of the TB6612FNG circuit using the I2C protocol
- IO mode: Controls the standby function of the TB6612FNG circuit with the “S”
- Reset modes
- Welded: reset with the d1 mini (reset at power up or by pressing the Reset button on the wemos d1 mini). This is the default mode.
- Opened: reset by the pin marked “DTR”
How to change the I2C address of the shield
By default, the Shield is at the address 0x30 on the I2C bus. On the back of the shield there are 2 jumper AD0 and AD1. By making a bridge by welding the two terminals of each jumper, one can change the address of the shield. The ‘-‘ means that the pot is open. The ‘x’ means that the bridge is closed by a weld.
Welding of connectors
There are 4 connectors to be welded on the Shield Motor. One on each side that allows to stack the shield on the Wemos D1 Mini as usual. The third (USB side) is used to power the motor on an external battery (the Wemos is not powerful enough to power engines) and to drive for both engines.
The fourth connector opposite the motor connector is not documented. It seems that this is simply a serial port. Hackers can use it to reprogram the STM32F030 microcontroller used for I2C communication (full tutorial).
The DTR pin allows you to reset the TB6612FNG.
The jumper RST on the back of the board will have to be de-soldered to activate this mode. To weld the motor connector, I advise you to insert it on a breadboard to keep the shield vertical during welding.
Upload ESP8266 code
Wemos has developed a C++ library for Arduino. The source code as well as four basic examples are available on GitHub here:
To call the library in your Arduino programs, it will suffice to declare it at the beginning of the program
The Motor method is used to initialize an object for each motor A and B. The Motor class takes as parameter:
- The I2C address of the board. Default 0x30
- Use the _MOTOR_A or _MOTOR_B key to indicate which engine the object is associated with
- The PWM frequency. By default, it is 1000Hz.
- Standby mode. By default, it is managed by the shield. If you need to control it from the Wemos, specify the pin used. Do not forget to weld the STBY bridge to the back of the board.
This gives, for example, for the motor A
Motor M1(0x30,_MOTOR_A, 1000);
To control the engine, we have the setmotor method which takes 1 or 2 parameters. The first parameter is the order to be executed. The second is the setpoint of the parameter. The commands offered by Toshiba’s integrated circuit TB6612FNG include the following:
- An early explanation of the interest of the function here
- which means counter clockwise or counterclockwise rotation. A power level between 0% and 100% is set as a parameter, which also corresponds to the maximum speed of the motor
- which means counter wise or clockwise rotation
- no need for explanation
- allows you to pause the motor.
You understand, there is nothing very complicated in the use of this library. As usual, we get a very compact assembly and very easy to integrate in our projects. We will see in an upcoming tutorial how to use it to recycle an old remote-controlled car. This shield, which costs less than €3 (excluding postage), will be easier to use than an L293D H-bridge.
- Get Started with HC-SR04, measure distance by ultrasound. Arduino code example
- ESP32, GPIO pins and associated functions. I/O, PWM, RTC, I2C, SPI, ADC, DAC
- ESP32-CAM pinout and equipments. ESP-EYE, AI Thinker, TTGO T-Camera, M5Stack Timer Camera …
- ESP32-CAM. Which model to choose? ESP-EYE, AI Thinker, TTGO T-Camera, M5Stack Timer Camera …
- M5Stack Atomic GPS. ESP32 TinyGPS++ tracker, GPX export on SD card, visualization on Google Maps or VSCode