WiFi LoRa 32 (V3) I2C SDA/SCL

Hello, i have the same kind of problem. I tried this :
/***************************************************************************

This is a library for the BMP280 humidity, temperature & pressure sensor

Designed specifically to work with the Adafruit BMP280 Breakout

----> http://www.adafruit.com/products/2651

These sensors use I2C or SPI to communicate, 2 or 4 pins are required

to interface.

Adafruit invests time and resources providing this open source code,

please support Adafruit andopen-source hardware by purchasing products

from Adafruit!

Written by Limor Fried & Kevin Townsend for Adafruit Industries.

BSD license, all text above must be included in any redistribution

***************************************************************************/

#include <Wire.h>

#include <SPI.h>

#include <Adafruit_BMP280.h>

#include ā€œSSD1306Wire.hā€

#define BMP_SCK (13)

#define BMP_MISO (12)

#define BMP_MOSI (11)

#define BMP_CS (10)

SSD1306Wire display(0x3c, SDA_OLED, SCL_OLED);

TwoWire I2Ctwo = TwoWire(1);

Adafruit_BMP280 bmp(&I2Ctwo); // I2C

//Adafruit_BMP280 bmp(BMP_CS); // hardware SPI

//Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK);

void setup() {

Serial.begin(115200);

display.setFont(ArialMT_Plain_10);

I2Ctwo.begin(SDA, SCL);

while ( !Serial ) delay(100); // wait for native usb

Serial.println(F(ā€œBMP280 testā€));

unsigned status;

status = bmp.begin(BMP280_ADDRESS_ALT, BMP280_CHIPID);

//status = bmp.begin();

if (!status) {

Serial.println(F("Could not find a valid BMP280 sensor, check wiring or "

                  "try a different address!"));

Serial.print("SensorID was: 0x"); Serial.println(bmp.sensorID(),16);

Serial.print("        ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");

Serial.print("   ID of 0x56-0x58 represents a BMP 280,\n");

Serial.print("        ID of 0x60 represents a BME 280.\n");

Serial.print("        ID of 0x61 represents a BME 680.\n");

while (1) delay(10);

}

/* Default settings from datasheet. */

bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */

              Adafruit_BMP280::SAMPLING_X2,     /* Temp. oversampling */

              Adafruit_BMP280::SAMPLING_X16,    /* Pressure oversampling */

              Adafruit_BMP280::FILTER_X16,      /* Filtering. */

              Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */

}

void loop() {

display.setTextAlignment(TEXT_ALIGN_LEFT);

display.drawString(0, 10, "Left aligned (0,10)");

Serial.print(F("Temperature = "));

Serial.print(bmp.readTemperature());

Serial.println(" *C");

Serial.print(F("Pressure = "));

Serial.print(bmp.readPressure()/100);

Serial.println(" hPa");

Serial.print(F("Approx altitude = "));

Serial.print(bmp.readAltitude(1013.25)); /* Adjusted to local forecast! */

Serial.println(" m");

Serial.println();

delay(2000);

}

It compiles but when i try to upload it i have a kernel panic.
Any idea ?

You should be able to strategically comment out a few of those lines of code to identify the offending line. But having said that, I uploaded your code and all that showed in the Serial Monitor was your message ā€œCould not find a valid BMP280 sensorā€¦etc.ā€ (which was no surprise because there was nothing connected to my Dev-Board). So maybe youā€™ve misconfigured your hardware in some way.

Kernel panicā€¦ bootloopā€¦ old version esptool? See earlier topics from past few days, itā€™s mentioned somewhere. May be the solution.

Itā€™s not an old esptool version. With the same sketch without any mention of SSD1306Wire (i comment all lines related) it works fineā€¦

hi, could u share the code about ur solution
Iā€™m very frustrating now on thisā€¦
I had tried the solution u said, but still not working
I just want to display the time on the screen using ds3231, the arduino serial monitor can display the time but my oled on wifi lora 32 V3 cant display

Anyone have the code for DS3231 with Heltec wifi lora 32 V3
I had tried many solution but it still no working

