Lcd plus sensor and motorshield connected to one Arduino Uno

I have a Arduino Uno connected to a v2.0. motor shield which I use for 1 stepper motor. I think I've seen somewhere that the motor shield uses the two SDA and SCL ports to comunicate with the Arduino Uno. Now I've connected a 16x02 lcd display with I2C module to 5V / GND / A4 / A5. But I need to more ports with a I2C bus for a sensor. can I just take A2 and A3 for the sensor?

If yes then I don't know how to connect it in the code.

LiquidCrystal_I2C lcd(0x27, 16, 2);

I've tried to connect the lcd to A2 and A3 but it won't work because I think I need to change the 0x27 to another number. Does anyone know how to use one Arduino Uno for two parts with I2C bus needed?

Thank you and best regards!
Michael

Arduino UNO only has a single I2C BUS. (Pins A4 and A5).

The I2C protocol allows you to connect multiple devices using the same pins.

What identifies which device will be used is the I2C address.

Each device connected to the I2C BUS must have a different address from the others.
For example, your LCD display has the address 0x27.

Thank you, and what would the adress be of the second component?
Maybe: 1x27?

No, this first number, (0x..) means that you are using HEX notation and should always be 0x..

You need identify what address of your device reading datasheet, or using the code I2Cscanner.ino

ref: " Arduino Playground - I2cScanner

1 Like

What sensor are you using? The data sheet should tell you its address and how to change it.

1 Like

It's a tof10120
datasheet: https://www.electroniclinic.com/wp-content/uploads/2020/11/TOF10120-Datasheet.pdf

Try address 0x52

SensorRead(0x00,i2c_rx_buf,2);

void SensorRead(unsigned char addr,unsigned char* datbuf,unsigned char cnt) 
{
  unsigned short result=0;
  // step 1: instruct sensor to read echoes
  Wire.beginTransmission(82); // transmit to device #82 (0x52)
  // the address specified in the datasheet is 164 (0xa4)
  // but i2c adressing uses the high 7 bits so it's 82
  Wire.write(byte(addr));      // sets distance data address (addr)
  Wire.endTransmission();      // stop transmitting
  // step 2: wait for readings to happen
  delay(1);                   // datasheet suggests at least 30uS
  // step 3: request reading from sensor
  Wire.requestFrom(82, cnt);    // request cnt bytes from slave device #82 (0x52)
  // step 5: receive reading from sensor
  if (cnt <= Wire.available()) { // if two bytes were received
    *datbuf++ = Wire.read();  // receive high byte (overwrites previous reading)
    *datbuf++ = Wire.read(); // receive low byte as lower 8 bits
  }
}

Thank you very much I'll try that as soon as I get the tof10120 delivered.

The link below will direct you the libraries and example code

Good luck

1 Like

As per the datasheet the I2C address of the TOF10120 is 0xA4 .

Does this comment not stand true?

Wire.beginTransmission(82); // transmit to device #82 (0x52)
  // the address specified in the datasheet is 164 (0xa4)
  // but i2c adressing uses the high 7 bits so it's 82

I found this info here:

" TOF10120 Laser Rangefinder + Arduino + Display, Interfacing & Code.

" TOF10120 I2C Address:

As per the datasheet the I2C address of the TOF10120 is 0xA4. But i2c addressing uses the high 7 bits so it’s 0x52 which is equivalent to 82. You can also find the I2C address of the TOF10120 by using the I2C Scanner code which is available below in the programming section.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.