Comments on: ESP32 I2C Communication: Set Pins, Multiple Bus Interfaces and Peripherals (Arduino IDE) https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/ Learn ESP8266, ESP32, Arduino, and Raspberry Pi Tue, 14 Jan 2025 22:31:29 +0000 hourly 1 https://wordpress.org/?v=6.8.2 By: Deepak https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/#comment-999931 Tue, 14 Jan 2025 22:31:29 +0000 https://randomnerdtutorials.com/?p=89386#comment-999931 In reply to Rajiv Shankar.

In theory it seems 128 devices can be connected. But practically it depends on the current drawn by the devices. The signals get weak if you connect more devices. You need to try adding and let everybody know how much you reached successfully.

]]>
By: Deepak https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/#comment-999930 Tue, 14 Jan 2025 22:28:12 +0000 https://randomnerdtutorials.com/?p=89386#comment-999930 In reply to Simon.

Depends, I have used esp32 with omron thermal array sensors which work on 5v, but the sensors accepted 3.3v data and esp32 pins seems 5v tolerant so I faced no issue. But as a precaution you must use a suitable resistor to limit current. In my case I used 1k resistor in series with scl and sda lines.
Here’s the trick with data transmission here, mostly half their vcc seems to be threshold point that is 1.65 for esp32 and 2.5v for sensor. So it kinda works fine.

]]>
By: Hubert https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/#comment-980624 Mon, 04 Nov 2024 15:06:48 +0000 https://randomnerdtutorials.com/?p=89386#comment-980624 Hi,
great tutorial!

But I have a major problem where I hope to get your support:
I tried to connect two HTU21D humiditiy sensors (where the address is fixed to 0x40) to an ESP32-S3 Mini Development Board.

I used your explanations in chapter “ESP32 Using Two I2C Bus Interfaces”, which is exactly what I need, and tried to modify it in a way to connect the HTU21D sensores insted of the BME.
Unfortunately I cannot compile with the Arduino IDE.

The problem seems to be in the setup() section of the code.
When I try to start the 1st sensor I get the followeing error message: “Compilation error: void value not ignored as it ought to be”

Here is my code, maybe somebody could help me:

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <SparkFunHTU21D.h>

#define SDA_1 2 // define SDA pin of 1st I2C bus
#define SCL_1 1 // define SCL pin of 1st I2C bus
#define SDA_2 4 // define SDA pin of 2nd I2C bus
#define SCL_2 3 // define SCL pin of 2nd I2C bus

TwoWire I2C_one = TwoWire(0); // create instance of 1st I2C bus
TwoWire I2C_two = TwoWire(1); // create instance of 2nd I2C bus

HTU21D HTU21_one; // create instance of 1st HTU21 sensor
HTU21D HTU21_two; // create instance of 2nd HTU21 sensor

void setup() {
Serial.begin(115200); // start serial

I2C_one.begin(SDA_1, SCL_1, 100000); // initialize 1st I2C bus
I2C_two.begin(SDA_2, SCL_2, 100000); // initialize 2nd I2C bus

bool status1 = HTU21_one.begin(I2C_one);
if (!status1) {
Serial.println(“Could not find a valid HTU21_1 sensor, check wiring!”);
while (1);
}

bool status2 = HTU21_two.begin(I2C_two);
if (!status2) {
Serial.println(“Could not find a valid HTU21_2 sensor, check wiring!”);
while (1);
}
Serial.println();
}

void loop() {
// Read from HTU21_one
Serial.print(“Temperature sensor1 = “);
Serial.print(HTU21_one.readTemperature());
Serial.println(” *C”);

Serial.print(“Humidity sensor2 = “);
Serial.print(HTU21_one.readHumidity());
Serial.println(” %”);

Serial.println(“——————–“);

// Read from HTU21_two
Serial.print(“Temperature sensor2 = “);
Serial.print(HTU21_two.getTemperature());
Serial.println(” *C”);

Serial.print(“Humidity sensor2 = “);
Serial.print(HTU21_two.getHumidity());
Serial.println(” %”);

Serial.println(“——————–“);

delay(1000);
}

]]>
By: Joachim https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/#comment-951113 Sun, 25 Aug 2024 12:36:03 +0000 https://randomnerdtutorials.com/?p=89386#comment-951113 Thanks for great tutorial!
If you have to use different pins than GPIO21 and GPIO22 (e.g. for WEMOS LOLIN32 Lite) it might help to set the needed pins by calling setPins function from Wire library before begin().
In my case for accessing the BME280 via WEMOS LOLIN32 Lite I use the library “Grove-Barometer_Sensor_BME280” where the pins to be used are SDA=23 and SCL=19 the initialization of the sensor is done via something like:

#include “Seeed_BME280.h”
#include <Wire.h>
BME280 bme280;

bool setSDA_SCL = Wire.setPins(23,19);
bool result;
result = bme280.init();

]]>
By: summer https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/#comment-939091 Thu, 18 Jul 2024 16:36:27 +0000 https://randomnerdtutorials.com/?p=89386#comment-939091 Hi,
do you test T-Display S3 with BME280?
I used your code on it doesn’t work.

]]>
By: Pentti Tarnanen https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/#comment-911223 Tue, 30 Apr 2024 08:09:50 +0000 https://randomnerdtutorials.com/?p=89386#comment-911223 Solved the problem. My own mistake caused problem. There are GPIO20 and GPO21 pins I can use for I2C.

]]>
By: Pentti Tarnanen https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/#comment-911217 Tue, 30 Apr 2024 07:47:23 +0000 https://randomnerdtutorials.com/?p=89386#comment-911217 Hello Sara and Rui!
I have tried to get the OLED SSD1306 display to work in the ESP32-C3 Super Mini environment without success. The card does not have GPIO 21 and GPIO 22 pins. I have tried to redefine those pins but have not been able to get the display to work. Do you have any experience with this problem?

]]>
By: Sara Santos https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/#comment-902987 Wed, 03 Apr 2024 10:46:56 +0000 https://randomnerdtutorials.com/?p=89386#comment-902987 In reply to JohnU.

That’s great.
Thanks 😀

]]>
By: JohnU https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/#comment-902864 Tue, 02 Apr 2024 19:51:13 +0000 https://randomnerdtutorials.com/?p=89386#comment-902864 Great explanation! The ESP32 documentation hinted at supported I2C, but with no examples.
You saved me from buying an Arduino board that supports I2C.

]]>
By: Edgier https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/#comment-897392 Sat, 09 Mar 2024 16:36:16 +0000 https://randomnerdtutorials.com/?p=89386#comment-897392 Useful summary. With ESP32S3, Arduino IDE 2.2.1, I got a compiler error until I omitted the ‘&’ in the Wire1 definition

]]>