i2c tb6612 Motor driver


I am using i2c tb6612 motor driver for my project with Arduino mega, for display i am using I2C Lcd Display.

My problem is that both of shield required SDA & SCL pin, kindly let me know how i can use both with Arduino mega.

I2C is a bus. It is meant to have multiple devices attached to the same two pins (SDA and SCL). Each device has a unique address, that us how the devices are differentiated.

You will see many examples for the Uno. Pins A4 and A5 are SDA and SCL on an Uno. The Mega uses different pins for I2C. On the Mega, SDA is pin 20 and SCL is pin 21 (or the 2 pins closest to the USB connector).

Really thanks for quick reply sir,I went through the video it covers very nice information. So I can connect SDA and SCL pin of my both device with pin 20 and 21 of Arduino mega?


Remember that the pullup resistors on the SDA and SCl lines are required. Some devices (modules) have the pullups on the board and some do not. If neither the motor driver nor the LCD have pullups on their boards, you will need to provide them. A 4.7K resistor from the SDA pin to 5V and another 4.7K from the SCL pin to 5V will do.

Also, keep the wires between the I2C devices and the Mega as short as possible. The I2C bus is meant to connect devices on the same board and will not, reliably, communicate over longer distance (> 0.5 meters). The distance can be extended by using lower value pullup resistors (1K to 2K at the minimum) and/or lowering the data rate.

Arduino MEGA has built-in pull-up (2x10k) resistors with the SDA/SCL lines.

Sir I connected both togather. Both are working fine but when restart my arduino then only display is working motor is not workibg..After reloading code then both are working together.

If you could show us your secret code we don‘t have to use our crystal balls to assist you :wink:

Sorry sir I am very new to this, learning day by day with the help of you all, thanks for that :slight_smile:

my code is below:

#include <Adafruit_MotorShield.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// all connection and starting stage************************************************************************************************************************************
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
Adafruit_DCMotor *motor1 = AFMS.getMotor(3);
Adafruit_DCMotor *motor2 = AFMS.getMotor(4);
Adafruit_StepperMotor *myMotor = AFMS.getStepper(48, 1);

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

void setup() {
   lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print("Stepper test!");

  AFMS.begin();  // create with the default frequency 1.6KHz
  //AFMS.begin(1000);  // OR with a different frequency, say 1KHz
  myMotor->setSpeed(10);  // 10 rpm   

  void loop() {
  Serial.println("Single coil steps");
  myMotor->step(100, FORWARD, SINGLE); 
  myMotor->step(100, BACKWARD, SINGLE); 

  Serial.println("Double coil steps");
  myMotor->step(100, FORWARD, DOUBLE); 
  myMotor->step(100, BACKWARD, DOUBLE);
  Serial.println("Interleave coil steps");
  myMotor->step(100, FORWARD, INTERLEAVE); 
  myMotor->step(100, BACKWARD, INTERLEAVE); 
  Serial.println("Microstep steps");
  myMotor->step(50, FORWARD, MICROSTEP); 
  myMotor->step(50, BACKWARD, MICROSTEP);

Hi please suggest me what to do now..

Is this your motor shield? Link to motor shield.

To see if the shield is communicating with the I2C bus and to confirm the addresses of the devices on the I2C bus, run this I2C scanner and report (copy and paste into a post) the results.

// I2C scanner by Nick Gammon.  Thanks Nick.

#include <Wire.h>

void setup() {
  Serial.begin (115200); //*****  make sure serial monitor baud matches *****

  // Leonardo: wait for serial port to connect
  while (!Serial) 

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  for (byte i = 1; i < 120; i++)
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}

Yes sir I am using that motor shield .

Ldc device i2cbus address is 0×27, and there is no motor shield address now...You are asking to find motor shield bus address?

I am asking you to run the scanner to see if the motor shield shows up on the bus. If the I2C scanner can't find it, your program won't either.

These devices are showing:

I2C scanner. Scanning ...
Found address: 39 (0x27)
Found address: 96 (0x60)
Found address: 112 (0x70)
Found 3 device(s).

My problem is all are working fine but when restart my Arduino then only display is working motor is not working..After reloading code then both are working together.

Sir please help ..

What happens when you run the stepper test example from the library by itself (without the LCD and DC motor code)? Does the same thing happen?