esp32MX-E icon indicating copy to clipboard operation
esp32MX-E copied to clipboard

Using I2C on the esp32

Open GeorgeSellner opened this issue 5 years ago • 3 comments

Hello,

I have been trying to use the I2C, pins 32, 33 from the Arduino IDE, and haven't had much luck. Same code, different pins, same I2C devices (BME280, RV-8803) work on a MEGA.

I haven't yet tried putting a 'scope on it to see if the code is actually doing anything. I haven't yet tried through the idf.

I was wondering if anyone else has been working with The I2C, either though the Arduino IDE or through esp-idf?

I have also been experiencing issues downloading through the CH340 under Linux, (Ubuntu 18.04). However I'm pretty sure part of the problem is I'm using a VirtualBox VM for the Linux guest on a Windows 10 host.

On a Ubuntu 14.04 laptop I can download and from Windows 10.

GeorgeSellner avatar Jul 08 '20 19:07 GeorgeSellner

@GeorgeSellner Did you get I2C work? I have the same question.

pauldeng avatar Sep 02 '20 01:09 pauldeng

If you want to use I2C, you can actually use pin 4 and pin 5. For example, I hooked up a sht30 and just initialise it as below would work:

#include "Adafruit_SHT31.h"

#define I2C_SDA 4
#define I2C_SCL 5
#define SHT30_I2C_ADDR 0x44

TwoWire I2C_DEV = TwoWire(0);
Adafruit_SHT31 sht30 = Adafruit_SHT31(&I2C_DEV);

void setup()
{
  I2C_DEV.begin(I2C_SDA, I2C_SCL);
  
  // read the sht sensor
  if (! sht30.begin(Internal_SHT30_ADDR)) {
    Serial.println("Couldn't find Internal SHT31");
    delay(1);
  } else {
    float t= sht30.readTemperature();
    float h= sht30.readHumidity();
    Serial.print("Temp *C = "); Serial.print(t); Serial.print("\t\t");
    Serial.print("Hum. % = "); Serial.println(h);
  }
}

In my application, I need both UART and I2C to work and communicate via Ethernet. However, I can not get this board to work reliability.

I decided to move on after pulling off my hair for few days of try.

Good luck, you are on your own.

pauldeng avatar Sep 14 '20 06:09 pauldeng

Same problem here. On the scope, SCL is only getting pulled low to ~2.3V during I2C operations. Seems that the STM32 (secondary processor) firmware is initializing that pin as a UART TX, which defaults to a high state and prevents it from being able to be pulled low for I2C.

SDA seems to still be usable, but another pin will need to be used for SCL and you will likely need to add your own pullup resistor (2.2kOhm to match the on-board one for SDA).

skiizo avatar Oct 23 '20 17:10 skiizo