A sensor stops working when using Heltec LoRa V32

When using LoRa, I have tried to program 2 sensors, which must send the data to the receiver, however when sending the data the sensors do not work.
The sensors used are: BME280 and CCS811

This code is in which when sending the data, the sensors stop working:

//Libraries for LoRa
#include <SPI.h>
#include <LoRa.h>

//Libraries for OLED Display
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

//Libraries for BME280
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

//Libraries for CCS811
#include "Adafruit_CCS811.h"
Adafruit_CCS811 ccs;

//define the pins used by the LoRa transceiver module
#define SCK 5
#define MISO 19
#define MOSI 27
#define SS 18
#define RST 14
#define DIO0 26

//433E6 for Asia
//866E6 for Europe
//915E6 for North America
#define BAND 866E6

//OLED pins
#define OLED_SDA 4
#define OLED_SCL 15
#define OLED_RST 16
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

TwoWire I2Cone = TwoWire(1);
Adafruit_BME280 bme;

//packet counter
int readingID = 0;

int counter = 0;
String LoRaMessage = "";

float temperature = 0;
float humidity = 0;
float pressure = 0;
float co2 = 0;

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RST);

//Initialize OLED display
void startOLED() {
  //reset OLED display via software
  pinMode(OLED_RST, OUTPUT);
  digitalWrite(OLED_RST, LOW);
  delay(20);
  digitalWrite(OLED_RST, HIGH);

  //initialize OLED
  Wire.begin(OLED_SDA, OLED_SCL);
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)) { // Address 0x3C for 128x32
    Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Don't proceed, loop forever
  }
  display.clearDisplay();
  display.setTextColor(WHITE);
  display.setTextSize(1);
  display.setCursor(0, 0);
  display.print("LORA SENDER");
}

//Initialize LoRa module
void startLoRA() {
  //SPI LoRa pins
  SPI.begin(SCK, MISO, MOSI, SS);
  //setup LoRa transceiver module
  LoRa.setPins(SS, RST, DIO0);

  while (!LoRa.begin(BAND) && counter < 10) {
    Serial.print(".");
    counter++;
    delay(500);
  }
  if (counter == 10) {
    // Increment readingID on every new reading
    readingID++;
    Serial.println("Starting LoRa failed!");
  }
  Serial.println("LoRa Initialization OK!");
  display.setCursor(0, 10);
  display.clearDisplay();
  display.print("LoRa Initializing OK!");
  display.display();
  delay(2000);
}

void startSensors() {

  I2Cone.begin(SDA, SCL, 100000);
  bool status1 = bme.begin(0x76, &I2Cone);
  if (!status1) {
    Serial.println("Could not find a valid BME280_1 sensor, check wiring!");
    while (1);
  }

  Serial.println("CO2, TVOC");
  if (!ccs.begin()) {                 // Intentar inicializar el sensor
    Serial.println("¡No se ha podido inicializar el sensor! Por favor, comprueba el cableado.");
    while (1);
  }
  while (!ccs.available());           // Esperar a que el sensor esté preparado

}
void getReadings() {

  co2 = ccs.geteCO2();    // Obtener y enviar el nivel del CO2 por el puerto serie
  temperature = bme.readTemperature();
  humidity = bme.readHumidity();
  pressure = bme.readPressure() / 100.0F;
}

void sendReadings() {
  LoRaMessage = String(readingID) + "/" + String(temperature) + "&" + String(humidity) + "#" + String(pressure);
  //Send LoRa packet to receiver
  LoRa.beginPacket();
  LoRa.print(LoRaMessage);
  LoRa.endPacket();

  display.clearDisplay();
  display.setCursor(0, 0);
  display.setTextSize(1);
  display.print("CO2:");
  display.setCursor(72, 0);
  display.print(co2);
  display.setCursor(0, 20);
  display.print("Temperature:");
  display.setCursor(72, 20);
  display.print(temperature);
  display.setCursor(0, 30);
  display.print("Humidity:");
  display.setCursor(54, 30);
  display.print(humidity);
  display.setCursor(0, 40);
  display.print("Pressure:");
  display.setCursor(54, 40);
  display.print(pressure);
  display.setCursor(0, 50);
  display.print("Reading ID:");
  display.setCursor(66, 50);
  display.print(readingID);
  display.display();
  Serial.print("Sending packet: ");
  Serial.println(readingID);
  readingID++;
}

void setup() {
  //initialize Serial Monitor
  Serial.begin(115200);
  startOLED();
  startSensors();
  startLoRA();
  delay(2000);
}
void loop() {
  Serial.print("MIERDA");
  if (ccs.available()) {              // Si el sensor está disponible
    if (!ccs.readData()) {
      getReadings();
      sendReadings();
    }
  }
  delay(1000);
}

This code is without sending data, in which the sensors do work:

//Libraries for BME280
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#include "Adafruit_CCS811.h"
Adafruit_CCS811 ccs;
TwoWire I2Cone = TwoWire(1);
Adafruit_BME280 bme;

float temperature = 0;
float humidity = 0;
float pressure = 0;
float co2 = 0;

void setup() {
  Serial.begin(115200);

  I2Cone.begin(SDA, SCL, 100000);
  bool status1 = bme.begin(0x76, &I2Cone);
  if (!status1) {
    Serial.println("Could not find a valid BME280_1 sensor, check wiring!");
    while (1);
  }

  Serial.println("CO2, TVOC");
  if (!ccs.begin()) {                 // Intentar inicializar el sensor
    Serial.println("¡No se ha podido inicializar el sensor! Por favor, comprueba el cableado.");
    while (1);
  }
  while (!ccs.available());           // Esperar a que el sensor esté preparado

}

void loop() {


  if (ccs.available()) {              // Si el sensor está disponible
    if (!ccs.readData()) {            // Cuando haya datos
      co2 = ccs.geteCO2();    // Obtener y enviar el nivel del CO2 por el puerto serie
      temperature = bme.readTemperature();
      humidity = bme.readHumidity();
      pressure = bme.readPressure() / 100.0F;

      Serial.print("CO2:");
      Serial.println(co2);
      Serial.print("Temp:");
      Serial.println(temperature);
      Serial.print("Hum:");
      Serial.println(humidity);
      Serial.print("Press:");
      Serial.println(pressure);
    }
    else {
      Serial.println("ERROR!");       // Cuando ocurra un error
      while (1);                      // El dispositivo deja de funcionar
    }
  }
  delay(2000);                         // Hacer la medida cada 2 segundos(2000ms)
}

Here the circuit:

Swap the two I2C interfaces!

You use Wire1 on the standard I2C pins for the sensor and Wire on non-standard I2C pins for the OLED. As you provide the I2C object to the constructor of the OLED object you can use Wire1 there and use Wire for the sensors. This is necessary because the CCS811 library always uses the Wire interface object, you cannot provide another instance.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.