I am using the hd44780 library to drive my LCD display with a PCF8574 I2C backpack. I'm using a cheap Chinese Pro Micro clone (3.3v 5v ATMega32U4). I've tried it on two separate Pro Micros with the same results. Incidentally, this code works perfectly on my Adafruit Feather 32U4.
After calling lcd.clear(), the next character is omitted.
For example, here is my code (from the I2Cexp LineWrap example, I just changed rows and cols values):
#include <Wire.h>
#include <hd44780.h> // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header
hd44780_I2Cexp lcd; // declare lcd object: auto locate & config exapander chip
// LCD geometry
// while 16x2 will work on most displays even if the geometry is different,
// for actual wrap testing of a particular LCD it is best to use the correct
// geometry.
const int LCD_COLS = 20;
const int LCD_ROWS = 4;
void setup()
{
int status;
// initialize LCD with number of columns and rows:
// hd44780 returns a status from begin() that can be used
// to determine if initalization failed.
// the actual status codes are defined in <hd44780.h>
status = lcd.begin(LCD_COLS, LCD_ROWS);
if(status) // non zero status means it was unsuccesful
{
status = -status; // convert negative status value to positive number
// begin() failed so blink error code using the onboard LED if possible
hd44780::fatalError(status); // does not return
}
// turn on automatic line wrapping
// which automatically wraps lines to the next lower line and wraps back
// to the top when at the bottom line
// NOTE:
// noLineWrap() can be used to disable automatic line wrapping.
// _write() can be called instead of write() to send data bytes
// to the display bypassing any special character or line wrap processing.
lcd.lineWrap();
}
void loop()
{
lcd.clear();
lcd.print("WrapTest");
delay(2000);
lcd.clear();
//print the configured LCD geometry
lcd.print(LCD_COLS);
lcd.print("x");
lcd.print(LCD_ROWS);
delay(3000);
lcd.clear();
// print a long text string
// without line wrapping enabled, the text would not wrap properly
// to the next line.
if(LCD_COLS == 8)
lcd.print("A long text line");
else
lcd.print("This is a very long line of text");
delay(3000);
lcd.clear();
// now print 2 full displays worth of characters to show
// the full wrapping.
lcd.cursor(); // turn on cursor so you can see where it is
// lcd.cursor(); // I had to call this twice after a clear to get it to work
char c = '0'; // start at the character for the number zero
for(int i = 2*LCD_COLS*LCD_ROWS; i; i--)
{
lcd.print(c++);
delay(200); // slow things down to watch the printing & wrapping
if(c > 0x7e) // wrap back to beginning of printable ASCII chars
c = '!';
}
delay(3000);
lcd.noCursor(); // turn off cursor
}
When this code runs, I see "rapTest" instead of "WrapTest" and "his is a very long line of text" instead of "This is a very long line of text". I can get it to work by calling lcd.print(" "); after each clear().
I am unable to get the results of I2CexpDiag on my cheap Pro Micro Clones (I can't seem to get the Serial Monitor to work), but here are the diagnostics on the LCD from my Adafruit Feather:
********************************************************************
Serial Initialized
--------------------------------------------------------------------
I2CexpDiag - i2c LCD i/o expander backpack diagnostic tool
--------------------------------------------------------------------
hd44780 lib version: 1.0.1
--------------------------------------------------------------------
Reported Arduino Revision: 1.8.5
CPU ARCH: AVR - F_CPU: 8000000
--------------------------------------------------------------------
SDA digital pin: 2
SCL digital pin: 3
--------------------------------------------------------------------
Checking for required external I2C pull-up on SDA - YES
Checking for required external I2C pull-up on SCL - YES
Checking for I2C pins shorted together - Not Shorted
--------------------------------------------------------------------
Scanning i2c bus for devices..
i2c device found at address 0x3F
Total I2C devices found: 1
--------------------------------------------------------------------
Scanning i2c bus for all lcd displays
LCD at address: 0x3F | config: P01245673H | R/W control: Yes
Total LCD devices found: 1
--------------------------------------------------------------------
LCD Display Memory Test
Display: 0
Walking 1s data test: PASSED
Address line test: PASSED
--------------------------------------------------------------------
Each working display should have its backlight on
and be displaying its #, address, and config information
If all pixels are on, or no pixels are showing, but backlight is on, try adjusting contrast pot
If backlight is off, wait for next test
--------------------------------------------------------------------
Blinking backlight test: to verify BL level autodetection
If backlight is mostly off but
you briefly see "BL Off" on display with backlight on,
then the library autodetected incorrect BL level
and the library cannot autoconfigure the device
--------------------------------------------------------------------
Displaying 'uptime' on all displays
--------------------------------------------------------------------
I noticed that when I run the diagnostics on my clone, the clock is very fast when it gets to the uptime section.
Can anyone suggest something I can do on my Pro Micros to get this to work? The workaround is a mjor hack and I'd like to avoid it.