It sounds like you are able to configure the DS3231 and display the time in the IDE Serial Monitor. So, have you tried the Examples > Heltec-Example > OLED > Simple Demo to test the OLED display? If you can do both of those, itā€™s not clear why you shouldnā€™t be able to simply combine the code from those two exercises, taking into consideration earlier posts in this thread in relation to operating the second I2C bus.

If you can successfully read the DS3231 and run the OLED Demo(s) independently, and you are still having trouble, if you post your code, someone who has not actually coded this particular configuration may still be able to help pinpoint your problem.

Yo estoy intentando conectar un sensor AHT10, lo he conectado al gpio 6 y 7 pero aĆŗn asĆ­ no me funciona:

#include <Wire.h>

#include <Adafruit_AHTX0.h>

#include ā€œHT_SSD1306Wire.hā€

// ConfiguraciĆ³n de la pantalla OLED en el bus principal IĀ²C

static SSD1306Wire display(0x3C, 500000, SDA_OLED, SCL_OLED, GEOMETRY_128_64, RST_OLED);

uint8_t sda_aht10 = 6; // SDA para AHT10

uint8_t scl_aht10 = 7; // SCL para AHT10

float decimal = 11.22;

// Instancia del sensor AHT10

Adafruit_AHTX0 aht10;

void VextON(void) {

pinMode(Vext, OUTPUT);

digitalWrite(Vext, LOW);

}

void VextOFF(void) {

pinMode(Vext, OUTPUT);

digitalWrite(Vext, HIGH);

}

void setup() {

Serial.begin(115200);

VextON();

delay(100);

// Inicializar el bus IĀ²C principal para la OLED

Wire.begin();

// Inicializar el segundo bus IĀ²C en GPIO6 (SDA) y GPIO7 (SCL) para AHT10 usando Wire1

Wire1.begin(sda_aht10, scl_aht10, 400000);

// Inicializar pantalla OLED

display.init();

display.clear();

display.setFont(ArialMT_Plain_10);

display.display();

// Inicializar el sensor AHT10 en el bus IĀ²C secundario

if (!aht10.begin(&Wire1)) {

Serial.println(F("AHT10 not connected or failed to load calibration coefficient"));

while (1) { delay(5000); } // Bucle infinito si falla la conexiĆ³n

}

Serial.println(F(ā€œAHT10 OKā€));

}

void loop() {

Serial.println(F(ā€œReading AHT10 sensorā€¦ā€));

display.drawString(0, 0, ā€œDecimal:ā€);

display.drawString(50, 0, String(decimal, 2));

sensors_event_t humidity, temp;

aht10.getEvent(&humidity, &temp);

Serial.print(F("Temperature: "));

Serial.print(temp.temperature);

Serial.println(F(" Ā°C"));

Serial.print(F("Humidityā€¦: "));

Serial.print(humidity.relative_humidity);

Serial.println(F(" %"));

display.clear();

display.setTextAlignment(TEXT_ALIGN_LEFT);

display.drawString(0, 0, ā€œTemperature:ā€);

display.drawString(50, 0, String(temp.temperature, 2));

display.drawString(0, 10, ā€œHumidity:ā€);

display.drawString(50, 10, String(humidity.relative_humidity, 2));

display.display();

delay(1000);

}

Biblioteca del AHT10 de adafruit: https://github.com/adafruit/Adafruit_AHTX0/tree/master

