Good morning everyone…
I have a little big problem in my project where I'm using different libraries that work great without conflicts with each other.
But now I have to transfer variables between a NANO and an ESP 32 38 pin using the WIRE library through I2c.
Result I have no data transfer between the two processors LCD does not work and BME 680 is not recognized.
In summary
NANO has to send data of a variable (x in my case) through I2c
ESP 32 must receive data with I2c using WIRE library
ESP 32 connected with I2c a 24x4 LCD display
ESP 32 connected a BME 680 with I2c
GND in common 5V power supply.
etc.
All services with I2c work fine without WIRE library
As soon as I insert this into the project, there is no transfer between the NANO and the ESP 32.
The instructions work perfectly between NANO and ESP 32 using only the WIRE and eliminating the use of other peripherals that use I2c
Very small connections about 10cm.
Through the serial line, only the variable x of the Loop is updated with the print of the zero previously assigned, but not updated by the receiveEvent(int howMany).
Some idea? Should I use a different library? Are there any known issues with ESP 32 and the WIRE?
I've already searched for a similar problem on the net, but haven't found anything for my case.
Thanks in advance for your attention.
#include <Wire.h> // Library for I2C communication
#define I2C_DEV_ADDR 0x55
#include <LiquidCrystal_I2C.h> // Library for LCD
//------------------------------------------------------------------------ SENSOR BME 680 //
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "MutichannelGasSensor.h"
#include "Adafruit_BME680.h"
#define SEALEVELPRESSURE_HPA (1022.6) //(1013.25)
float correzione_temperatura = 2.08;
float correzione_pressione = 12.5;
Adafruit_BME680 bme;
float temperature;
float pressure;
float humidity;
float gas_resistance;
float readAltitude;
//------------------------------------------------------------------------ SENSOR BME 680 //
//--------------------------------------------------------------------------- LCD DISPLAY //
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
int x = 0;
void setup() {
//--------------------------------------------------------------------------- LCD DISPLAY //
Wire.begin((uint8_t)I2C_DEV_ADDR); // Inizializzazione I2c
Wire.onReceive(receiveEvent);
Serial.begin(115200); // Inizializzazione Seriale
// ---- S E T U P - LCD ----//
lcd.backlight(); // // Backlight ON LCD
lcd.begin(20, 4); // // Inizializzazione Display LCD 20x4
// ---- S E T U P - LCD ----//
// ---- S E T U P - BME 680 ----//
if (!bme.begin()) {
Serial.println(F("Could not find a valid BME680 sensor, check wiring!"));
//while (1);
}
// Set up oversampling and filter initialization
bme.setTemperatureOversampling(BME680_OS_8X);
bme.setHumidityOversampling(BME680_OS_2X);
bme.setPressureOversampling(BME680_OS_4X);
bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
bme.setGasHeater(320, 150); // 320*C for 150 ms
// ---- S E T U P - BME 680 ----//
}
void loop() {
BME_680(); // aggiorna valori dei Sensor
delay(100);
Serial.print("x nel loop ");
Serial.println(x);
lcd.setCursor(0, 0);
lcd.print(x);
}
void receiveEvent(int howMany) {
x = Wire.read();
Serial.print("x nella ricezione evento ");
Serial.println(x);
}
//------------------------------------------------------------------------ SENSOR BME 680 //
void BME_680() {
if (!bme.performReading()) {
Serial.println("Failed to perform reading :(");
return;
}
temperature = bme.temperature - correzione_temperatura; // fattore di correzione
pressure = (bme.pressure / 100.0) + correzione_pressione;
humidity = bme.humidity;
gas_resistance = bme.gas_resistance / 1000.0;
readAltitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
// Obtain measurement results from BME680. Note that this operation isn't
// instantaneous even if milli() >= endTime due to I2C/SPI latency.
if (!bme.endReading()) {
Serial.println(F("Failed to complete reading :("));
return;
}
}