Hello to the Forum.
I have been working on a project that uses an optical encoder and LCD to display a value from turning the encoder shaft.
So far my breadboard has been working Ok using a 16X2 LCD that uses the Hitachi chip (HD44780). So next was to use the LCD that was 12X1, a model made by Newhaven model NHD-0112BZ that I believe uses the SPLC780D chip. I have looked online and it appears this chip is compatible with the Hitachi chip but from what i am seeing it may not fully be.
Here is my code:
#include <LiquidCrystal.h>
LiquidCrystal lcd (4,5,6,7,8,9);
volatile float xcount = 0.0;
volatile int xdir = 12;
float x_axis;
float x_axis_dia;
int zero_pin = 10; //Zero x axis readout button pin
//if high or 1 then clear display
int R_D_pin = 11; //display radius or diameter
//if high or 1 then display diameter
// X axis interupt routine
void xstep() {
if (digitalRead(xdir) == 1) {
xcount++;
}
else {
xcount--;
}
}
void setup() {
Serial.begin(9600);
pinMode(zero_pin, INPUT);
pinMode(R_D_pin, INPUT);
lcd.begin(12,1);
lcd.setCursor(0,0);
attachInterrupt(digitalPinToInterrupt(2), xstep, RISING);
}
void loop() {
float x_axis = xcount/5000.0;
if (digitalRead(zero_pin) == 1) {
xcount = 0.0;
//Serial.println("H");
}
if (digitalRead(R_D_pin) == 1) {
x_axis_dia = x_axis*2.0; //display diameter
lcd.setCursor(0,0);
lcd.print("XD ");
}
else {
x_axis_dia = x_axis; //display radius
lcd.setCursor(0,0);
lcd.print("X ");
}
lcd.setCursor(3,0);
lcd.print(x_axis_dia,5);
//Serial.println(x_axis,5);
}
The display shows up with the characters X and XD plus number 0.0 however when I turn the encoder I am not seeing the full count like I was seeing on the 16X2 display which worked perfectly but not on this 12x1 display. Just the 0.0 and depending on the count 0.1 for example but none of the numbers before the .1 (not sure i explained that right but hope the idea comes through).
Any thoughts on what could be the issue between the displays? Oh I am using the Arduino Pro Mini 5 volt version.
Thanks,
Bruce