First up, when you include code in a post, first type three ā€˜grave accentā€™ or ā€˜backtickā€™ charactersā€”thatā€™s this character `, itā€™s the top left key on the main part of the keyboard, the one to the left of the ā€œ1ā€ keyā€”press the return key, paste your code, press the return key again, then type three more ā€˜grave accentā€™ or ā€˜backtickā€™ characters:

```
your code here
```

Here is a link to a more detailed explanation if you need it. If you do that, your code will appear in a window, nicely formattedā€”assuming, of course, that it was nicely formatted in the first placeā€”and coloured, with a scroll bar like this:

/*
 * HelTec Automation(TM) WIFI_LoRa_32 factory test code, witch includ
 * follow functions:
 * 
 * - Basic OLED function test;
 * 
 * - Basic serial port test(in baud rate 115200);
 * 
 * - LED blink test;
 * 
 * - WIFI connect and scan test;
 * 
 * - LoRa Ping-Pong test (DIO0 -- GPIO26 interrup check the new incoming messages);
 * 
 * - Timer test and some other Arduino basic functions.
 *
 * by Aaron.Lee from HelTec AutoMation, ChengDu, China
 * ęˆéƒ½ęƒ åˆ©ē‰¹č‡ŖåŠØ化ē§‘ęŠ€ęœ‰é™å…¬åø
 * https://heltec.org
 *
 * this project also realess in GitHub:
 * https://github.com/HelTecAutomation/Heltec_ESP32
*/

#include "Arduino.h"
#include "WiFi.h"
#include "images.h"
#include "LoRaWan_APP.h"
#include <Wire.h>  
#include "HT_SSD1306Wire.h"
/********************************* lora  *********************************************/
#define RF_FREQUENCY                                868000000 // Hz

#define TX_OUTPUT_POWER                             10        // dBm

#define LORA_BANDWIDTH                              0         // [0: 125 kHz,
                                                              //  1: 250 kHz,
                                                              //  2: 500 kHz,
                                                              //  3: Reserved]
#define LORA_SPREADING_FACTOR                       7         // [SF7..SF12]
#define LORA_CODINGRATE                             1         // [1: 4/5,
                                                              //  2: 4/6,
                                                              //  3: 4/7,
                                                              //  4: 4/8]
#define LORA_PREAMBLE_LENGTH                        8         // Same for Tx and Rx
#define LORA_SYMBOL_TIMEOUT                         0         // Symbols
#define LORA_FIX_LENGTH_PAYLOAD_ON                  false
#define LORA_IQ_INVERSION_ON                        false


#define RX_TIMEOUT_VALUE                            1000
#define BUFFER_SIZE                                 30 // Define the payload size here

char txpacket[BUFFER_SIZE];
char rxpacket[BUFFER_SIZE];

static RadioEvents_t RadioEvents;
void OnTxDone( void );
void OnTxTimeout( void );
void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr );

typedef enum
{
    LOWPOWER,
    STATE_RX,
    STATE_TX
}States_t;

int16_t txNumber;
int16_t rxNumber;
States_t state;
bool sleepMode = false;
int16_t Rssi,rxSize;

String rssi = "RSSI --";
String packSize = "--";
String packet;
String send_num;
String show_lora = "lora data show";

unsigned int counter = 0;
bool receiveflag = false; // software flag for LoRa receiver, received data makes it true.
long lastSendTime = 0;        // last send time
int interval = 1000;          // interval between sends
uint64_t chipid;
int16_t RssiDetection = 0;


void OnTxDone( void )
{
	Serial.print("TX done......");
	state=STATE_RX;
}

void OnTxTimeout( void )
{
  Radio.Sleep( );
  Serial.print("TX Timeout......");
	state=STATE_TX;
}

etc.

As far as your code goes then, have you verified that the sensor is working, by itself, on wire1?

1 Like

This is a duplicated post and still no formatting!

You risk splitting the efforts of the volunteers helping you. Which topic do you want us to reply in to?

I have been able to get Wire1 setup (with the adafruit bme680) and can see serial debugging for both Wire (Heltec LoRa 32(v3) onboard temperature) and Wire1 using the following:

//create BME sensor
Adafruit_BME680 bme(&Wire1); // I2C on second Wire channel (Wire1)

//Define the I2C pins for Wire1
#define BME_SDA 42
#define BME_SCL 41

and then in void setup:

Wire.begin();

bool wireStatus = Wire1.begin(BME_SDA, BME_SCL);
bme.begin(0x77, &Wire1);

Serial.begin(115200); 

I didā€™t try other gpio pins for SDA and SCL, but I assume there may be other options too.

I have not been able to get the onboard OLED to initialize once the second I2C bus is active. I havce seen some references to this issue elsewhere, but have not attempted fixing it. For now, I simply have a dead OLED.

I mentioned in an earlier reply that I was able to get the Adafruit BME680 sensor to work over Wire1, which is true. The sketch code for that is here:

// Pause between sends in seconds, so this is every 15 minutes. (Delay will be
// longer if regulatory or TTN Fair Use Policy requires it.)
#define MINIMUM_DELAY 300 


#include <heltec_unofficial.h>
#include <LoRaWAN_ESP32.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"

LoRaWANNode* node;

//create BME sensor
Adafruit_BME680 bme(&Wire1); // I2C on second Wire channel (Wire1)

#define SEALEVELPRESSURE_HPA (1013.25)

//Define the I2C pins for Wire1
#define BME_SDA 42
#define BME_SCL 41

//Setup sequatial counting for data transmissions
RTC_DATA_ATTR uint8_t count = 0; //for LoRa transmissions
RTC_DATA_ATTR uint8_t trans = 0; //for serial debugging

void setup() {
 //Not sure about the ordering of the next few things, but this works. It starts the heltec board
 //along with serial debugging and the BME680 board
 heltec_setup();

 Wire.begin();

bool wireStatus = Wire1.begin(BME_SDA, BME_SCL);
bme.begin(0x77, &Wire1);

 Serial.begin(115200); 

//Debugging at 115200 baud for BME680
 if (!bme.begin()) {
    Serial.println("Could not find a valid BME680 sensor, check wiring!");
    while (1);
    }else{
      Serial.print("BME680 found");
      }
  
  // Set up oversampling and filter initialization for BME680
  bme.setTemperatureOversampling(BME680_OS_1X);
  bme.setHumidityOversampling(BME680_OS_2X);
  bme.setPressureOversampling(BME680_OS_16X);
  bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
  bme.setGasHeater(320, 150); // 320*C for 150 ms

 // Obtain directly after deep sleep
 // May or may not reflect room temperature, some correction needed 
  float temp = heltec_temperature();
  Serial.println();  
  Serial.println(F("-------------------------"));
  Serial.print("Consecutive Transmissions: ");
  Serial.print(trans++);
  Serial.println();
  Serial.printf("Heltec Temperature: %.1f Ā°C\n", temp);

 //create floats and nicknames for the BME680 values
  float bmet = bme.readTemperature();
  float bmeh = bme.readHumidity();
  float bmep = bme.readPressure();
  float bmea = bme.readAltitude(SEALEVELPRESSURE_HPA);
  float bmeg = bme.readGas();

 //Perform reading of BME680 sensor to make data available for transmision
  bme.performReading();

 //Print BME680 data to serial for debugging, math to get values into indicated units
  Serial.printf("BME Temperature: %.1f Ā°C\n", bmet);
  Serial.print("Pressure = ");
  Serial.print((bme.pressure) * 0.000010197162, 4);
  Serial.println(" atm");
  Serial.print("Humidity = ");
  Serial.print(bme.humidity);
  Serial.println(" %");
  Serial.print("Gas = ");
  Serial.print(bme.gas_resistance / 10000.0);
  Serial.println(" KOhms");
  Serial.print("Approx. Altitude = ");
  Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
  Serial.println(" m");
  Serial.println(F("-------------------------"));
 
 // initialize radio
  Serial.println("Radio init");
  int16_t state = radio.begin();
  if (state != RADIOLIB_ERR_NONE) {
    Serial.println("Radio did not initialize. We'll try again later.");
    goToSleep();
  }

  node = persist.manage(&radio);

  if (!node->isActivated()) {
    Serial.println("Could not join network. We'll try again later.");
    goToSleep();
  }

// If we're still here, it means we joined, and we can send something

// Manages uplink intervals to the TTN Fair Use Policy
  node->setDutyCycle(true, 1250);

//create LoRa data uplink structure and packet
  uint8_t uplinkData[7];
  uplinkData[0] = (count++); //sequantially adds one intiger to the value 'count' for each transmission, resets when RST button pushed
  uplinkData[1] = (temp * 4); //max value to multiply by and keep under cap of 256 for uint8_t value
  uplinkData[2] = (bmet * 5); //max value to multiply by and keep under cap of 256 for uint8_t value
  uplinkData[3] = (bmeh); //no math needed
  uplinkData[4] = (bmep * 0.0010197162); //converts to atm * 100 to keep two decimals
  uplinkData[5] = (bmea / 16.09); //converts to miles * 100 to keep decimals
  uplinkData[6] = (bmeg / 10000.0); //converts to kOhms

//define LoRa downlink size
  uint8_t downlinkData[256];
  size_t lenDown = sizeof(downlinkData);

//Send of the LoRa data and establish wait for downlink
  state = node->sendReceive(uplinkData, sizeof(uplinkData), 1, downlinkData, &lenDown);

  if(state == RADIOLIB_ERR_NONE) {
    Serial.println("Message sent, no downlink received.");
  } else if (state > 0) {
    Serial.println("Message sent, downlink received.");
  } else {
    Serial.printf("sendReceive returned error %d, we'll try again later.\n", state);
  }

  goToSleep();    // Does not return, program starts over next round

}

void loop() {
  // This is never called. There is no repetition: we always go back to
  // deep sleep one way or the other at the end of setup()
}

void goToSleep() {
  Serial.println("Going to deep sleep now");
  // allows recall of the session after deepsleep
  persist.saveSession(node);
  // Calculate minimum duty cycle delay (per FUP & law!)
  uint32_t interval = node->timeUntilUplink();
  // And then pick it or our MINIMUM_DELAY, whichever is greater
  uint32_t delayMs = max(interval, (uint32_t)MINIMUM_DELAY * 1000);
  Serial.printf("Next TX in %i s\n", delayMs/1000);
    Serial.println(F("*****-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*****"));
  Serial.println();
  delay(100);  // So message prints
  // and off to bed we go
  heltec_deep_sleep(delayMs/1000);
}

I have been trying to get this to also work with other Adafruit sensors such as the CCS811 and the VCNL4040, but I have not been able to get those devices to initialize over I2C. For example, I get ā€œCompilation error: no matching function for call to 'Adafruit_CCS811::Adafruit_CCS811(TwoWire*)ā€ when I use the same
Adafruit_BME680 bme(&Wire1);
line to name the device AND set it up on Wire1.

For the CCS811, I am not able to get past the serial debug of finding the sensor on I2C and here is what I have for the code:

// Pause between sends in seconds, so this is every 15 minutes. (Delay will be
// longer if regulatory or TTN Fair Use Policy requires it.)
#define MINIMUM_DELAY 300 


#include <heltec_unofficial.h>
#include <LoRaWAN_ESP32.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_CCS811.h"

LoRaWANNode* node;

//create CCS811 sensor and give it the nickname "ccs"
Adafruit_CCS811 ccs;

//Define the I2C pins for Wire1
#define SDA1 42
#define SCL1 41

//Setup sequatial counting for data transmissions
RTC_DATA_ATTR uint8_t count = 0; //for LoRa transmissions
RTC_DATA_ATTR uint8_t trans = 0; //for serial debugging

void setup() {

 //Let's try to start I2C along with serial debugging and the CCS811 board
heltec_setup();

Wire.begin();

bool wireStatus = Wire1.begin(SDA1, SCL1);

ccs.begin(0x5A, &Wire1);

Serial.begin(115200); 

// Wait until serial port is opened
  while (!Serial) { delay(1); }

  Serial.println("CCS811 test");

  if(!ccs.begin()){
    Serial.println("Failed to start sensor! Please check your wiring.");
    while(1);
  }

  // Wait for the sensor to be ready
  while(!ccs.available());

Any ideas about why this is not working whent he BME680 is working? Iā€™m guessing I just have a minor error somewhere, but I canā€™t find any references online that have helped. I can cofirm that the SDA1 and SCL1 pins are correct since they work for the BME680 and I can confirm that Wire1 works on this board and with the BME680 board on this specific Heltec board since I have already tested that sketch and it works.