LCD problem+video+code

Hello,

since 3 weeks ive been trying desperately to make my lcd run…

I try to realize a menu to monitor current position of a stepper and to enter/calibrate positions for auto drive.

The LCD crashes at some point and shows weird characters as seen in the video:

The first state of the display shows the main loop.

From there i call a function for menu and from there a second function for the calibration value input (where the error occurs).

Here the code, just before the function wich leads to the error is called:

case 1:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Menu:");   
        lcd.setCursor(0,1);
        lcd.print("2: Calibrate pos.?");
       
        delay(100); 
        if(digitalRead(enterSwitchPin)==HIGH){
        steps=manualPosition();

and code from manualPosition(); function where the error occurs:

long manualPosition(){
  delay(200);
 lcd.clear();
  int stelle=0;
  int stelle0Value=0;
  int stelle1Value=0;
  int stelle2Value=0;
  int stelle3Value=0;
   lcd.print("TESTESTEST");
  delay(200);
long totalsteps=0;
  
  
    while(stelle==0){
      delay(200);
    speedpotiValue=analogRead(speedPotiPin);
     if(speedpotiValue<=100){
          
          lcd.setCursor(0,0);
          lcd.print("Enter Position:"); 
          lcd.setCursor(0,1);
            lcd.print("0x.xx cm");
      Serial.print("Pos 0x.xxcm\n");
      stelle0Value=0;
    }
    if(speedpotiValue>100 && speedpotiValue<=200){
            lcd.setCursor(0,0);
          lcd.print("Enter Position:"); 
          lcd.setCursor(0,1);
            lcd.print("1x.xx cm");
            Serial.print("Pos 1x.xxcm\n");
            stelle0Value=1;
    }
     if(speedpotiValue>200 && speedpotiValue<=300){
       lcd.setCursor(0,0);
          lcd.print("Enter Position:"); 
          lcd.setCursor(0,1);
            lcd.print("2x.xx cm");
            Serial.print("Pos 2x.xxcm\n");
            stelle0Value=2;
    }

there follow many speedpoti value if conditions to check the value for calibration.
but it doesnt matter since lcd.print(“TESTESTEST”); doesnt even work.

i need advice, please help me somehow

Here the code, just before the function wich leads to the error is called:

Have you considered turning your phone 90 degrees when you take your videos?

You really should show all of the code.

You should also show an in-focus picture of your entire setup.

Right now we have no idea which Arduino pins you are using for your display. For example if you are using pin 1 then the serial.print() can affect your LCD.

Don

#include <LiquidCrystal.h>
LiquidCrystal lcd(9,8,7,6,5,4);

const int cwccwSwitchPin=49;
const int clockSwitchPin=47;
const int enableSwitchPin=51;
const int speedPotiPin=A0;
const int menuSwitchPin=53;
const int enterSwitchPin=45;
const int backSwitchPin=43;


const int cwccwPin=12;
const int clockPin=13;
const int enablePin=11;
const int testPin=10;

long manualposValue=0;
int manualPositionValue=0;
int enterSwitchpinState=0;
int backSwitchPinState=0;
 int cwccwSwitchPinState=0;
 int clockSwitchPinState=0;
// int halffullSwitchPinState=0;
 int enableSwitchPinState=0;
 
 int prevcwccwSwitchPinState=0;
 int prevclockSwitchPinState=0;
 //int prevhalffullSwitchPinState=0;
 int prevenableSwitchPinState=0;
 int menuSwitchPinState=0;
 long steps=0;
 double manipulatortransmissionratio=0.005;
double translationdistance=0;

int x=0,y=0,z=0;
int richtung=0;
int schritt=0;
int schrittweite=0;
int enable=0;
int speedpotiValue=0;

void setup(){
lcd.begin(16,2);
lcd.clear();
  
  pinMode(menuSwitchPin,INPUT);
  pinMode(cwccwSwitchPin,INPUT);
  pinMode(clockSwitchPin,INPUT);
  //pinMode(halffullSwitchPin,INPUT);
  pinMode(enableSwitchPin,INPUT);
  
  pinMode(cwccwPin,OUTPUT);
  pinMode(clockPin,OUTPUT);
  //pinMode(halffullPin,OUTPUT);
  pinMode(enablePin,OUTPUT);

  Serial.begin(9600);
}

void loop(){
 //************MENU****
Serial.print("welcome to main loop\n");
lcd.setCursor(0,0);
lcd.print("Man. drive ");
if(richtung==0){            //direcLED aus aus=kammer raus =mehr skala=+1
  lcd.print("backw.");
  }
  else{                          //direcLED an=kammer rein=weniger skala=-1
  lcd.print("forw.");
  }
lcd.setCursor(0,1);

    lcd.print((steps*manipulatortransmissionratio)/10);
   lcd.print("cm");
   
 menuSwitchPinState=digitalRead(menuSwitchPin);
 if( menuSwitchPinState==1){
 mainMenu();
     Serial.print("lol");
   
 }



  }
  if(enable==1){  /
    digitalWrite(enablePin,HIGH);
    clockSwitchPinState=digitalRead(clockSwitchPin);
  //Serial.println(clockSwitchPinState);
  while(clockSwitchPinState==HIGH){
  clockSwitchPinState=manualDrive(clockSwitchPinState);
  
    }
      analogWrite(clockPin,0);
  }
  else{
   digitalWrite(enablePin,LOW); 
  }
  prevenableSwitchPinState=enableSwitchPinState;
}






//******manualDrive*******

int manualDrive(int x){
  
  speedpotiValue=analogRead(speedPotiPin);

  if(speedpotiValue<300){
  digitalWrite(clockPin,HIGH);
  delay(100);
  digitalWrite(clockPin,LOW);
  Serial.print("min");
  
  x=digitalRead(clockSwitchPin);
 
  
  }
  
  if(speedpotiValue>=300 && speedpotiValue<650){
  digitalWrite(clockPin,HIGH);
  delayMicroseconds(100);
  digitalWrite(clockPin,LOW);
  Serial.print("med");
  
  x=digitalRead(clockSwitchPin);
 
  
  }
  
  if(speedpotiValue>=650){
  digitalWrite(clockPin,HIGH);
  delayMicroseconds(1);
  digitalWrite(clockPin,LOW);
  Serial.print("max");
  
  x=digitalRead(clockSwitchPin);


  
  }
  if(richtung==0){            /
   
   // lcd.setCursor(0,1);
    steps+=1;
    //lcd.print((steps*manipulatortransmissionratio)/10);
    //lcd.print("cm");
    
  }
  else{                          //direcLED an=kammer rein=weniger skala=-1 ,Zählt steps richtig rum
    //lcd.setCursor(0,1);
    steps-=1;
    //lcd.print((steps*manipulatortransmissionratio)/10);
    //lcd.print("cm");
    
  }
   lcd.print("                              ");
  lcd.setCursor(0,1);
  lcd.print((steps*manipulatortransmissionratio)/10);
  Serial.print((steps*manipulatortransmissionratio)/10);
    Serial.print("\n");
  return x;

  
}



//*********manualDirection*************

void manualDirection(){
 
        richtung=!richtung;
     delay(200);
   

  
  if(richtung==1){
  digitalWrite(cwccwPin,HIGH);
  }
  else{
   digitalWrite(cwccwPin,LOW); 
    }
    return;
}


[color=red]//******************mainMenu*************[/color]

void mainMenu(){
  delay(100);
  menuSwitchPinState=0;
  backSwitchPinState=0;
  while(backSwitchPinState==0){
   switch(menuSwitchPinState){
     
    case 0:
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Menu:"); 
    lcd.setCursor(0,1);
    lcd.print("1: Drive to pos.?");
    Serial.print("manualDriveto\n");
      delay(100);
      if(digitalRead(enterSwitchPin)==HIGH){
        manualposValue=manualPosition();
        Serial.print(manualposValue);
        Serial.print("vorautodrive\n");
        delay(2200);
        steps=autoDrive(manualposValue,steps);
        Serial.print(manualposValue);
        Serial.print("nachautodrive\n");
        delay(2200);
        
        }
      if(digitalRead(menuSwitchPin)==HIGH){
       menuSwitchPinState+=1;
      
       }
       if(digitalRead(backSwitchPin)==HIGH){
       backSwitchPinState=1;
       }
      break;
    case 1:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Menu:");   
        lcd.setCursor(0,1);
        lcd.print("2: Calibrate pos.?");
       Serial.print("Calibrate\n");
       
        delay(100); 
        if(digitalRead(enterSwitchPin)==HIGH){
     [color=red]   steps=manualPosition();[/color]
        Serial.print(steps);
                Serial.print("steps nach steps=manualpos in case 1 hauptmenü\n");
        delay(2200);
        
        }
      if(digitalRead(menuSwitchPin)==HIGH){
       menuSwitchPinState+=1;
      
       }
       if(digitalRead(backSwitchPin)==HIGH){
       backSwitchPinState=1;
       }
      break;
    case 2:
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Menu:"); 
      lcd.setCursor(0,1);
      lcd.print("33: Drive to Pos?");
       Serial.print("menu2\n");
       delay(100);
       if(digitalRead(menuSwitchPin)==HIGH){
       menuSwitchPinState+=1;
      
       }
       if(digitalRead(backSwitchPin)==HIGH){
       backSwitchPinState=1;
       }
       break;
    case 3:
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Menu:"); 
      lcd.setCursor(0,1);
      lcd.print("444: Drive to Pos?");
       Serial.print("menu3\n");
       delay(100);
       
       if(digitalRead(menuSwitchPin)==HIGH){
       menuSwitchPinState=0;
      
       }
       if(digitalRead(backSwitchPin)==HIGH){
       backSwitchPinState=1;
       }
       break;
   
   }
   
    
  }
  //Serial.print("lol");
 return;
}

[color=red]//*********manualPosition******

long manualPosition(){[/color]
  delay(200);
  lcd.clear();
  int stelle=0;
  int stelle0Value=0;
  int stelle1Value=0;
  int stelle2Value=0;
  int stelle3Value=0;
   lcd.print("umbrellaella");
  delay(2000);
long totalsteps=0;
  
  
    while(stelle==0){
      delay(200);
    speedpotiValue=analogRead(speedPotiPin);
     if(speedpotiValue<=100){
          
          lcd.setCursor(0,0);
          lcd.print("Enter Position:"); 
          lcd.setCursor(0,1);
            lcd.print("0x.xx cm");
      Serial.print("Pos 0x.xxcm\n");
      stelle0Value=0;
    }
    if(speedpotiValue>100 && speedpotiValue<=200){
            lcd.setCursor(0,0);
          lcd.print("Enter Position:"); 
          lcd.setCursor(0,1);
            lcd.print("1x.xx cm");
            Serial.print("Pos 1x.xxcm\n");
            stelle0Value=1;
    }
     if(speedpotiValue>200 && speedpotiValue<=300){
       lcd.setCursor(0,0);
          lcd.print("Enter Position:"); 
          lcd.setCursor(0,1);
            lcd.print("2x.xx cm");
            Serial.print("Pos 2x.xxcm\n");
            stelle0Value=2;
    }
   
   totalsteps=stelle0Value;
    totalsteps*=20000;
    totalsteps=totalsteps+(stelle1Value*1000 + stelle2Value*100 + stelle3Value*10)*2;
   
    Serial.print(totalsteps);
    Serial.print(" totalsteps ohne variablen\n");
  delay(2000);
    
    lcd.clear();
    delay(200);
 return totalsteps; 
}

Heres the code. I still had to cut it because it exceeded 9500 chars.
LCD is a KS0066/hitachi kompatible one.
i connected pins like this:
1:gnd
2:+vcc
3:10k poti
4: pin 9 (arduino mega 2560)
5:gnd
6:pin 8
7:-
8:-
9:-
10:-
11:pin 7
12:pin 6
13:pin 5
14:pin 4
15:-
16:-

Okay i found the root of the Problem: i used too low pulldown Resistor for an Input switch. The LCD tilted because of that.