0

Is it possible to connect more than one I2C device to an Arduino Uno? I know that the SCL and SDA pins are on analog pins A4 and A5 respectively, but there are also two pins labeled SCL and SDA located next to the AREF pin on the other side of the board. Does that mean I can connect multiple devices to the same board and, if so, how?

For context, I'm currently working on creating a robotic arm that matches its movements to the movements of my arm (I believe this is called a telepresence robot). To do so, I wanted to use a couple of IMUs (specifically the MPU-6050) to record the movements of my wrist and shoulder. Using the TinyMPU6050 library by Gabriel Milan, I've already been able to establish communication with one IMU, but I'm struggling with the second one. I'm already communicating with the arm via the Uno's SPI interface so I can't use that to communicate with a second IMU, although I know it's possible.

I know that similar questions have been asked before, but none of the questions I could find had the exact answers that I needed, so I thought I would ask anyway. This code that I currently have works for one IMU, but I don't know where to begin to add a second one (if it's even possible). Any help that I can get would be greatly appreciated. Cheers!

#include <TinyMPU6050.h>
MPU6050 IMU_1(Wire);
void setup() {
 Serial.begin(9600);
 //initializing and calibrating `IMU_1`
 IMU_1.Initialize();
 Serial.println("Calibrating...");
 IMU_1.Calibrate();
 Serial.println("Calibrated");
 while (!Serial) {
 //empty while loop
 }
}
void loop() {
 IMU_1.execute();
 Serial.println();
 Serial.print("X angle = ");
 Serial.println(IMU_1.GetAngX());
 Serial.print("Y angle = ");
 Serial.println(IMU_1.GetAngY());
 Serial.print("Z angle = ");
 Serial.println(IMU_1.GetAngZ());
 delay(1000);
}
asked Jul 13, 2021 at 19:19

1 Answer 1

3

I2C is a multi-drop bus. That means that one set of I2C pins are designed to have multiple devices on it as long as each device has a unique address.

On an Uno the discrete I2C pins and the A4/A5 I2C pins are the same pins. The discrete pins are an attempt to provide a cross-platform standard location for the I2C signals for shields.

answered Jul 13, 2021 at 19:30
3
  • So, since I don't have a way of connecting multiple devices to the A4/A5 pins, does that mean that I can connect one IMU to the A4/A5 pins and one to the discrete pins and have it still function as long as I give them different addresses? Thanks for your help! Commented Jul 13, 2021 at 19:42
  • Yep. Except you don't normally "give" I2C devices addresses (unless you're making them yourself) - you usually are able to select between a couple of addresses using special pins on the I2C devices. If you can't select different addresses then you have the option of an "I2C multiplexer" to select between them. Commented Jul 13, 2021 at 20:02
  • Adding on to Majenko, you might find A1, A2, A3 on your I2C device, usually these are not connected, by soldering them (individually) you can change the address of your device, which you can then change in your code Commented Jul 14, 2021 at 1:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.