TTGO LoRa32 ESP32 SX1276 OLED AND ESP-WROOM-32 I2c Issues.

steinerrw
Posts: 4
Joined: Wed Dec 27, 2023 1:16 pm

TTGO LoRa32 ESP32 SX1276 OLED AND ESP-WROOM-32 I2c Issues.

Postby steinerrw » Fri Jan 12, 2024 10:22 pm

After days of trying to test a bme680 I2C sensor with my TTGO LoRa32 SX-1276 OLED board without success...
I tried a couple of different scenarios.
1.) The above test...FAILED.
2.) The LoRa board and a DHT11...it worked.
3.) ESP-WROOM 32 and the DHT11, it worked.
4.) ESP-WROOM 32 and a bme680 using I2c pins, it worked.
Tests 1 & 4 used the same code.
First it all the code works. I can send and receive messages between two LoRa32 boards,
I can connect the bme680 and run the test sketch with serial output OK.
Without changing any hardware, pins etc. I load the lora code with the bme added to it and it loads BUT it fails the bme read.

Code: Select all

#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"

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

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

//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 915E6

//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

//packet counter
int counter = 0;

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

#define I2CSDA 21
#define I2CSCL 13
#define SEALEVELPRESSURE_HPA (1013.25)
TwoWire I2CPin = TwoWire(0);
Adafruit_BME680 bme; // I2C
float temperature;
float humidity;
float pressure;
bool status1;

String LoRaMessage = "";

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

  //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 ");
  display.display();
  
  //SPI LoRa pins
  SPI.begin(SCK, MISO, MOSI, SS);
  //setup LoRa transceiver module
  LoRa.setPins(SS, RST, DIO0);
  
  if (!LoRa.begin(BAND)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }  bool status;

  display.setCursor(0,10);
  display.print("LoRa Initializing OK!");
  display.display();
  delay(2000);

  I2CPin.begin(I2CSDA, I2CSCL, 100000); 
  bool status1 = bme.begin(0x77, &I2CPin);  
  if (!status1) {
    Serial.println("[b]Could not find a valid BME280_1 sensor, check wiring!"[/b]);
  } else {
    // 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
  }
}

void loop() { 
  if (!bme.performReading()) {
    LoRaMessage = String("BME680 Read Failed: ") + String(counter);
    //Send LoRa packet to receiver
    LoRa.beginPacket();
    LoRa.print(LoRaMessage);
    LoRa.endPacket();
  
    display.clearDisplay();
    display.setCursor(0,0);
    display.println("LORA SENDER");
    display.setCursor(0,20);
    display.setTextSize(1);
    display.print("LoRa packet sent.");
    display.setCursor(0,30);
    display.print("Counter:");
    display.setCursor(50,30);
    display.print(counter);      
    display.display();
  } else {
    temperature = bme.temperature;
    humidity    = bme.humidity;
    pressure    = bme.pressure/100.00;
    LoRaMessage = String(temperature) + "* " + String(humidity) + "% " +String(pressure) + "^ " + String(counter);
    //Send LoRa packet to receiver
    LoRa.beginPacket();
    LoRa.print(LoRaMessage);
    LoRa.endPacket();
  
    display.clearDisplay();
    display.setCursor(0,0);
    display.println("LORA SENDER");
    display.setCursor(0,20);
    display.setTextSize(1);
    display.print("LoRa packet sent.");
    display.setCursor(0,30);
    display.print("Counter:");
    display.setCursor(50,30);
    display.print(counter);      
    display.display();
  }
  counter++;
  delay(10000);
}
Serial output...
rst:0x1 (POWERON_RESET),boot:0x17 (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:0x3fff0030,len:1184
load:0x40078000,len:13260
load:0x40080400,len:3028
entry 0x400805e4
Could not find a valid BME280_1 sensor, check wiring!

I have read many posts on the LoRa32 and I2C and would like to chain multiple I2C sensors to do some tests but I need to get one working first....
So why does the ESP-WROOM32 work and the TTGO LoRa32 does not...
I know they are two different boards BUT they are both based on the same technology.

Any suggestions...Thanks

MicroController
Posts: 1734
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: TTGO LoRa32 ESP32 SX1276 OLED AND ESP-WROOM-32 I2c Issues.

Postby MicroController » Sat Jan 13, 2024 9:16 am

Note that the OLED uses I2C too. Make sure that the OLED and the bme either use the same pins and I2C controller ("Wire") or they use different pins and different I2C controllers, i.e. try "TwoWire I2CPin = TwoWire(1)" for example..

steinerrw
Posts: 4
Joined: Wed Dec 27, 2023 1:16 pm

Re: TTGO LoRa32 ESP32 SX1276 OLED AND ESP-WROOM-32 I2c Issues.

Postby steinerrw » Sat Jan 13, 2024 2:58 pm

I have tried that, same results. I am aware of the boards I2C settings for the OLED and LoRa...
And after trying many more times I came back to your post and read it more carefully and initially, I would have thought that they needed two separate I2C busses but in re-reading your comment ...as either the same or different...
I changed to wiring and code to use the OLED I2C and it works...thanks :D

Who is online

Users browsing this forum: jesper and 101 guests