Tech Note 075 - How to connect and get I2C devices working (Arduino, ESP32, ESP8266)

preview_player
Показать описание
An improved explanation (I hope) of how to get I2C devices to function that can often be problematic, be it determining which pins on a development board are SDA and SCL; determining the I2C device address to resolving conflicting library functions that all prevent a device from working.

Code for I2C Scanner:
Рекомендации по теме
Комментарии
Автор

Good go through debugging of I²C
"An expert is a man who has made all the mistakes which can be made, in a narrow field." -- Niels Bohr

chlordk
Автор

Thanks for a very good tutorial and video. Just a tip, when you order BME280 on Ebay you will most likely get a BMP280 delivered to you. The BMP280 can only measure temperature and air pressure. That means no humidity is shown.

oladunk
Автор

Very important hint, I solved the problem by copying changed libraries into the local libraries folder, then with platformio they have 1st priority and the global lib will not be changed. But without your hint, I have never had found the problems. THX

DocMicha
Автор

thank you without this video i probably would not have though to change the bus adress from the library

emiel_nl
Автор

Thank you for this video! Had to make a deeper cut on my BME/BMP280 to change the I2C adress..

Faewks
Автор

It helps a lot, many thanks for spending time for such valuable lesson.. I hope you doing good as in good in many good things, truly

foodbygintea
Автор

Thanks, great clear video once again.

philwilkinson
Автор

Haha! What are the chances of you posting this today? Spent a while trying to get a Chinese BMP280 on I2C talking over ESP-now. HEX address and library mods discovered the hard way!
Thanks for an other very handy demo!

garrypkeogh
Автор

The LED is on D4 (why show or make that breakout pin?) and D8 can't be hardware high at boot (no boot). Just saying because it was extra work. I plan to use 10 or more of those ESP8266 boards because they don't heat up so much with ESP Now. Got some RX/TX working as well, so they can be expansions.

elektronkim
Автор

Hello,
My ESP32 I2C still aren't working. I'm trying to connect that with MPU6050. I'm using Lolin32 Lite and there are no 21 and 21 pins out. I'm doing:

Wire.begin(13, 15);
Serial.println(SDA);
Serial.println(SCL);

That still printing out 21 and 22.

When it comes to the libraries I'm using only Wire.h, nothing more.

What could be the case?

Xkam
Автор

Thanks for your tutorial. But my ESP32 reboots some times when I use RTC DS3231 chip, I can fix it

vtech
Автор

Hi I am unable fix i2c device issues with any device connecting with esp8266 did multiple trials to fix but found no solution I will be happy if you could help me finding a solution with i2c oled with esp8266

BennyJacksonbj
Автор

// i want to connect apds9960 and mpu6050 but it doesn't work
//people help me .
// i have changed some a little things in the code of apds9960.
#include <Wire.h>
#include "mpu6050.h"
#include <SparkFun_APDS9960.h>
// Pins
#define APDS9960_INT 2 // Needs to be an interrupt pin
// Constants
// Global Variables
SparkFun_APDS9960 apds = SparkFun_APDS9960();
int isr_flag = 0;
float tmp;
int address_sensor1= 0x68; //binary equivalent is 1001000

int address_sensor2= 0x39; //binary equivalent is 1001001

int accelX, UP, DOWN, LEFT, RIGHT;
void setup(){

Serial.begin(115200); //this creates the Serial Monitor

Wire.begin(); //this creates a Wire object
mpu6050();

Serial.println();

Serial.println(F("SparkFun APDS-9960 - GestureTest"));


// Initialize interrupt service routine
attachInterrupt(0, interruptRoutine, FALLING);

// Initialize APDS-9960 (configure I2C and initial values)
if ( apds.init() ) {
Serial.println(F("APDS-9960 initialization complete"));
} else {
Serial.println(F("Something went wrong during APDS-9960 init!"));
}

// Start running the APDS-9960 gesture sensor engine
if ( ) {
Serial.println(F("Gesture sensor is now running"));
} else {
Serial.println(F("Something went wrong during gesture sensor init!"));
}

}

void loop(){
//Send a request to begin communication with the device at the specified address

Wire.write(0xFC);
Wire.write(0xFD);
Wire.write(0xFE);
Wire.write(0XFF);

Wire.endTransmission(); //this ends transmission of data from the arduino to the temperature sensor

Wire.requestFrom(0x39, 6); //Request Accel Registers (3B - 40)// 0x68
while(Wire.available() < 6);

UP = Wire.read()<<8|Wire.read(); //Store first two bytes into UP
DOWN = Wire.read()<<8|Wire.read(); //Store first two bytes into DOWN
LEFT = Wire.read()<<8|Wire.read(); //Store first two bytes into LEFT
RIGHT = Wire.read()<<8|Wire.read(); //Store first two bytes into RIGHT

processAccelData();
delay(1000);

//I2C address of the MPU
Wire.write(0x3B); //Starting register for Accel Readings
Wire.endTransmission();

Wire.requestFrom(address_sensor2, 6); //Request Accel Registers (3B - 40)// 0x68
while(Wire.available() < 6);
accelX = Wire.read()<<8|Wire.read(); //Store first two bytes into accelX

processAccelDataB();

delay(1000);

}

void interruptRoutine() {
isr_flag = 1;
}
void processAccelData(){
if( isr_flag == 1 ) {
handleGesture();
detachInterrupt(0);
isr_flag = 0;
attachInterrupt(0, interruptRoutine, FALLING);
}
}

void processAccelDataB(){
int value=map(accelX, -16384, 16384, -90, 90);

}

void handleGesture()
{

apds.readGesture();

if(UP==DIR_UP)
{
Serial.print("UP");
}
else if(DOWN==DIR_DOWN)
{
Serial.print("DOWN");
}
else if(LEFT==DIR_LEFT)
{
Serial.print("LEFT");
}
else
{
Serial.print("RIGHT");
}

}

quocna
visit shbcf.ru