Line Wrap Demo omits character after lcd.clear()

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.


void loop()

 //print the configured LCD geometry

 // 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");
 lcd.print("This is a very long line of text");

 // 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--)
 delay(200); // slow things down to watch the printing & wrapping

 if(c > 0x7e) // wrap back to beginning of printable ASCII chars
 c = '!'; 
 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.

When I look at all the information:

  • dropped characters/command after clear()

  • serial port not working

  • the clock is very fast when it gets to the uptime section

  • works on another Arduino with same processor

  • clock rate used/reported in I2CexpDiag is 8Mhz

This all points to the clock on the clone Pro Micro not running at the speed that the IDE board type selected is using.
i.e. the IDE board type selected is likely 8Mhz but the Arduino clone board is actually running at 16Mhz.

You can test this with a simple sketch.
Run the blink sketch that comes with the IDE. If you get more than 5 blinks in 10 seconds, like 10, then actual clock rate of the board does not match the clock in the IDE board type.
If they don't match, then the delays in the LCD library will wrong and the serial baud rate will also be wrong.

If the board is running double (16 Mhz instead of 8Mhz) then the baud rate will be double what the sketch is trying to use.
I.e. 19200 instead of 9600

and all the LCD delays will be shorter than they need to be which can cause commands/chars to be dropped after a long command like clear()

--- bill

I did, indeed, have the wrong board selected. I had the 8MHz board selected and I'm actually using the 16MHz board. Once I changed it, the LCD worked correctly.

Thanks for your help.

You had said that the clone board was

a cheap Chinese Pro Micro clone (3.3v ATMega32U4)

Is your board a 3.3v board? running at 16Mhz?

The AVR spec shows 3.3v parts are not rated to run at 16Mhz.

If it is a 3v board running at 16Mhz then you may experience issues running it beyond its rated specs.

--- bill

My original post was incorrect. I was using my incorrect board selection voltage. I checked it with a meter and it's running at 5v. Thanks for pointing that out.

Glad it is all working.
--- bill