LCD trouble or coding issue?

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
rdg123
 
Posts: 16
Joined: Mon Sep 01, 2008 11:21 pm

LCD trouble or coding issue?

Post by rdg123 »

I have been noodling around with my new Ardiuno Experimentation Kit and the LCD from adafruit. After figuring out how to get everything wired and programmed correctly, I've come across a stumper.

The LCD seems to glitch on the word "station" (see accompanying code & pic). If I try to step through the word letter-by-letter, I get to "ation" and things get screwy. Is there something about my code causing this or is it something else?

These new toys sure take a lot of time off my hands...
LCD prob
LCD prob
1222091726.jpg (371.02 KiB) Viewed 1155 times
#include <LiquidCrystal.h>

/* 
 The circuit:
 * pushbutton attached to pins 6,7,8 from +5V with pullup resistors (10k) & GND
 * LCD attached to digital pins 12(reset), 11(enable), 5(DB4), 4(DB5), 3(DB6), 2(DB7), +5V & GND
 * LCD read/write pin to GND
 * LCD pin for brightness to 1k pot
 * LCD pin for backlight(+) to 1k pot wired to +5V
 * LCD pin for backlight(-) to GND
  
 created  22 Dec 2009
 by Will Rogers
 
 cribbed from http://arduino.cc/en/Tutorial/ButtonStateChange & /./LiquidCrystal
 
 */

// Constants won't change:
LiquidCrystal lcd (12,11,5,4,3,2);
const int terminalPin = 6; // the pin that the pushbutton is attached to
const int tenPin = 7;
const int onePin = 8;

const int numRows = 2;
const int numCols = 16;

// Variables will change:
char terminalPush [] = {'A', 'B', 'C', 'D'}; //list of available terminal posts
int terminalPushCounter = 4; // counter for the number of button presses
int terminalState = 0; // current state of the button
int lastTerminalState = 0; // previous state of the button

int tenPush = 0;
int tenPushCounter = 9;
int tenState = 0;
int lastTenState = 0;

int onePush = 0;
int onePushCounter = 9;
int oneState = 0;
int lastOneState = 0;

void setup() {
  // initialize the button pins as inputs
  pinMode(terminalPin, INPUT);
  pinMode (tenPin, INPUT);
  pinMode (onePin, INPUT);
  // initialize serial communication for troubleshooting
  Serial.begin(9600);
  //initialize lcd
  lcd.begin (numRows, numCols);
}


void loop() {
  // read the pushbutton input pins
  terminalState = digitalRead(terminalPin);
  tenState = digitalRead(tenPin);
  oneState = digitalRead(onePin);
  delay (50);

  // compare the buttonStates to their previous state
  if (terminalState != lastTerminalState) {
    // if the state has changed, increment the counter
    if (terminalState == HIGH) {
      delay (10);
      if (terminalPushCounter < 4) {
        terminalPushCounter++;
      }
      else {
        terminalPushCounter = 0;
      }
      Serial.println(terminalPush);
        } 
    else {
    }
    lastTerminalState = terminalState;
  }
  if (tenState != lastTenState) {
    if (tenState == HIGH) {
      delay (10);
      if (tenPushCounter < 9) {
        tenPushCounter++;
      }
      else {
        tenPushCounter = 0;
      }
      Serial.println(tenPushCounter);
    }
    else {
    }

    lastTenState = tenState;
  }
  if (oneState != lastOneState) {
    if (oneState == HIGH) {
      delay (10);
      if (onePushCounter < 9) {
        onePushCounter++;
      }
      else {
        onePushCounter = 0;
      }
      Serial.println(onePushCounter);
    }
    else {
    }
    lastOneState = oneState;
  }
  lcd.setCursor (0,0);
  lcd.print ("TERMINAL");
  lcd.setCursor (14,0);
  lcd.print (terminalPush [terminalPushCounter]);
  delay (50);
  lcd.setCursor (0,1);
  lcd.print ("STATION");
  delay (100);
  lcd.setCursor (14,1);
  lcd.print (tenPushCounter);
  delay (50);
  lcd.setCursor (15,1);
  lcd.print (onePushCounter);
  delay (50);
}

User avatar
zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: LCD trouble or coding issue?

Post by zener »

Read this thread:

http://forums.adafruit.com/viewtopic.php?f=8&t=12627

This type of problem has been reported a couple of times. There are a couple of workarounds shown toward the end of the thread that you can try.

User avatar
rdg123
 
Posts: 16
Joined: Mon Sep 01, 2008 11:21 pm

Re: LCD trouble or coding issue?

Post by rdg123 »

Dude - yer thread was dead on. Thanks! Now to follow your previous suggestions and learn how to send this info over my two wires.

User avatar
zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: LCD trouble or coding issue?

Post by zener »

Keep in mind I wrote very little of that thread, and not much useful as I recall... although I was right that the display was not to blame...

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”