Good Morning from San Tan Valley Arizona!
For ESP32-S3-DevKitC-1U V1.0 and Arduino IDE
I worked through a tutorial at https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/#3 at Use Different I2C Pins with ESP32 (change default I2C pins) and it certainly set me straight on reassigning I2C to other more convenient GPIO pins. And it works for the BME280 and the SSD1306 OLED separately, but the next example at Multiple I2C devices (same bus, different addresses) showing how to use both modules on the same I2C bus does not address reassigning I2C to other GPIO pins and I cannot for the life of me figure out how to get both working on the same I2C bus AND be reassigned to other pins.
I tried doing a simple I2C address scan with both on the reassigned bus, and they both respond to their addresses, but I cannot get both to initialize and function. The code just hangs checking to see if they are there.
I need to find and read up on…
- How to setup and initialize the SSD1306 and assign I2C to different GPIO pins.
- How to setup and initialize the BME280 and assign I2C to different GPIO pins.
- TwoWire and how it works. Do I use it to create separate I2C bus objects per device that point them to an already created I2C bus assigned to other GPIO pins?
- Why (and how) is the setup for AdaFruit BME280 different from the AdaFruit SSD1306.
Also, everyone says to use the default GPIO (21 and 22) for I2C but my ESP32-S3-DevKitC-1U V1.0 (external antenna) does not have a GPIO 22 broken out on the board, and I cannot find what the development board’s default I2C pins are. It has two I2C peripherals also. The legend for the pinout does not even mention I2C, or at least with an acronym I have encountered yet.
I hope someone can help. Thank you for your valuable time!
Hi.
To find your board default I2C pins, try to run the following code:
void setup() { // put your setup code here, to run once: Serial.begin(115200); Serial.print("SDA: "); Serial.println(SDA); Serial.print("SCL: "); Serial.println(SCL); } void loop() { // put your main code here, to run repeatedly: }
This section explains how to set custom pins for BME280.
ESP32 I2C Communication: Set Pins, Multiple Bus Interfaces and Peripherals (Arduino IDE)
You use the same logic for the SSD1306.
Bur if you want to see an example, check this project, where we assign different pins for the SSD1306: https://randomnerdtutorials.com/esp32-built-in-oled-ssd1306/
“TwoWire and how it works. Do I use it to create separate I2C bus objects per device that point them to an already created I2C bus assigned to other GPIO pins?
“
When creating a two wire instance, you select the I2C pins. I think you just need to create one TwoWire instance if your’re using the same bus for both devices. Then, when initializing the devices, select their specific address.
“Why (and how) is the setup for AdaFruit BME280 different from the AdaFruit SSD1306.”
You have to take a look at the libraries source files:
– https://github.com/adafruit/Adafruit_BME280_Library/blob/master/Adafruit_BME280.cpp
– https://github.com/adafruit/Adafruit_SSD1306/blob/master/Adafruit_SSD1306.cpp
I hope this helps.
Regards,
Sara
Thank you so much Sara for the reply!!
That first code to find the defaults is awesome! Of course I would probably know that at some point going through the courses. I went ahead and got them all so I will be spending a lot of time going through them. I do not normally use the Arduino IDE. I use VSCODE for everything but I had a terrible time trying to code using the ESP-IDF in VSC so I moved back to Arduino-IDE where there is a lot more “hand-holding” to guide you through what you need to do.
The rest of your post I will step-through when I finish working at my primary job today. And I sincerely cannot wait! I will post back with my results.
Thanks again Sara for the reply and the help. I really appreciate it! I want to use the ESP32 for everything I want to do with our new smart home, and numerous other projects including robotics, solar, AI, audio analysis, SDR analysis, and smart tiny toys I print for my grandkids. 🙂 Thanks for the site and all the knowledge!
Thank you Sara! I made the modification that you suggested and sure enough, the sketch worked as expected with reassigned pins. I am now trying to figure out how to track that down using the links you provided, so I know where to look the next time it happens, and I am sure it will soon enough. I haven’t been able to track it down yet, and wonder if it is possible to set a debug break point in a called library so I can trace it. I just want to be self-sufficient and not have to ask questions like this again.
Thanks again for the help and the solution!! I marked your answer as the solution.
Hi.
Unfortunately, I don’t know how to do that or if that’s possible (I don’t think so).
But, if you provide more details about what you’re struggling with and the current code that you have, maybe I can try to take a look.
Regards,
Sara
Thank you Sara, there is plenty of info online on how to look at library code to figure out what parameters are needed to use it. I’m just not there yet. After I refamiliarize myself with CPP it will be easier. Along the way thus far I have a short list of strange anomalies to research and I will definitely post if I hit a brick wall working through those.