adafruit / Adafruit_SSD1306

Arduino library for SSD1306 monochrome 128x64 and 128x32 OLEDs
http://www.adafruit.com/category/63_98
Other
1.78k stars 976 forks source link

Problem with this lib and LoRa #229

Open Baptou88 opened 2 years ago

Baptou88 commented 2 years ago

Hello Everyone !

I just noticed a problem with this library and some libraries for the use of an ssd1306 and I would like to understand where this problem comes from and how it is possible to fix it

here is my situation:

At this point all is Ok my project work correctly

However when I want to use the screen through these libs (Adafruit_SSD1306 or this one ) I'have an error on The Serial Monitor [E][esp32-hal-i2c.c:1434] i2cCheckLineState(): Bus Invalid State, TwoWire() Can't init sda=1, scl=1 which occurs just after passing the function 'onTxDone'


#include <Arduino.h>
 #include <SPI.h>              // include libraries
 #include <LoRa.h>
 // #include <Adafruit_GFX.h>
// #include <Adafruit_SSD1306.h>
#include <SSD1306Wire.h>
#include <Wire.h>

const long frequency = 868E6;  // LoRa Frequency
const int csPin = 10;          // LoRa radio chip select
const int resetPin = 9;        // LoRa radio reset
const int irqPin = 2;          // change for your board; must be a hardware interrupt pin
#define SCREEN_ADDRESS 0x3C
//Adafruit_SSD1306 display(128  , 64, &Wire1, RST_OLED);
//Adafruit_SSD1306 display(4);
SSD1306Wire display(0x3c,SDA_OLED,SCL_OLED,GEOMETRY_128_64);
void onReceive(int packetSize){
  Serial.println("I've receive a packet");
}
void onTxDone(){
  Serial.println("txDone " + String( millis()));
  LoRa.receive();
}
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
//  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c)) { //SSD1306_EXTERNALVCC
//     Serial.println(F("SSD1306 allocation failed"));
//     for(;;); // Don't proceed, loop forever
//   }
    pinMode(16, OUTPUT);
    digitalWrite(16, HIGH);
    delay(10);
    if (!display.init())
    {
    Serial.println("Error init display");
    } 
    display.drawCircle(10,10,5);
    display.display();
    SPI.begin(SCK,MISO,MOSI,SS);
    LoRa.setPins(18,14,26);
    pinMode(25,OUTPUT);
    while (!LoRa.begin(frequency)) {
        Serial.println("Starting LoRa failed!");
        delay(500);
    }
    Serial.println("Lora ok");
    LoRa.onReceive(onReceive);
    LoRa.onTxDone(onTxDone);
    LoRa.receive();
    delay(1000);
}
void loop() {
  // put your main code here, to run repeatedly:
  // display.clearDisplay();
  // display.setCursor(10,10);
  // display.println("Bonjour ");
  // display.drawCircle(20,20,10,SSD1306_WHITE);
  static int test = 0;
  display.clear();
  if (test > 128)
  {
    test = 0;
  }
  test++;
  display.setPixel(test,10);
  display.display();
  static unsigned long lastsend =0;
  if (millis()-lastsend > 5000) //send packet every 5sec
  {
    lastsend = millis();
    LoRa.beginPacket();
    LoRa.println("bonjour");
    digitalWrite(25,HIGH);
    LoRa.endPacket(true);
    //LoRa.receive();
    Serial.println(millis());
    digitalWrite(25,LOW);
  }
}

I hope I have been understandable enough

https://github.com/sandeepmistry/arduino-LoRa/issues/536#issue-1068603182