How to connect the TB6612FNG SKU DRI0044 Motor Driver to Raspberry Pi

You can find a link to our video bellow or simply just follow this post.

In this video we will go over the DRI0044 motor driver with TB6612FNG chipset to control 2 DC motors with power supply of up to 12V using an external power supply from DFROBOT.

This chipset is only 2cm x 2cm and makes it perfect for small robots. Given that there is no documentation on how to connect it to a Raspberry Pi, we decided to put it out there for everyone to learn.

What you need:

  • Raspberry Pi ( I’m using the Raspberry Pi 4 Model B)
  • The DRI0044 driver
  • Breadboard
  • 2 x DC motors
  • 4 x male to male jumper cables for the motors (2 each)
  • 3 x male to male jumper cables for ground pins
  • 6 x email to male jumper cables to connect to pins on raspberry pi
  • Power supply (I’m using a 9v battery)
  • 2 cables to connect the power supply
Diagram for the connections

Keep in mind that all the ground pins (GND) have to be connected to gather so on the breadboard use a male to male jumper cable to connect the ground from battery to the ground that goes to Raspberry Pi. (Leave the + as is). Use the diagram above to connect each pin to the corresponding one on the Raspberry Pi.

Use the code on our GitHub page to program the Raspberry Pi and make sure to install the required libraries on your raspberry by going to the terminal and using the pip instal … command.
Remember that the PWM is for speed and and you can change the direction of the motors by changing the DIR to HIGH for forward and LOW for backwards.

Lastly, please leave any questions or feedback that you may have below and we will make sure to answer them.

Engineering Journal – Bangkok 2022

Team Pashmam

Team Pashmam was established in March of 2019 in Melbourne, Australia and consists of two members, George (Georgios) and Koosha (Reza). Each member plays a different role in the team. George handles the engineering and hardware while Koosha programs and operates the software of the robot.

Past experiences:

  • Team Pashmam first competed in the 2019 secondary rescue regional (Melbourne) where they were able to come second.
  • After that Team Pashmam was able to use their experiences to come first in the state (Victorian) competition. (Rescue secondary open).
  • Finally for the last in person experience team Pashman was able to achieve first place in the nationals (Australian) competition in 2019.
  • Team Pashmam attempted to compete in 2021 virtual internationals.
  • Rescue open nationals (Australia) 2021 virtual.

Apart from experiences as a team both George and Koosha have their own experiences in the past as well such as competing in the WRO events at a young age.

Members meet regularly at least once a week to work on the robot however this could be as often as daily during the school holidays. Team members communicate through the shared documents such as google docs, GitHub and various forms of social media outside of their routine meetings in order to share the progress and the engineering journal. 

Engineering journal

January

20/1/2022

  • Meeting: 
  • Meet up to discuss the competition and requirements.
  • Assigning tasks to each team member such as designing, gathering information and requirements.
  • George has been assigned with gathering requirements
  • Koosha has been assigned with designing a sketch

27/1/2022

February

3/2/2022

  • George: 
  • Creating G-Suit, for Team Pashmam and starting a YouTube channel to share our journey with others as well as being able to upload files to the cloud for each other to access.
  • Koosha:
  • Starting to design a prototype with fusion 360 for the robot based on requirements discussed during the last meeting. Available at our YouTube page link 2: Pashmam Design v1.0

7/2/2022

  • Koosha:
  • Finalised the prototype.
  • George:
  • planning for assembling the robot available in table 1:
FebMarAprMayJunJul
list all the requirements.
Estimating the cost.
Ordering the tools
Assembling the base
Attaching the IR sensor.
getting the line follower started.
Attaching the distance sensor 
coding the obstacle avoidance 
attaching the colour sensor.
finalizing the green turn 
coding the husky lens to detect rescue kit
Ordering PCB
finishing evacuation zone
tests
travel to thailand.

29/2/2022

March

14/3/2022

