Difference between revisions of "TB6612 DC Motor Driver Module"

From Wiki
Jump to: navigation, search
(Experimental Test)
Line 52: Line 52:
 
|GND
 
|GND
 
|}
 
|}
<br>
 
 
Connect the Arduino UNO to the module:<br>
 
Connect the Arduino UNO to the module:<br>
 
{|class="wikitable"
 
{|class="wikitable"
Line 74: Line 73:
 
|PWMB
 
|PWMB
 
|}
 
|}
<br>
 
 
Connect the motor to the module:<br>
 
Connect the motor to the module:<br>
 
{|class="wikitable"
 
{|class="wikitable"
Line 107: Line 105:
 
Since the motor will use large amount of power, you need to provide this module with an independent power supply so as to ensure the servo will have adequate supply.<br>
 
Since the motor will use large amount of power, you need to provide this module with an independent power supply so as to ensure the servo will have adequate supply.<br>
 
Connect the independent power supply to the module as shown below:<br>
 
Connect the independent power supply to the module as shown below:<br>
::::Independent Power Supply<---->TB6612 Motor Driver
+
{| class="wikitable"
::::::::::::VCC----VM
+
|-
::::::::::::GND----GND
+
|Independent Power Supply
 +
|TB6612 Motor Driver
 +
|-
 +
|VCC
 +
|VM
 +
|-
 +
|GND
 +
|GND
 +
|}
  
 
Connect the Raspberry pi to the module:
 
Connect the Raspberry pi to the module:
::::::::Raspberry Pi<---->TB6612 Motor Driver
+
{|class="wikitable"
::::::::::::+5V----VCC
+
|-
::::::::::::GND----GND
+
|Raspberry Pi
::::::::::::BCM17----MA
+
|TB6612 Motor Driver
::::::::::::BCM18----MB
+
|-
::::::::::::BCM27----PWMA
+
|GND
::::::::::::BCM22----PWMB
+
|GND
 +
|-
 +
|GPIO17
 +
|MA
 +
|-
 +
|GPIO27
 +
|PWMA
 +
|-
 +
|GPIO18
 +
|MB
 +
|-
 +
|GPIO22
 +
|PWMB
 +
|}
 +
Connect the motor to the module:<br>
 +
{|class="wikitable"
 +
|-
 +
|Motor
 +
|TB6612 Motor Driver
 +
|-
 +
|Black wire
 +
|A1
 +
|-
 +
|Red wire
 +
|A2
 +
|-
 +
|Red wire
 +
|B1
 +
|-
 +
|Red wire
 +
|B2
 +
|}
 
<br>
 
<br>
 
Pins of Raspberry Pi:<br>
 
Pins of Raspberry Pi:<br>
Line 127: Line 164:
  
 
Connect the servo to the module:
 
Connect the servo to the module:
:::::::::Motors<----->TB6612 Motor Driver
+
{|class="wikitable"
:::::::::Black wire of one motor-----A1
+
|-
:::::::::Red wire of one motor-----A2
+
|Motor
:::::::Black wire of the other motor-----B1
+
|TB6612 Motor Driver
:::::::Red wire of the other motor-----B2
+
|-
 +
|Black wire
 +
|A1
 +
|-
 +
|Red wire
 +
|A2
 +
|-
 +
|Red wire
 +
|B1
 +
|-
 +
|Red wire
 +
|B2
 +
|}
  
 
'''Step 2. Establish your project:'''  
 
'''Step 2. Establish your project:'''  

Revision as of 06:36, 6 January 2017

Introduction

Tb6612-1.jpg

The TB6612 Motor Driver Module uses TB6612FNG as the driver chip which has large current (1.2A continuous current) and two-channel output in a MOSFET-H bridge structure, and can drive two motors. The motor voltage and the working voltage of the module are separated - VCC for the module: 2.7 V to 5.5 V, and VM for the motor: 15V (Max). But the optimum working voltage of the motor is 2.5V-13.5V, and it cannot work when the voltage is lower than 4.5V.
It’s easy to control since you can control the forward and reverse rotation of the two servos by setting the values MA and MB as high or low level. The values PWMA and PWMB are to control the rotational speed of the motor which only occupy 4 I/O pins. The anti-reverse ports for motor connection and signal input can be plugged firmly and conveniently. With low-voltage detection and thermal shutdown inside the chip to protect the circuit, you don’t need to worry about ruining your project or damaging the main control board.

Features

>Uses the TB6612FNG motor driver chip with a maximum output current of 1.2A.
>Firm and convenient wiring, with anti-reverse port for both motor connection and signal input.
>Simple control: control two motors simultaneously - MA and MB for direction of the motor, and PWMA and PWMB for rotational speed.
>Dual power supply. VCC for the module: 2.7-5.5 V, VM for the motor: 15V (Max).
>Small and lightweight, with 3mm mounting holes, suitable for smart cars.
>Built-in thermal shutdown circuit and low-voltage detection.
>Size: 42 x 32 mm

Experimental Test

I Drive 2 motors with Arduino

Drive 2 motors to speed up and slow down.
Components
-1 x TB6612 Motor Driver
-1 x Arduino Uno
-1 x Motor
-1 x 18650 Battery Holder
-2 x 18650 Li-on Batteries
-Several jump wires

Step 1. Install the library
Open the Arduino software, and select Sketch -> Include Library ->Add .ZIP Library.

Tb6612-2.png

Choose the downloaded zip file and open it.SunFounder_TB6612.zip

Tb6612-3.png

Step 2. Open the Example
Open File -> Examples –> Sunfounder TB6612 Motor Driver -> motor, then upload this example

Tb6612-3-1.png

Step 3. Wiring
Connect the independent power supply to the module as shown below:

Independent Power Supply TB6612 Motor Driver
VCC VM
GND GND

Connect the Arduino UNO to the module:

Arduino UNO TB6612 Motor Driver
GND GND
5 MA
6 PWMA
9 MB
10 PWMB

Connect the motor to the module:

Motor TB6612 Motor Driver
Black wire A1
Red wire A2
Red wire B1
Red wire B2

Here is how the wiring looks like:

Tb6612-4.jpg]

After the example is uploaded, the motor will speed up to rotate and slow down in forward direction, then repeat in the reverse direction.
You can open the Serial Monitor to see the change of the output PWM value - various from small to larger, and then larger to small.
There is a positive correlation between the rotational speed of the motor and the PWM value.

Tb6612-5.png

II Control 2 motors with Raspberry pi

Step 1. Wiring Since the motor will use large amount of power, you need to provide this module with an independent power supply so as to ensure the servo will have adequate supply.
Connect the independent power supply to the module as shown below:

Independent Power Supply TB6612 Motor Driver
VCC VM
GND GND

Connect the Raspberry pi to the module:

Raspberry Pi TB6612 Motor Driver
GND GND
GPIO17 MA
GPIO27 PWMA
GPIO18 MB
GPIO22 PWMB

Connect the motor to the module:

Motor TB6612 Motor Driver
Black wire A1
Red wire A2
Red wire B1
Red wire B2


Pins of Raspberry Pi:

Pi3 gpio.png


Connect the servo to the module:

Motor TB6612 Motor Driver
Black wire A1
Red wire A2
Red wire B1
Red wire B2

Step 2. Establish your project: Log into the Raspberry Pi via ssh, and copy the TB6612 repository from Github:

pi@raspberrypi:~ $ git clone https://github.com/sunfounder/SunFounder_TB6612.git

After copying, you will have the package of the TB6612 in Python. Import it into the Python program, and you can use it then.
Here is a simple example:
1. Create a new file:

pi@raspberrypi:~ $ mkdir test_TB6612/

2. Copy the package to the file:

pi@raspberrypi:~ $ cd test_TB6612
pi@raspberrypi:~/test_TB6612 $ cp –r /home/pi/SunFounder_TB6612 ./

3. Create a code file

pi@raspberrypi:~/test_TB6612 $ touch test_motor.py

Here the file structure of your program is like this:
test_TB6612/
├── SunFounder_TB6612
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── LICENSE
│ ├── README.md
│ ├── show
│ ├── TB6612.py
│ └── TB6612.pyc

└── test_motor.py

With this structure, you can import the Python file successfully.
Next, let’s see how to control the motors.
Step 3. Code to Drive the motors

pi@raspberrypi:~/test_TB6612 $ nano test_motor.py

Type in the following code:

#!/usr/bin/env python
import time
from SunFounder_TB6612 import TB6612
import RPi.GPIO as GPIO

def main():
	import time

	print "********************************************"
	print "*                                          *"
	print "*           SunFounder TB6612              *"
	print "*                                          *"
	print "*          Connect MA to BCM17             *"
	print "*          Connect MB to BCM18             *"
	print "*         Connect PWMA to BCM27            *"
	print "*         Connect PWMB to BCM22            *"
	print "*                                          *"
	print "********************************************"
	GPIO.setmode(GPIO.BCM)
	GPIO.setup((27, 22), GPIO.OUT)
	a = GPIO.PWM(27, 60)
	b = GPIO.PWM(22, 60)
	a.start(0)
	b.start(0)

	def a_speed(value):
		a.ChangeDutyCycle(value)

	def b_speed(value):
		b.ChangeDutyCycle(value)

	motorA = TB6612.Motor(17)
	motorB = TB6612.Motor(18)
	motorA.debug = True
	motorB.debug = True
	motorA.pwm = a_speed
	motorB.pwm = b_speed

	delay = 0.05

	motorA.forward()
	for i in range(0, 101):
		motorA.speed = i
		time.sleep(delay)
	for i in range(100, -1, -1):
		motorA.speed = i
		time.sleep(delay)

	motorA.backward()
	for i in range(0, 101):
		motorA.speed = i
		time.sleep(delay)
	for i in range(100, -1, -1):
		motorA.speed = i
		time.sleep(delay)

	motorB.forward()
	for i in range(0, 101):
		motorB.speed = i
		time.sleep(delay)
	for i in range(100, -1, -1):
		motorB.speed = i
		time.sleep(delay)

	motorB.backward()
	for i in range(0, 101):
		motorB.speed = i
		time.sleep(delay)
	for i in range(100, -1, -1):
		motorB.speed = i
		time.sleep(delay)

def destroy():
	motorA.stop()
	motorB.stop()

if __name__ == '__main__':
	try:
		main()
	except KeyboardInterrupt:
		destroy()

Enter the command to run the example:

pi@raspberrypi:~/test_TB6612 $ python test_motor.py

We will still see the motor speeding up to rotate and slowing down in forward direction, then repeating in the reverse direction, same as shown previously.

Attachment

Datasheet
SunFounder_TB6612.zip