I have trouble defining the second I2C-bus on my Adafruit Featherwing Huzzah32 ESP32. The standard I2C-bus uses SDA Pin 23 & SCL Pin 22.
Are there predefined pins for the second bus (maybe 33&32?) or is it possible to use any GPIO as long as my software defines them using e.g. Wire1.setPins()

- 13
- 3
-
Only one is configured by default in the Feather Arduino IDE support [show in this website](https://learn.adafruit.com/adafruit-huzzah32-esp32-feather/pinouts?view=all) – Oscar Jul 21 '22 at 11:49
-
@Oscar Thanks. So I can use two random GPIO-Pins and define them via the Wire1.setPins() command? – karovier Jul 21 '22 at 12:20
-
No , use I2C slaves and address them – Oscar Jul 21 '22 at 12:51
-
As Oscar pointed out, you can have have several devices as slaves. [Here is a basic tutorial from adafruit](https://learn.adafruit.com/scanning-i2c-addresses/i2c-basics) – sebo1234 Jul 21 '22 at 13:25
-
1There are perfectly valid reasons for wanting to use the second I2C controller. This is a reasonable question. – romkey Jul 21 '22 at 15:23
-
Yes you can use every output capable gpio and avoid the strapping pins. (Isn’t impossible, but more parts and work) – RemyHx Jul 22 '22 at 15:20
2 Answers
Most ESP32 breakout boards don't define default pins for the second I2C controller, so you'll need to define them when you configure it.
As the question mentioned, you can use the set_pins()
method on a TwoWire
(the class of Wire
and Wire1
) object:
Wire1.set_pins(PIN_SDA, PIN_SCL);
It's important to call this before calling the begin()
method. Doing this allows you to configure Wire1
before passing it to a library which may call begin()
.
You can also set the pins when you call begin()
:
Wire1.begin(PIN_SDA, PIN_SCL);
You can also remap Wire
(the first I2C controller) to different pins this way.
Unfortunately, some libraries do not allow you to pass a TwoWire
object to them, so you'll probably need to make a local copy of any library like this and modify it.
You can use most, but not all, GPIO pins on the ESP32. The pins to avoid are the strapping pins, which determine how the processor boots (GPIO0 and GPIO12 - 12 may work for SCL but I would avoid it if possible), and the high numbered ADC pins, which are input-only (GPIO34 - GPIO39). You might also want to avoid whatever pin is connect to the on board LED, if there is one.
Random Nerd Tutorials has a good overview of what pins are usable on ESP32 CPUs. The usable pins will vary if you're using other variations of the ESP32 like the S2 or S3.
As a couple of people have pointed out, you can connect multiple I2C devices to one controller, but there are valid reasons for using multiple I2C busses, which is what the question asked.
Sometimes an I2C device will not operate well with others (especially if it uses clock stretching). You can also operate two different busses at different speeds. And if you use multiple busses, if a device on one bus crashes and jams the bus it won't interfere with other busses.
And of course, if you need to use two devices which have the same I2C address and can't change the address, using the second built-in I2C controllers is easier than using an I2C multiplexor.

- 6,218
- 3
- 16
- 12
Only one is configured by default in the Feather Arduino IDE support shown here
A better bet would be to address other devices as slaves using their slave address and the same I2C pins like this. I'm assuming you're trying to reach multiple breakout boards, so your Featherwing should run the master code. Then replace the slave address number with the one associated with the breakout board you want to address.

- 96
- 1
- 9