Wiero Screen Problem.

Hi all,

I have a really strange problem with my 20x4 lcd screen when uploading to the Arduino. When i add the following lines of code and upload them it sends the screen crazy with random japanese type characters even though it compiles fine.

if (movesteps < 0){
  lcd.print ("   LEFT  ");
}

if (movesteps > 0){
  lcd.print ("   RIGHT  ");
}

If i remove the above lines of code from my Arduino project it works perfectly. The above code is just in the main loop body of my code as show below.

Does anyone have any idea’s as i’m mystified.

//Include the button Library
#include <Button.h>

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

#include <PololuWheelEncoders.h>
PololuWheelEncoders encoder;
char val1, val2;
char s;
   
  int i = 0;
   
Button button_left = Button(6,PULLUP);
//Button button_ent = Button (7, PULLUP);
Button button_right = Button(7,PULLUP);


int BUTTONLOOP;

unsigned long previousMillis;


void setup()
{
  lcd.begin(20, 4);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
          digitalWrite(8, LOW);
          digitalWrite(9, LOW);
          
          pinMode(13,OUTPUT);
          digitalWrite(13,LOW);
          //initialize encoder for pins 10,13  
          encoder.init(10,13,255,255);
          
  Serial.begin(9600);

   lcd.setCursor(0,0);
   lcd.print("********************");
     lcd.setCursor(0,1);
   lcd.print("*     AsrtoSky     *");
     lcd.setCursor(0,2);
   lcd.print("*    Dome Runner   *");
     lcd.setCursor(0,3);
   lcd.print("********************");
   delay (4000);
   lcd.setCursor(0,0);
   lcd.print("                    ");
   lcd.setCursor(0,1);
   lcd.print("                    ");
   lcd.setCursor(0,2);
   lcd.print("                    ");
   lcd.setCursor(0,3);
   lcd.print("                    ");
   lcd.setCursor(0,0);
   lcd.print("AstroSky DomeRunner");
   lcd.setCursor(0,1);
   lcd.print("====================");
   lcd.setCursor(6,3);
   lcd.print("AZ: ");
   //lcd.setCursor(11,3);
   //lcd.print(" DEG");
}

const int MAX_LEN = 4; // the max digits in the number plus decimal point
char  strValue[MAX_LEN + 1]; // add one for the terminating null

int index = 0;
int value1;
int value2;
int diffvall;
int movesteps;

void loop()
{

//Serial.print("Current Millis : ");
//Serial.println(millis());
lcd.setCursor(10,3);
lcd.print(value1);
    GetAz();
    value1 = value2;
   lcd.setCursor(10,3);
   lcd.print(value1);
    ButtonPress();
    llegirPos();

  
if (millis() - previousMillis > 15000){

  previousMillis = millis();
GetValue2();
lcd.setCursor(15,2);
lcd.print("   ");
diffvall = (value2 - value1);
lcd.setCursor(15,2);
lcd.print(diffvall);
movesteps = (diffvall * 10);
lcd.setCursor(0,0);
lcd.println(movesteps);

if (movesteps < 0){
  lcd.print ("   LEFT  ");
}

if (movesteps > 0){
  lcd.print ("   RIGHT  ");
}

          
         }
      }
  
   
 void GetAz(){ 
  if( Serial.available())
  {
    char ch = Serial.read();
    if(index < MAX_LEN && ch != 13) // 13 is ascii value of carriage return
    {
      strValue[index++] = ch; // add the ASCII character to the string;
    }
    else
    {
      // here when buffer full or on the first non digit
      strValue[index] = '\0';        // terminate the string with a 0
   
      index = 0;      // reset the index for the next string
        lcd.setCursor(10,3);
      //Serial.println(strValue);
        //lcd.print(value);
    }  
  }
 }
 

 void GetValue2(){
            value2 = atoi(strValue);  // use atof to convert the string to a float
            lcd.setCursor(15,3);
            lcd.print(value2);
            
                          previousMillis = millis();
                          //Serial.print("Previous Millis : ");
                          //Serial.print(previousMillis);
                          //Serial.println();
                 }
 



 void ButtonPress() {
   
    while(button_left.isPressed()) {    
              digitalWrite(8, HIGH);
              digitalWrite(9, HIGH);
              lcd.setCursor(1,3);
              lcd.print("<--- ");            
}

digitalWrite(8, LOW); 
              lcd.setCursor(1,3);
              lcd.print("     ");
 

    while(button_right.isPressed()) {    
              digitalWrite(8, HIGH);
              digitalWrite(9, LOW);
              lcd.setCursor(15,3);
              lcd.print("---> ");              
}

 digitalWrite(8, LOW); 
               lcd.setCursor(15,3);
              lcd.print("     ");
}

//capture encoder counts.
void llegirPos() {

  lcd.setCursor(1,2);
  lcd.print("Encoder: ");
  lcd.print( encoder.getCountsM1(), DEC );
  lcd.print ("    ");  
}

ribuck,
the top part of your code is not the source of your problem. It’s somewhere deep dark down inside your code. I’ll try and see.

This code works fine to test the top part of your post.

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

int movesteps = -1;

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

void loop() {
  
  if (movesteps < 0){
    lcd.print ("   LEFT  ");
  }

  if (movesteps > 0){
    lcd.print ("   RIGHT  ");
  }
  lcd.home();
}

:-?

I know it's been a while, Have you figured it out, I'm too much of a newbie to know what's going on in your code, sorry :-[ .

:-/

Happy Post-Thanksgiving