Problem initializing LCD

I’m struggling with a issue here… I made a remote control with LCD Display. Link !

I noticed that the LCD doesn’t always initialize.

// NRF24L01 Remote control - Last update: AndreasVan 2015-03-27 Version 1.56
// NRF24L01 connected to Arduino Uno
// Transmit analog values from joystick to the receiver using RF24 library
// Receive 2 floats (current from the motors) from Explorer Controller Board

// LiquidCrystal
// LCD RS pin to digital pin 0 
// LCD Enable pin to digital pin 1
// LCD Backlight pin 3
// LCD D4 pin to digital pin 4
// LCD D5 pin to digital pin 5
// LCD D6 pin to digital pin 6
// LCD D7 pin to digital pin 7
// LCD R/W pin to ground

// 1 - GND
// 2 - VCC 3.3V !!! NOT 5V
// 3 - CE to Arduino pin 9
// 4 - CSN to Arduino pin 10
// 5 - SCK to Arduino pin 13
// 6 - MOSI to Arduino pin 11
// 7 - MISO to Arduino pin 12
// 8 - UNUSED
   
// Default Button Pins: 
// Up - pin 2
// Right - pin 3
// Down - pin 4
// Left - pin 5
// - 
// Analog Joystick module
// GND to Arduino GND
// VCC to Arduino +5V
// X Pot to Arduino A0
// Y Pot to Arduino A1

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Wire.h>
#include <Bounce2.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR    0x27  // Define I2C Address 
#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7

int n = 1;
LiquidCrystal_I2C	lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
RF24 radio(9,10);

const uint64_t pipes[2] = { 
  0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

int joystick[7];
float current[4];
int upbut = 2;
int rightbut = 3;
int downbut = 4;
int leftbut = 5;

const int z = 2;
int roverState = LOW;         // the current state of the output pin

Bounce bouncer = Bounce();

long previousMillis = 0;
long interval = 25;

void setup(){
  delay(600);                  // delay for display !
  pinMode(z, INPUT);           //declare pinMode for all buttons and initial state
  pinMode(upbut,INPUT);
  digitalWrite(upbut,LOW);
  pinMode(rightbut,INPUT);
  digitalWrite(upbut,LOW);
  pinMode(downbut,INPUT);
  digitalWrite(downbut,LOW);
  pinMode(leftbut,INPUT);
  digitalWrite(leftbut,LOW);  //end pinMode and digitalWrite
  radio.begin();
  radio.openWritingPipe(pipes[0]);
  radio.openReadingPipe(1,pipes[1]);
  radio.startListening();
  lcd.begin (20,4);
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home ();                  
  lcd.clear();
  lcd.setCursor(0, 1);
  lcd.print("   Startup Remote ");
  lcd.setCursor(0, 2);
  lcd.print("    Version 1.56  ");
  delay(1500);
  lcd.clear();
  lcd.print(" Rover 5 active  ");
  lcd.setCursor(1,3);
  lcd.print("M1=");
  lcd.setCursor(9,3);
  lcd.print("M2=");
 
}
void loop(){
  joystick[0] = analogRead(A1);
  joystick[1] = analogRead(A0);
  joystick[2] = roverState;
  joystick[3] = digitalRead(upbut);
  joystick[4] = digitalRead(rightbut);
  joystick[5] = digitalRead(downbut);
  joystick[6] = digitalRead(leftbut);
  
  lcd.setCursor(1,2);
  lcd.print("X=");
  if(joystick[0]<1000) { lcd.print("0");}
  lcd.print(joystick[0]);
  lcd.setCursor(9,2); 
  lcd.print("Y=");
  if(joystick[1]<1000) { lcd.print("0");}
  lcd.print(joystick[1]);
  lcd.setCursor(17,0); 
  lcd.print("U=");
  lcd.print(joystick[3]);  
  lcd.setCursor(17,1); 
  lcd.print("D=");
  lcd.print(joystick[5]);  
  lcd.setCursor(17,3); 
  lcd.print("R=");
  lcd.print(joystick[4]); 
  lcd.setCursor(17,2); 
  lcd.print("L=");
  lcd.print(joystick[6]); 
  

  if ( bouncer.update() ) {
    if ( bouncer.read() == HIGH) {
      if ( roverState == LOW ) {
        roverState = HIGH;
      } 
      else {
        roverState = LOW;
      }
    }
  }

  if ( radio.available() )
  {
    unsigned long currentMillis = millis();

  if(currentMillis - previousMillis > interval) {
    previousMillis = currentMillis;   
    
    // Dump the payloads until we've gotten everything
    bool done = false;
    while (!done)
    {
      // Fetch the payload, and see if this was the last one.
      done = radio.read( &current, sizeof(current) );
    }
  }
    lcd.setCursor(3,3);
    lcd.print(current[0]);
    lcd.setCursor(12,3);
    lcd.print(current[2]);
    radio.stopListening();
    bool ok = radio.write( &joystick, sizeof(joystick) );
    radio.startListening();  

  }
}

Now I’m testing with delay, works fine so far but I wonder if it is the right Way

void setup(){
  delay(600);                  // delay for display !
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

Are you using the F Malpartida library? If you are, then you do not need the #include <LCD.h>. It will be called by <LiquidCrystal_I2C.h>. Perhaps calling it explicitly, and first, may be creating a problem with initialization.

#include <LCD.h>
Was from the display before ( 2x16 )

Removing doesn’t have any effect :frowning:

You didn't answer the question.

Don

floresta:
You didn’t answer the question.

Don

Sorry …
I am using the F Malpartida library!

There is already a delay in begin() of 100ms so no additional delay should be needed when running at 5v. How is everything being powered and at what voltage? I see comments in the code mentioning VCC being both 5v and 3.3v How are the batteries powering things and what voltage is the AVR and the other components using?

--- bill

bperrybap: There is already a delay in begin() of 100ms so no additional delay should be needed when running at 5v. How is everything being powered and at what voltage? I see comments in the code mentioning VCC being both 5v and 3.3v How are the batteries powering things and what voltage is the AVR and the other components using?

--- bill

Hello Bill Right now I'm using 6xAA batteries - Vin is between 7,2 and 9 V For the Joystick 5V for the NRF24 3,3 directly from UNO.

//Andreas

So the LCD and its backpack are running off of 5v?

Is 5v regulation happening, and where is it being done? I'm only asking because I can't see where the battery wires are connected.

Is there some kind of hidden connection under the board that connects the battery output to the uno Vin connector?

bperrybap:
So the LCD and its backpack are running off of 5v?

Is 5v regulation happening, and where is it being done?
I’m only asking because I can’t see where the battery wires are connected.

Is there some kind of hidden connection under the board that connects the battery output to
the uno Vin connector?

Battery wires are connected directly over the switch to the VIN connector !
On the 7-segment Display on the right you can see the battery voltage.

Still having this problem :(

Now I'm using a reset button when it happens ...

Klick !

AndreasVan: Battery wires are connected directly over the switch to the VIN connector ! On the 7-segment Display on the right you can see the battery voltage.

This description does not seem to match the photo in the first post I'm looking at. In that photo, the 7-segment LED is on the left and there is no visible power connecting into the VIN barrel power connector on the UNO board below the shield.

You have not fully described your setup and we can't see your setup including your wires to tell how things are connected. Without being able to see what you have and how you have everything wire up, we can't verify your wiring so things devolve down into guessing which is not fun and wastes time.

The only other thing that I could guess at would be: Are you using the required i2c pullup resistors on the i2c signals?

--- bill