How to program a motor circuit with the TB67H420FTG

This is a continuation of a series of articles for how to Build A Custom PID Line Following Robot From Scratch. In this article I’ll show you how to program a motor circuit we made previously in this article How to build a motor circuit with TB67H420FTG

Parts

We actually don’t need any new parts for this, all of the parts we will use are on our circuit we built in the previous article.

Watch the video

If you prefer to watch a video, you can check that out below or continue on. The first half of the video discusses details about the motor driver and how I hooked it up, the second half covers the programming portion.

The code

The library I use in the video can be found here: https://github.com/mcc-robotics/Dynamic_Motor_Driver

What next?

Let’s get this thing on a chassis and get moving, check out the next video from the main page Build A Custom PID Line Following Robot From Scratch

2 Comments

  1. Joseph Wheelahan

    Hi, this was a very helpful video. What would one do if they want to use lets say three of these driver boards controlling a total of 6 motors. How would you be able to have motors C, D, E and F? Is that possible with the library?

    1. Good question, the beauty of using objects is you can theoretically create as many as you want. So, using multiple motor drivers is as simple as creating an object for each motor driver. You won’t be able to reference them as motors C, D, E, and F (that’s just simply because motors drivers that can control two motors usually refer to motors A and B so you have to think of it with respect to each driver). Instead you’d have something like driver1.setMotorAPower(50), and driver2.setMotorAPower(50) where driver2 motor A would be the equivalent of motor C. Here’s a quick example (this wouldn’t be working code on an Arduino as you need PWM pins assigned appropriately):

      L298 driverAB(3, 4, 5, 6);
      L298 driverCD(7, 8, 9, 10);

      void setup() {
      // The only thing left to do is call init() so the library can initialize the pins
      driverAB.init();
      driverCD.init();

      // Now to control motors A and B
      driverAB.setMotorAPower(50); // Motor A
      driverAB.setMotorBPower(50); // Motor B

      // And control motors C and D
      driverCD.setMotorAPower(20); // Motor C
      driverCD.setMotorAPower(20); // Motor D

      // And so on...
      }

      You could also name them something more specific like, if you have a four wheel drive vehicle, you might have the rear driver be called rearDriver and the front driver be frontDriver so you could say rearDriver.setAllCoastPower(50) and frontDriver.setAllCoastPower(50) which would set all motors on both drivers to half speed.

Leave a Reply

Your email address will not be published.