LCD not displaying everything [FIXED]

Hi, i hope someone can help me with my project’s issue. So i have a sparkfun 5v lcd and i have got it working before but with this project i am using buttons to display different text on my lcd and i have got the code working and all of my buttons work but one. The last button is making a servo spin and that’s working but it is not displaying the message to the lcd. If you need to see my code just ask. And sorry if this post is in the wrong support section because this is my first post.

Thank You, For any help.

We need to see your code, how could anyone possibly answer without seeing it?

Ok, Here’s my code

#include <LiquidCrystal.h>
#include <Servo.h>
const int button5Pin =1;
Servo servo;
boolean servoState=false;

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

const int buttonPins[]={7,8,6,13,0};
boolean lastStates[]={false,false,false,false,false};

const int order[]={0,2,4,1,3};
int correctPressed=0;
int target=5;

void setup(){
  Serial.begin(9600);
  for(int i=0; i<target; i++)
  {
    pinMode(buttonPins[i], INPUT);
  }
  pinMode(button5Pin, INPUT);
  servo.attach(9);
  servo.write(90);
  lcd.begin(16,2);
  lcd.clear();
  lcd.print(" Enter Pin Code  ");
  lcd.setCursor(0,1);
  lcd.print(" Box is Locked!");
  delay(5000);
  lcd.clear();
  
  
  
}

void loop(){
  for(int i=0; i<target; i++)
  {
    if(checkButton(buttonPins[i]))
    {
      if(i==order[correctPressed])
      {
        correctPressed++;
        Serial.println(correctPressed);
        lcdPrint("correct", String(correctPressed));
        if(correctPressed>=target)
        {
          boxOpen();
        }
      }
      else{
        correctPressed=0;
        Serial.println("incorrect");
        lcdPrint("Incorrect", String(correctPressed));
      }
    }
  }
  delay(500);
  
 int button5State = digitalRead(button5Pin);
 Lock();
}
boolean checkButton(int pin)
{
  if(!digitalRead(pin))
  {
    delay(10);
    return true;
  }
  else{
    return false;
  }
}

void lcdPrint(String lineone, String linetwo)
{
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(lineone);
  lcd.setCursor(0,1);
  lcd.print(linetwo);
}

void boxOpen()
{
  lcd.clear();
  lcd.println(" Pin is Correct ");
  lcd.setCursor(0,1);
  lcd.print("  Box is Open!");
  correctPressed=0;
  servo.write(0);
  servoState=true;
  delay(3000);
}
void Lock(){
  int button5State;
  button5State = digitalRead(button5Pin);
lcd.clear();
lcd.setCursor(0,1);
  if(button5State == LOW){lcd.println(" Box is Locked! ");
  servo.write(90);
  
  lcd.clear();
  }
}

Ok some indication of what line is giving you the problem would help. In general comment out just the servo move bit and if it then works, you have a decoupling problem on the servo supply.

Hi, thanks for the reply tried commenting it out and the text still does not display. As i said before all the other buttons work but the only problem i can think of it could be is that when i soldered leads onto the pins of the LCD i bridged it somewhere below the header but as far as i can tell from looking at my soldering job nothing is causing a short.

If your LCD shows something then it is not the soldering. Can you point to a line that works and the one that dosn't?

In this part of the code part where the LCD is supposed to print Box is Locked. And like i said the servo.write function when i press the button still works just not the displaying text.

void Lock(){
  int button5State;
  button5State = digitalRead(button5Pin);
lcd.clear();
lcd.setCursor(0,1);
  if(button5State == LOW)[color=yellow]{lcd.println(" Box is Locked! ");[/color]
  servo.write(90);
  
  lcd.clear();
  }

Thanks for the help so far.

I notice that you have not done any cursor setting on the LCD, it could be that it is off the screen by the time you come to do this. Try adding a cursor positioning LCD call first.

I read that pin 0 and 1 are used by the USB connection for transfers when its connected.

Are you testing with an USB device attached ?

Could test it by expanding:

if(button5State == LOW){lcd.println(" Box is Locked! "); servo.write(90);

lcd.clear(); }

to

if(button5State == LOW){lcd.println(" Box is Locked! "); servo.write(90);

lcd.clear(); } else { lcd.clear(); lcd.setCursor(0,0); lcd.print("issues"); delay(5000); }

If your display says "issues" then it means the pin is not going low.

The lcd.println() statement is going to give you problems even if you get everything else sorted out.

Don

Hi, Thanks for the help so far,

Grumpy_Mike: I tried setting the cursor settings still did not display the text.

lennaert: I tried that and my LCD said issues, but none of the other buttons worked or did anything after trying that. Also tried using a battery Pack instead of the USB cable to see if that changed anything and still didn't.

Did you get that point?
You can not use pins 0 & 1 once you use Serial.begin that screws things up. Use some other pins.

I would, but I've used all the pins on my UNO... :( Honestly i guess i don't really need to display a message when i reset the servo but it would be nice if it did though.

I can't see you have used any of the analogue pins, they can be used just as digital pins if you define them as inputs.

You can…I never new that, How would you define them as inputs or in a array would it be like A0, A1 or something like that?

Thanks for all the help so far. :slight_smile:

Indeed you would. Just fill in the pin number or the pin function such as A0. Works both ways. Use it the same way as any other pin, so tell it it is an input (you might want to look into PULLUP too).

As stated before: do not use println in inappropriate display position, your text will be printed, but might drop off of the screen so to say.

I can't see you have used any of the analogue pins, they can be used just as digital pins if you define them as inputs.

Why are you saying they have to be defined as inputs? As far as I know they are just like all of the other I/O pins on the chip. The only thing that makes them 'analog' pins is because the Arduino normally makes use of their "alternate port functions" (datasheet section 13.3).

Don

I don't exactly know what happened...I took a nap and when i woke up i tried the code and know it works haven't changed anything so i'm a little bit confused :~ but now it works... So now i can finish my project

Thank you for the help everyone, Also thank you for the tip about being able to use analog pins as Digital.

floresta:
Why are you saying they have to be defined as inputs? As far as I know they are just like all of the other I/O pins on the chip. The only thing that makes them ‘analog’ pins is because the Arduino normally makes use of their “alternate port functions” (datasheet section 13.3).

Yes Don they are inputs by default, but it is good practice to define them as such in the setup function because it makes it clear that you are expecting to use them as inputs. It is also just a bit safer to set them as inputs in case of accidental code or hardware glitches.

I once worked with PICs and they had a nasty habit of very occasionally loosing their pin mode configuration so a trick was to redefine the pins each tie round the main loop.

My point is that they are the same as all the other I/O pins. You don't have to deal with them any differently than you do any of the so called 'digital' pins. They can even be accessed like the others, with the numbers 14-19.

Don