I2C on Sparkfun ESP32; Pull-Up resistors not working. Ideas?

Posts: 1
Joined: Thu Dec 06, 2018 8:51 pm

I2C on Sparkfun ESP32; Pull-Up resistors not working. Ideas?

Postby jonathanleistiko » Thu Dec 06, 2018 9:48 pm


I'm trying to get an accelerometer to talk to an ESP32 over I2C. It didn't work without pull-up resistors. I added pull-up resistors and it's still not working. I'm looking for suggestions.

Functionally, I'm trying to emulate the steps and success in the article at:
http://www.esp32learning.com/code/esp32 ... xample.php

I'm using:
• A Sparkfun ESP 32 Thing – https://www.sparkfun.com/products/13907
• An Adafruit MMA 8451 breakout board – https://www.adafruit.com/product/2019
• Adruino IDE – Note: I can upload programs (blinky lights, etc.) to the ESP 32 just fine.

I have the accelerometer wired up to the ESP 32 pins, just like it is in this diagram:
https://i0.wp.com/www.esp32learning.com ... .png?w=678
(VIN to 3V, GND to GND, SDA to pin 21 (aka SDA), SCL to pin 22 (aka SCL))

The ESP 32 has the following code uploaded to it:

Code: Select all

#include <Wire.h>
#include "Adafruit_MMA8451.h"
#include <Adafruit_Sensor.h>
Adafruit_MMA8451 mma = Adafruit_MMA8451();
void setup(void) {
Serial.println("Adafruit MMA8451 test!");
if (! mma.begin()) {
Serial.println("Couldnt start");
while (1);
Serial.println("MMA8451 found!");
Serial.print("Range = "); Serial.print(2 << mma.getRange());
void loop() {
// Read the 'raw' data in 14-bit counts
Serial.print("X:\t"); Serial.print(mma.x);
Serial.print("\tY:\t"); Serial.print(mma.y);
Serial.print("\tZ:\t"); Serial.print(mma.z);
/* Get a new sensor event */
sensors_event_t event;
/* Display the results (acceleration is measured in m/s^2) */
Serial.print("X: \t"); Serial.print(event.acceleration.x); Serial.print("\t");
Serial.print("Y: \t"); Serial.print(event.acceleration.y); Serial.print("\t");
Serial.print("Z: \t"); Serial.print(event.acceleration.z); Serial.print("\t");
Serial.println("m/s^2 ");
/* Get the orientation of the sensor */
uint8_t o = mma.getOrientation();
switch (o) {
case MMA8451_PL_PUF:
Serial.println("Portrait Up Front");
case MMA8451_PL_PUB:
Serial.println("Portrait Up Back");
case MMA8451_PL_PDF:
Serial.println("Portrait Down Front");
case MMA8451_PL_PDB:
Serial.println("Portrait Down Back");
case MMA8451_PL_LRF:
Serial.println("Landscape Right Front");
case MMA8451_PL_LRB:
Serial.println("Landscape Right Back");
case MMA8451_PL_LLF:
Serial.println("Landscape Left Front");
case MMA8451_PL_LLB:
Serial.println("Landscape Left Back");
(The Adafruit libraries for the accelerometer are properly installed. I know this because I the same accelerometer breakout board works fine with my Arduino Uno and Nano boards.)

When it runs, I get the following:
configsip: 0, SPIWP:0xee
mode:DIO, clock div:1
entry 0x400802e4
Adafruit MMA8451 test!
Couldnt start
I did a bunch of research. I read that I need to use pull-up resistors to make this work, so I connected SDA and SCL to VCC with 2.2K ohm resistors. Issue persists. I replaced the 2.2K ohm resistors with 3.3K ohm resistors. Issue persists. I replaced the 3.3K ohm resistors with 4.7K ohm resistors. Issue persists.

(Why am I using 2.2, 3.3, and 4.7K ohm resistors? I'm following advice from this thread: https://github.com/espressif/arduino-es ... -357546894 )

Any thoughts?

This YouTuber from Oct 2017 asserts it's an error in the Wire library: https://www.youtube.com/watch?v=qoc7N6Yg5jk I haven't tried this yet, and am not likely to any time soon.

I used the I2C scanner from https://github.com/espressif/arduino-es ... -337461933 and it sees the lone I2C device (the accelerometer).

Thanks in advance for any help you can offer. :)


Posts: 2557
Joined: Thu Nov 26, 2015 4:08 am

Re: I2C on Sparkfun ESP32; Pull-Up resistors not working. Ideas?

Postby ESP_Sprite » Fri Dec 07, 2018 1:56 am

Do you have a scope or LA to see what's going on on the I2C lines? Also, I'm moving your post to the Arduino subforum as that's what you seem to be using.

Posts: 80
Joined: Tue Aug 21, 2018 5:28 am

Re: I2C on Sparkfun ESP32; Pull-Up resistors not working. Ideas?

Postby boarchuz » Fri Dec 07, 2018 7:57 pm

Can you confirm that you ran the i2c scanner on the ESP32? And it found the accelerometer? It's unlikely to be a hardware issue if that is working fine.

In that case, I would be double-checking the address. I suspect it's expecting 0x1D but your accelerometer is at 0x1C (or vice versa). Run the scanner again.

Greg Corson
Posts: 35
Joined: Sun May 20, 2018 9:16 pm

Re: I2C on Sparkfun ESP32; Pull-Up resistors not working. Ideas?

Postby Greg Corson » Tue Jan 15, 2019 9:14 pm

There were some wire library issues in the 1.0.0 release that caused me problems with accelerometers. Sometimes if you reset the chip when the accelerometer was in the middle of sending on I2C it would hold the bus in a state that froze I2C. Fairly soon after this was discovered there was a patch but the only way to get it was to checkout a branch from github. The fix should be in the latest release that was done in January.

I also had some issues because of electrical noise. Basically some disconnected components were randomly oscillating at high frequency and the signal was leaking back into the I2C lines. Probably less likely you have this problem, but if you have access to a scope, try checking your I2C for analog noise.

Also, if you are trying to debug I2C be sure to try going to "tools"->core debug level and setting it to VERBOSE, I2C generates some useful messages that can tell you what's going wrong.

Who is online

Users browsing this forum: No registered users and 8 guests