18/3/2022

  • Meeting:
  • Problem: We are not able to connect IR sensor to raspberry pi as it is an Analog sensor 
  • Solution: to order ADC Pi which allows for up to 8 analog input for raspberry pi. Available at link 7:
  • Link 8 shows it on raspberry pi

20/3/2022

25/3/2022

  • Meeting:
  • assembling the motors and the printed parts pictures are available at link 11 and 12
  • Problem: we have to run everything from the raspberry pi and power the raspberry using a cable. 
  • We have to find solutions for a battery
  • George:
  • Consideration:
    • After measuring all components needed voltage is 5V 
    • 1-cell batteries are 3.7V so we need a 2-cell battery and a 5V step down regulator
    • As much current as possible for longer use
    • LiPo batteries benefit us in terms of consumption as seen in graph 1:

from link 13 (Regular AA & AAA batteries are rated 1.5V and rechargeable ones are rated 1.2V why the dif and does it make a dif to the devices using them? – Quora)

  • LiPo batteries are reusable so less cost
  • needed current to run the robot for 1 hour estimated around 850mAh
  • Decision: 2-cell 5000mAh LiPo batteries to reach necessary voltage and run for long periods of time. Also able to recharge easily

29/3/2022

April

1/4/2022

  • Team meeting:
  • Problems that arise from using such batteries:
    • We have to redesign the robot as the length of the battery is bigger than the current base.
    • The stepdowns which are on the way (link 15) produce a lot of heat and are not reliable. 
  • solutions:
    • increasing the length and width of the base and re-printing. and mounting the battery under the base.
    • purchasing pre-manufactured voltage regulator link 19 (Arduino Compatible DC Voltage Regulator).
  • Other Problems:
    • the battery will increase the weight by around 400g 
    • the battery has height of 16mm which could possibly get stuck to the bumps on the tiles 
  • solutions:
    • repositioning the location of the motors from being mounted on the base (link 11) to under the base. As seen in link 20 from under the robot: (Copy of re-design of base.jpeg)

2/4/2022

  • Koosha:
  • adding more support to the motor mount as the v1 of the base (link 11) did not provide enough support.
  • Printing the new design. The size comparison can be seen in link 21 (base v2.jpeg)
  • found the ADCPi python library to read voltage:
  • Purchased a 5A blade fuse to account for the safety as LiPo batteries are strong enough to cause fire in case of short circuit.
  • Purchased a switch to be able to power on/off.

7/4/2022

  • George:
  • Assembling the :
    • Raspberry.
    • Motor driver.
    • Battery. 
    • ADCPi.
    • switch.
    • Fuse.
    • IR sensor
  • So far the robot looks like this Link 23 (base one assembled .mp4)

10/4/2022

  • Koosha:
  • Planing the PID algorithm for line follow.
    • challenges:
      • The code has to use a single value (right side of IR – Left side) to decide which way to turn and by how much.
      • the two motors do not turn in the same speed and direction most of the time.
      • first time using the ​​rpi.gpio library link 24 (Welcome to RPIO’s documentation!)
      • the motor driver only accepts positive values (which means we can not use -1 to turn backwards)
    • solution:
      • to use a scale function that can change scale to the desirable range.
      • making a function to change -1 to 1 and – direction before passing the value to the motor driver which results in an error. example can be seen in link 25(Github)
      • full video explaining how the algorithm work can be accessed through link 26 (PID explanation.MOV)
      • More diagrams available through link 27 and 28

20/4/2022

  • Koosha:
  • Ran the line following code for the first time today. The video can be accessed through link 29 (first line follow.mp4)

25/4/2022

  • Koosha:
  • Issues:
    • The raspberry pi decided to die out of nowhere.
  • solution:
  • more issues:
    • The new os seems to be based on a different port of linux called the bullseye. There seems to be an issue with connecting github to visual studio code. (could not find a solution)
    • have to re-install ADCPi and rpi.gpio libraries 

