crashing lcd.

Hello all,

I've got a little problem with my LCD and can't figure out what is happening.
this is what's happening:
every time I upload a sketch the screen stays as it should one piece,
But after say 3 to 10 seconds, it crashes to the first halve of the screen.
Sometimes it just crashes right away.

Now I found out I had the weird split up kind. Like here:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1276361433

I have build it like this, except I put the contrast pin to pin 6 on the arduino, so I could spare me one more pot:

But with a arduino/atmega (atmega328) chip on a breadboard.

And I use the library someone suggests on that page (liquidcrystal440).
Further more I have switched out the atmega chips, meening I looked if it was the chip malfunctioning or not.
but it's not the chip :frowning:

I know of this Ram issue that can happen, where you do something in the code that writes the Ram full.
I must say I'm not a rooky, but I'm not very experienced either, but if something might be wrong with the code, I can't find it:

int pota;
int potb;
int potc;
int dval;
int buttonstate;
int apin = A0;
int bpin = A1;
int cpin = A2;
int buttonpin = 8;
int ledpin = 13;

//include a library that works with my lcd.
#include <LiquidCrystal440.h>
//set pins to use for lcd screen connections
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup(){
  //set pinmodes.
  pinMode(apin, INPUT);
  pinMode(bpin, INPUT);
  pinMode(cpin, INPUT);
  pinMode(6, OUTPUT);
  pinMode(buttonpin, INPUT);
  pinMode(ledpin, OUTPUT);
  //set screen brightness.
  analogWrite(6, 70);
  lcd.begin(8,2);
  //start serial to debug.
  Serial.begin(9600);
  delay(1000);
}

  void loop(){
    dval = (100);

    //read the value's from the potmeters
    pota = (analogRead(apin));
    potb = (analogRead(bpin));
    potc = (analogRead(cpin));
    
    //read the button state.
    buttonstate = digitalRead(buttonpin);
    //see over serial what the button state is.
    Serial.println(buttonstate);
    //test to see if the buton works.
    if(buttonstate == 1){
      digitalWrite(ledpin, HIGH);
      
      //clear lcd just in case.
      lcd.clear();
      //set cursor at the start, just in case.
      lcd.setCursor(0,0);
      //little wait delay.
      delay(10);
      
      //print on the first halve the data we get from pin A0.
      lcd.print("bA0:");
      lcd.print(pota);
      delay(10);
      
      //print on the second halve the data we get from pin A1.
      lcd.setCursor(0,1);
      lcd.print("bA1:");
      lcd.print(potb);
      
      delay(dval);
      
    }
    else{
      digitalWrite(ledpin, LOW);
      delay(100);
    }
    
  }

Any suggestions would be appreciated :slight_smile:

I have build it like this, except I put the contrast pin to pin 6 on the arduino, so I could spare me one more pot:
So you did everything just like the tutorial except:
(1) You used a breadboarded chip rather than an Arduino,
(2) You used PWM instead of a potentiometer to control the contrast,
(3) You used a different library,
(4) you used a different sketch.

So really all you used from the tutorial is the choice of pins. None of this should be a problem but it is kind of interesting!

I suggest that you simplify your sketch so that initially it just displays some static information on each half of the screen and make sure that part works correctly. Then piece by piece add in the the additional functions that you desire and make sure each one works before adding in the next.

Since you are writing to each half of your 16x1 LCD separately you really don't need the functionality of the LiquidCrystal440 library. That library allows you to write a string of more than 8 characters to a 16x1 display without repositioning the cursor after the the 8th character, but you are not doing this.

Don

Yes arduino on breadbord, pwm for pin 6 (this is possible right?)
yes had to use that library cause the normal one couldn't wrap place 8 and 40 together (split screen type.)
Yes diffrent sketch because the example works :slight_smile:

beside just showed the tutorial, to show you how I hooked the wires to the ic, and the only difference from the schematic/diagram is that the contrast pin is on pin 6 of the arduino, yes I tested and the screen could be controled by PWM.

yes had to use that library cause the normal one couldn't wrap place 8 and 40 together (split screen type.)
But you are not using this capability.

Don

From what I read is that it does it automaticly but I could offcourse be wrong :slight_smile:

It says it on this page:
http://code.google.com/p/liquidcrystal440/

at the line that starts with Linewrap :slight_smile:

From the LiquidCrystal440 info mentioned above:

Linewrap When you declare the dimensions of the LCD in your begin call, the LiquidCrystal library remembers how long the lines are. Now when it reaches the end of line 1, text wraps onto line 2 (not line 3 as previously).

