arduino-libraries / LiquidCrystal

Liquid Crystal Library for Arduino
http://arduino.cc/
246 stars 169 forks source link

LiquidCrystal causing ESP32-S2-Wrover-I to crash. #41

Open ammartahircheema opened 3 years ago

ammartahircheema commented 3 years ago

ESP32-s2 is crashing on LCD initialization. Code is 'Hello World' from examples.

Debug Logs is as follow.

ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0x10 (RTCWDT_RTC_RST),boot:0xb (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3ffe6100,len:0x8
load:0x3ffe6108,len:0x620
load:0x4004c000,len:0xa38
load:0x40050000,len:0x2848
entry 0x4004c190
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 8;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis() / 1000);
}
ammartahircheema commented 3 years ago

Update. Crash only occurs when I initialize LCD on global scope. "LiquidCrystal lcd(7, 6, 5, 4, 3, 8);" keeping this statement inside a function somehow resolves this issue. but i need lcd variable accessible in both setup and loop function...

proboscide99 commented 3 years ago

I'm having the same issue on a WROOM after updating the esp32 core to current version. Looking at the library file, I see that the constructor calls 'begin(16,1)'.

Calling 'begin(16,1)' at the end of the constructor leads to an endless delay because -it seems that- the 'delayMicroseconds()' function does not work yet at that point of the initialization. For some reason, it used to work with an older core (V3.3).

The program gets halted even before being able to output anything on the Serial.

Commenting out the 'begin(16,1)' call from the 'LiquidCrystal::init' function in 'LiquidCrystal.cpp' and placing it in the sketch (where it should be already, with proper display size) solves the issue, because the 'delayMicroseconds()' function will work.

Alessandro, Italy

per1234 commented 2 years ago

The problem with the constructor was previously reported at https://github.com/arduino-libraries/LiquidCrystal/issues/11

https://github.com/arduino-libraries/LiquidCrystal/issues/11 is odd in that it was originally a pull request https://github.com/arduino/Arduino/pull/87, but was somehow converted to an issue during the transfer of the library from its original home bundled with the Arduino IDE repository to this dedicated repository. The proposed changes are in this branch: https://github.com/arduino-libraries/LiquidCrystal/tree/pr_87 with the constructor fix in this commit: https://github.com/arduino/Arduino/pull/87/commits/f82ec65a0d6e22f39266e91b85cb615df0780b3f