May

2/5/2022

  • Team meeting:
  • designing the second level which will hold the motors, the box in which victims will be stored and the Huskeylens.

4/5/2022

George:

  • assembling the 3D printed parts for the design. the final result can be seen with link 31 (second level v1.HEIC)
    • issued with the new design:
      • as we used glue to stick the parts they are very weak.
      • no access to the interior after assembling the robot 
    • solutions:
      • We sketched walls which will be screwed to holders.
      • The design allows us to open the robot by unscrewing only 2 screws, Making it super easy to adjust the robot.

5/5/2022

Koosha:

  • Re-designing the walls and printing them.
    • images are available through links 32 and 33:
    • Advantages:
      • parts are more stable.
      • can be re-printed and each part can be modified without changing much.
      • Can easily access the inside of the robot.
    • things to do:
      • making the supports bigger.
      • redesigning and printing the base to make sure the supports are perfectly aligned.

10/5/2022

George:

  • Designed the un-fixed IR sensor holder that adjusts its distance to stay uniform through the course. 
  • Challenges:
    • requires to be attached to the chassis.
  • suggested solution:
    • using lego technic parts.
  • Lego parts measurements available through link 34 (https://i.stack.imgur.com/83RL2.png)
  • final result available through link 35 (IR holder.png)

14/5/2022

Koosha:

  • suggesting possible issues:
    • The distance to the tiles is not enough and sensors can hit the ramps.
    • As the two adjusters are far apart they might not hit the ramp at the same time 
  • solutions:
    • making the adjusters bigger.
    • adding one more in the middle

George:

  • Implemented the suggested improvements,
  • final result is available through link 36 (IR holder v2.png)

15/5/2022

16/5/2022

20/5/2022

 24/5/2022

  • Koosha:
  • started coding the camera and object detection.
  • As the process will be quite long I have decided to write in depth information accessible through link 45 Object detection

29/5/2022

George:

  • Assembled the robot with the new camera holder 
  • final result is available through link 46 (Camera.HEIC)

June

5/6/2022

  • Team meeting
  • printing the arm using reference link 47 (Gripper | 3D CAD Model Library | GrabCAD)
  • the final result available through link 48: Arm v1
    • issues:
      • the arms are too small.
      • components keep falling as they are not fixed.
      • the arm doesn’t open wide enough.
    • ideas:
      • to use the same design for the base but change the arm.
  • After printing the arm the final result looks as link 49:
    • Arm solution .HEIC
    • Advantages:
      • The claws can open wide enough.
      • Easy capture of the victims.
      • Once the victim is captured the chances of it falling are very low.
    • Disadvantages:
      • Due to its shape and design the rescue kit falls out.
      • the rescue kit gets stuck in between the claws which stops them from closing
    • solutions:
      • Adding a sponge like material to the claws to add extra grip.
      • adding an extra piece of support to the base of the arms to prevent the part from coming in between the arms.

7/6/2022

  • Koosha:
  • Designing the arms that attach the gripper to the robot.
    • Problems:
      • Having the servos on the second level will increase the height of the robot.
    • solution:
      • moving the servos to the inside of the robot through the side walls. As seen in link 50 Servos.JPG
  • the final result can be seen with link 51:

9/6/2022

  • George:
  • implementing the solutions previously mentioned about the gripper. the results can be seen in link 52 and 53
  • advantages:
    • The rescue kit can now be easily lifted.
    • Rescue kit no longer gets stuck in between the claws.

10/6/2022

Koosha:

  • starts to code the servo motors of the arms and the gripper.
  • A servo motor knows which angle to travel to based on a signal sent by the microcontroller (Raspberry Pi in our case) 
  • As python is not a computer based language, there is a small delay between the time it is compiled and executed therefore 1.5ms pulse could be 1.6 or 1.4 which servo considers it as different angle and a jitter is produced.
    • solution:
      • using the library available at link 55(pigpio Daemon)
      • by doing so the pulse will be handled through hardware and not software therefore the pulses will be accurate.
  • the source code is available through link 56:

14/6/2022

  • Koosha:
  • Issue: the servos are too fast and the claws might throw the ball instead of grabbing it.
    • solutions:
      • reduce the voltage. (makes them weaker)
      • code them to move a degree or two at a time with a fraction of second delay in between each pulse
    • advantages of second method:
      • controls the speed. Improves the accuracy 
    • disadvantages:
      • As we do not know the current location of the servo we can not code it to move slowly from the current position. The servo will move fast to the starting angle and from there it moves slowly.
    • the code examples available in link 57:
    • Github

15/6/2022

  • Team meeting:
  • Issue: 
    • The Raspberry Pi reaches to 60 degrees while running frame analyzation and doing so decreases the speed significantly.
  • solution:
    • Attaching a fan aimed at the processor.
    • available through link 58 and 59:
    • Fan Mount.png
    • Fan
  • George:
  • designing a custom PCB for power distribution using link 60 EasyEDA
  • Available through link 61: PCB V1.png
  • ordered them through link 62: JLCPCB

20/6/2022

  • Koosha:
  • issues when the servos run:
    • I have observed that when we run the servos I get low voltage warning on the raspberry pi example in link 63:
    • Low voltage
    • The raspberry pi shuts down when 3 servos run at the same time.

26/6/2022

  • There is a spike in current when first a motor or servo is first starting to move which exceeds the current limit on the voltage regulator and kills it.
  • solution:
    • Buy another voltage regulator to power the servos.
    • and use the first one to power Raspberry Pi.

27/6/2022

  • George:
  • issues caused by using a ramp evacuation system as seen at the end of link 2:
    • if the angle is not sharp enough, the rescue kit will not slide out.
    • if the angle is too sharp the box will not be as big 
  • to solve:
  • Designing another PCB that will reduce a lot of cables. available to see in graph 4 through same manufacturer and website
  • Koosha:
  • Designing a servo motor for the camera which allows it to move up and down. available through link 67

29/6/2022

  • Team meeting:
  • Issue: 
    • The robot is not strong enough to go up the ramps:
  • solutions:
  1. Get a stronger battery and 12v motors. 
  2. use the same motor but make the wheels sticky to improve traction.
  3. add a motor driver and 2 more dc motors.
  4. get 6v motors with a higher gear ratio and torque.
  • Disadvantages of each option:
    1. will significantly increase the weight and will require more space.
    2. not reliable enough.
    3. have to re-code the line following algorithm.
    4. will significantly slow down the robot.
  • Final decision :
  • To add a motor driver and 2 more DC motors with the same gear ratio. 

July

1/7/2022

  • Team meeting:
  • Re-designing the base for a four wheel drive: available through link 68
  • finished assembling the evacuation box. The first test can be seen through link 69:

2/7/2022

  • Koosha:
  • Adjusting the victim rescue available to see at link 70:
  • Issues:
    • the Robot will hit the ball and accidentally push it too far.
  • solution:
    • Finding the estimated distance to the victim and only travelling far enough.
  • To implement:
    • calculating the relationship between the y value of the center of the victim to the distance. Which results in graph 5:
  • by dividing 1/Distance to the robot we can transform the graph and increase the r value from 0.78 to 0.99 for a really high accuracy. Which results in graph 6:

Now we can use the linear equation and estimate the distance as seen in line 15 at link 71 GitHub.

3/7/2022

  • George:
  • Rewiring the robot and preparing for the competition.

4/7/2022

  • Team:
  • Purchasing backup parts.

5/7/2022

  • Team:
  • Soldering the new PCB. Available to see in link 72:
  • PCB.jpeg

6/7/2022

All Images are available here: https://drive.google.com/drive/folders/16tpbjV4dFGhzcPJA7UBUi8r4UxX3bfHi?usp=sharing