I2C on Sparkfun ESP32; Pull-Up resistors not working. Ideas?
Posted: Thu Dec 06, 2018 9:48 pm
Howdy!
Summary:
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
Details:
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:
(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:
(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?
Etc...
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.
JAL
Summary:
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
Details:
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.begin(115200);
Serial.println("Adafruit MMA8451 test!");
if (! mma.begin()) {
Serial.println("Couldnt start");
while (1);
}
Serial.println("MMA8451 found!");
mma.setRange(MMA8451_RANGE_2_G);
Serial.print("Range = "); Serial.print(2 << mma.getRange());
Serial.println("G");
}
void loop() {
// Read the 'raw' data in 14-bit counts
mma.read();
Serial.print("X:\t"); Serial.print(mma.x);
Serial.print("\tY:\t"); Serial.print(mma.y);
Serial.print("\tZ:\t"); Serial.print(mma.z);
Serial.println();
/* Get a new sensor event */
sensors_event_t event;
mma.getEvent(&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");
break;
case MMA8451_PL_PUB:
Serial.println("Portrait Up Back");
break;
case MMA8451_PL_PDF:
Serial.println("Portrait Down Front");
break;
case MMA8451_PL_PDB:
Serial.println("Portrait Down Back");
break;
case MMA8451_PL_LRF:
Serial.println("Landscape Right Front");
break;
case MMA8451_PL_LRB:
Serial.println("Landscape Right Back");
break;
case MMA8451_PL_LLF:
Serial.println("Landscape Left Front");
break;
case MMA8451_PL_LLB:
Serial.println("Landscape Left Back");
break;
}
Serial.println();
delay(500);
}
When it runs, I get the following:
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.rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:808
load:0x40078000,len:6084
load:0x40080000,len:6696
entry 0x400802e4
Adafruit MMA8451 test!
Couldnt start
(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?
Etc...
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.
JAL