This particular paragraph refers to the 20x4 displays since it mentions line 3. Normally if you send a long string of characters to such a display the text wraps from line 1 to line 3, from line 3 to line 2, from line 2 to line 4 and then from line 4 back to line 1 ( 1 --> 3 --> 2 --> 4 --> 1 etc.). The '440 library fixes this so that the wrap goes normally, 1 --> 2 --> 3 --> 4 --> 1 etc. I believe that the library also fixes the gap between lines 1 and 2 of the 16x2 displays and, as I mentioned before, fixes the need to reposition the cursor for the right half of a 16x1 display. None of this capability is used by your sketch so what I am saying is that you do not need to use LiquidCrystal440 for your application.

I would remove the variable for the delay value (which probably should be initialized in 'setup' instead of 'loop') and remove the test for the push button state. I would put a much longer delay at the end of the loop and then see if your sketch can continuously and reliably display the value of the potentiometers.

Also, I see that each time around the 'loop' you are clearing the display and rewriting some information that never changes. This is not necessary and should probably be avoided by writing the unchanging information in 'setup' and just writing the information that changes in 'loop'. This introduces some other problems that you will become aware of when you get things working, but they can be fixed later.

Don

Yes thanks :slight_smile:
I should have said that the screen is 16 x 1 but logicly is 20 x 4.
that is why I had to use it cause the right halve wasn't being used :slight_smile:

I should be more clear.

Thanks for the tips, I'll use them and see if it helps me out.

Alright tryed the modifications and bam, still crashes .. :frowning:

ow and i experienced that problem, things stick around on the display :S

edit: It been working for a while now, haven't seen it crash, what I did was change some wire's to different pins.
this is what the code looks like right now:

int pota;
int potb;
int potc;
//int buttonstate;
int apin = A0;
int bpin = A1;
int cpin = A2;
//int buttonpin = 10;
int ledpin = 13;

//include a library that works with my lcd.
#include <LiquidCrystal440.h>
//set pins to use for lcd screen connections
LiquidCrystal lcd(12,11,5,6,7,8);

void setup(){
  //set pinmodes.
  pinMode(apin, INPUT);
  pinMode(bpin, INPUT);
  pinMode(cpin, INPUT);
  pinMode(9, OUTPUT);
  //pinMode(buttonpin, INPUT);
  pinMode(ledpin, OUTPUT);
  //set screen brightness.
  analogWrite(9, 70);
  lcd.begin(8,2);
    
  //print on the first halve the bA0, (bit value, pin A0)
  lcd.setCursor(0,0);
  lcd.print("bA0:");
  //print on the second halve the bA1, (bit value, pin A1)
  lcd.setCursor(0,1);
  lcd.print("bA1:");
  
  //start serial to debug.
  Serial.begin(9600);
  delay(1000);
}

  void loop(){
    //clear lcd just in case.
    //lcd.clear();
    
    //read the value's from the potmeters
    pota = (analogRead(apin));
    potb = (analogRead(bpin));
    potc = (analogRead(cpin));
    
    //read the button state.
    //buttonstate = digitalRead(buttonpin);
    //see over serial what the button state is.
    //Serial.println(buttonstate);
    //test to see if the buton works.
    //if(buttonstate == 1){
      
      digitalWrite(ledpin, HIGH);
     
      //print the data next to bA0      
      lcd.setCursor(4,0);
      lcd.print(pota);
      
      //print the data next to bA1
      lcd.setCursor(4,1);
      lcd.print(potb);
      
    //}
    //else{
      digitalWrite(ledpin, LOW);
      delay(100);
    //}
  }

ow it just crashed while I was typing this!

here is the following problem, if I declare bA0 and bA1 in the setup these can't be changed!
since I'm working on a system that can display multiple things, it ain't handy.
Also I have noticed that when I put the lcd.clear() in the loop it often crashes faster!

Something is clearly wrong, I salvaged this from a velleman kit, that had it working fine though.
I obviously checked if it was hardware compatible with the arduino library! and it was!
but since it was in the Thrash can I wouldn't be surprised if it was thrown away because the display didn't work :slight_smile:

I should have said that the screen is 16 x 1 but logicly is 20 x 4.
It is logically an 8x2 not a 20x4. Follow the LCD Addressing link at http://web.alfredstate.edu/weimandn for the complete explanation.

Also I have noticed that when I put the lcd.clear() in the loop it often crashes faster!
You don't want to use lcd.clear() now since it will erase the "bA0:" and "bA1:" headings.

I wouldn't be surprised if it was thrown away because the display didn't work
You can verify that it works by just commenting out everything in loop() and also getting rid of the serial debugging code in setup(). Your "bA0:" and "bA1:" titles should show up and stay there until you remove power.

Don