LCD display does not display the right things

Hello, i’m making a arduino program for my year project. It’s my first time using an lcd display and I have a problem. When I make a simple program with just the lcd in it, everything works just fine, but when I add the part that ‘makes’ the project, weird characters appear on my lcd.

My simple code:
#code

#include <LiquidCrystal.h>

LiquidCrystal lcd( 1, 2, 4, 5, 6, 7); //RSP (RS), Enable (E), Register D4-D7

void setup() {
  lcd.begin(16, 2); //lcd 16*2 vakjes
}

void loop() {
  //schrijven van: Injectie: 1000ms op 1ste rij lcd scherm
  lcd.print("Injectie: ");
  lcd.print(1000);
  lcd.print("ms");
  delay(100);

  //schrijven van: Sluit: 2000ms op 2de rij lcd scherm
  lcd.setCursor(0, 1);
  lcd.print("Sluit:");
  lcd.print(2000);
  lcd.print("ms");
  delay(2000);

  //leegmaken lcd scherm
  lcd.clear();
  delay(500);
}

My program with everything in it:
#code

/*Change the injectiontiming for ethanol by setting 2 timers with 4 buttons*/

#include <LiquidCrystal.h>
#include <Bounce2.h>

#define UP1 10
#define DOWN1 11
#define UP2 12
#define DOWN2 13

Bounce debouncer1 = Bounce(); //UP1
Bounce debouncer2 = Bounce(); //DOWN1
Bounce debouncer3 = Bounce(); //UP2
Bounce debouncer4 = Bounce(); //DOWN2

int pinRelais = 8;

int delayInjectie = 0;
int delaySluit = 0;

LiquidCrystal lcd( 1, 2, 4, 5, 6, 7); //RSP (RS), Enable (E), Register D4-D7

void setup() {

  // eerste drukknop UP1
  pinMode(UP1, INPUT_PULLUP);
  debouncer1.attach(UP1);
  debouncer1.interval(5);

  // tweede drukknop DOWN1
  pinMode(DOWN1, INPUT_PULLUP);
  debouncer2.attach(DOWN1);
  debouncer2.interval(5);

  // derde drukknop UP2
  pinMode(UP2, INPUT_PULLUP);
  debouncer3.attach(UP2);
  debouncer3.interval(5);

  // vierde drukknop DOWN2
  pinMode(DOWN2, INPUT_PULLUP);
  debouncer4.attach(DOWN2);
  debouncer4.interval(5);

  pinMode(pinRelais, OUTPUT);

  Serial.begin(9600);

  lcd.begin(16,2);

}

void loop() {

  debouncer1.update();
  debouncer2.update();
  debouncer3.update();
  debouncer4.update();

  int value1 = debouncer1.read();
  int value2 = debouncer2.read();
  int value3 = debouncer3.read();
  int value4 = LOW;
  //debouncer4.read();

  if (value1 == HIGH) {
    delayInjectie += 250;
  }else if (value2 == HIGH) {
    delayInjectie -= 250;
  }

  if (value3 == HIGH){
    delaySluit += 250;
  } else if (value4 == HIGH){
    delaySluit -= 250;
  }
  
  Serial.print("delayInjectie =");
  Serial.println(delayInjectie);
  Serial.print("delaySluit =");
  Serial.println(delaySluit);
  Serial.print("value1 ");
  Serial.println(value1);
  Serial.print("value2 ");
  Serial.println(value2);
  Serial.print("value3 ");
  Serial.println(value3);
  Serial.print("value4 ");
  Serial.println(value4);

  lcd.clear();

  lcd.print("Injectie: ");
  lcd.print(delayInjectie);
  lcd.print("ms");

  lcd.setCursor(0, 1);
  lcd.print("Sluit:   ");
  lcd.print(delaySluit);
  lcd.print("ms");

    digitalWrite(pinRelais, HIGH);
  delay(delayInjectie);
  digitalWrite(pinRelais, LOW);
  delay(delaySluit);
}

Here is an image of the LCD display with wrong characters: https://drive.google.com/open?id=1uJ7MGqfQE96nqeAucq-jOMAf48oh-0DF
I’ve been searching for several hours but didn’t find it…

Google Drive is a poor place to post images - or indeed anything - for public viewing as it obfuscates the information.

Not sure what you mean by "wrong characters".

One appears to be a "degree" symbol - not sure where that comes from - and there is a question mark which may mean the "print" class is unable to interpret what is is given, as a number.

LiquidCrystal lcd( 1, 2, 4, 5, 6, 7); //RSP (RS), Enable (E), Register D4-D7

pins 1 & 2 are serial pins and should not be used while using Serial.print & LCD>

cherk:
LiquidCrystal lcd( 1, 2, 4, 5, 6, 7); //RSP (RS), Enable (E), Register D4-D7

pins 1 & 2 are serial pins and should not be used while using Serial.print & LCD>

Well spotted!

It's actually pins 0 and 1, but these definitely should not be used. :roll_eyes:

Interesting that pin 3 was already skipped over. Why?

thx! As I said, first time using lcd, watched a tutorial on youtube that used that pins, didnt think about it. just sticked with the same pins. But it works now. Thank you very much!

YouTube and "instructables".

Good material for thought - but it frequently does help to be smarter than the presenter. :roll_eyes:

Car crash videos tend to be my addiction. :grinning:

LCD displays need cursor control.
First rule: place everything that does not need to be refreshed in Setup, and all variable stuff in Loop. Also, use lcd.setCursor (row, column); before printing ONLY the value of your preferred parameter to display. Else wipe the line with 16 empty characters before printing something on it

What happens in your current (second) sketch is that the LCD continues printing on the display where it has stopped in the previous instruction. It concatenates and because of that partly overwrites previously
displayed stuff. The result is that you think it is gibberish. Nope! The LCD does exactly hat you instruct it to do - the right stuff!

here is some suggestion: inset this:
lcd setCursor (0,1);
lcd.print (" ");

in this part of yoru sketch: …

lcd.clear();

lcd.print("Injectie: ");
lcd.print(delayInjectie);
lcd.print(“ms”);

lcd setCursor (0,1);
lcd.print (" ");

lcd.setCursor(0, 1);
lcd.print("Sluit: ");
lcd.print(delaySluit);
lcd.print(“ms”);

digitalWrite(pinRelais, HIGH);
delay(delayInjectie);
digitalWrite(pinRelais, LOW);
delay(delaySluit);
}

Vooruitdanmaar. Niet echt mooi maar het kan! Succes,