LCD I2C does not reintialize if i do not press reset button

Hello, I am using an LCD I2C to measure some voltage and resistance, everything is fine but when I unplug and plug back in the Arduino nano the LCD is not showing up anything. I think some code rules before initializing the LCD thus it make it stuck.

the library I am usingI2C library


#include <Wire.h> //better communication of arduino with I2C devices
#include <LiquidCrystal_I2C.h> //better comunication with lcd
#include <time.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);//stating lcd adress and its characteristics

// Define the input pin for the pulse signal
#define pulse_ip A0
// Declare constants for the switch pin numbers
const int switch1Pin = 5;
const int switch2Pin = 6;

// Declare a variable to store the current function
int function = 0;


void setup() { 
  delay(2000);
   
  lcd.begin();
  lcd.clear(); 
 // Set the input pins for the switches to INPUT mode
  pinMode(switch1Pin, INPUT);
  pinMode(switch2Pin, INPUT);
  pinMode(pulse_ip, INPUT);

  // Enable the pull-up resistors for pins 5 and 6
  digitalWrite(switch1Pin, HIGH);
  digitalWrite(switch2Pin, HIGH);

  // Initialize the LCD and clear the screen

}

void loop() {
// Read the states of the switches
  int switch1State = digitalRead(switch1Pin);
  int switch2State = digitalRead(switch2Pin);

  // Check the state of the switches and switch between the functions accordingly
  if (switch1State == LOW && switch2State == HIGH) {
    // Switch to the next function
    function = (function + 1) % 4;
  } else if (switch1State == HIGH && switch2State == LOW) {
    // Switch to the previous function
    function = (function + 3) % 4;
  }

  // Perform the current function
  performCurrentFunction();


}


Please post your code as described in the forum guide. Never post images of code, or serial Monitor output. Always post them by copying the text and pasting it into your post using code tags.

Also post your schematic, and links to the components you are using. Not all i2c backpacks are the same.

Thanks for correcting your post!

I use some generic components, I do not think it is their fault since everything seems to work as long as the single problem I encounter is the one described

Please post your complete code! Some if it is missing.

The relevant part of the code is posted.

If you knew what the relevant part of the code was, then you would not be asking questions on this forum. Please post all your code.

It also stops us trying your code to see if we can find where it is deviating from your expectations.

There is an approximately 50% probability you are wrong about that.

I don't know which LCD library your are really using.
Go into the examples of your LCD I2C library and check the "Hello World" example.

If it does the initialization in setup() with

lcd.init();

use also lcd.init() - not lcd.begin()

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