Problems with NewHavenDisplay's serial 4x20 in i2c mode

Working in i2c mode, the display initially shows all text and numbers in the right places… but after running for a while (which can be as short as ~1 minute or can be 4-5 minutes) there appears random numbers/characters in random locations on the LCD.

This problem shows up regardless of whether I use the lcd API library or I use Wire commands and send the commands and data to the LCD

Has anyone else run into this? Is this a programming issue? Can you help?
See below my program using the Wire library

thanks

#include <Wire.h>
#include <stdlib.h>
#include <stdio.h>
#define NHDLCD 0x28

extern char *ftoa(float f);

int counter=0;
float floater=0.0;

//---------------------------------------

void setup() {
Wire.begin();
delay(100);
init_lcd();
}
//---------------------------------------

void init_lcd()
{
lcd_clear();
lcd_XYtext(0, 0, “Hello Wire LCD”);
lcd_XYtext(1, 0, “LCD Line-1”);
lcd_XYtext(2, 0, “LCD Line-2”);
lcd_XYtext(3, 0, “LCD Line-3”);
delay(1000);
}

void lcd_clear()
{
Wire.beginTransmission(NHDLCD); //LCD on address (0x28)
Wire.send(0xFE);
Wire.send(0x51);
Wire.endTransmission();
}

void lcd_backspace()
{
Wire.beginTransmission(NHDLCD); //LCD on address (0x28)
Wire.send(0xFE);
Wire.send(0x4E);
Wire.endTransmission();
}

void lcd_cursorLeft()
{
Wire.beginTransmission(NHDLCD); //LCD on address (0x28)
Wire.send(0xFE);
Wire.send(0x49);
Wire.endTransmission();
}

void lcd_cursorRight()
{
Wire.beginTransmission(NHDLCD); //LCD on address (0x28)
Wire.send(0xFE);
Wire.send(0x4A);
Wire.endTransmission();
}

void lcd_contrast(unsigned char contrast)
{
Wire.beginTransmission(NHDLCD); //LCD on address (0x28)
Wire.send(0xFE);
Wire.send(0x52);
Wire.send(contrast);
Wire.endTransmission();
}

void lcd_brightness(unsigned char brightness)
{
Wire.beginTransmission(NHDLCD); //LCD on address (0x28)
Wire.send(0xFE);
Wire.send(0x52);
Wire.send(brightness);
Wire.endTransmission();
}

void lcd_underlineCursor(char state)
{
Wire.beginTransmission(NHDLCD); //LCD on address (0x28)
Wire.send(0xFE);
if(state==0) Wire.send(0x48);
else Wire.send(0x47);
Wire.endTransmission();
}

void lcd_blinkCursor(char state)
{
Wire.beginTransmission(NHDLCD); //LCD on address (0x28)
Wire.send(0xFE);
if(state==0) Wire.send(0x4C);
else Wire.send(0x4B);
Wire.endTransmission();
}

void lcd_XYtext(int row, int col, char *s)
{
lcd_setCursor(row, col);
Wire.beginTransmission(0x28); //LCD on address 80D (0x50)
while(*s) Wire.send(*s++);
Wire.endTransmission();
}

void lcd_XYfloat(int row, int col, float f)
{
char *s, a[5];
s=a;
lcd_setCursor(row, col);
// s=ftoa(f);
sprintf(s, “%f5.3”, f);
Wire.beginTransmission(0x28); //LCD on address 80D (0x50)
while(*s) Wire.send(*s++);
Wire.endTransmission();
}

void lcd_XYint(int row, int col, int n)
{
char *s, a[5];
s=a;
lcd_setCursor(row, col);
// itoa(n, s, 10);
sprintf(s, “%i”, n);
Wire.beginTransmission(0x28); //LCD on address 80D (0x50)
while(*s) Wire.send(*s++);
Wire.endTransmission();
}

void lcd_setCursor(int row, int col)
{
int cursorPos;
switch(row)
{
case 0:
cursorPos=col;
break;
case 1:
cursorPos=0x40+col;
break;
case 2:
cursorPos=0x14+col;
break;
case 3:
cursorPos=0x54+col;
break;
}
Wire.beginTransmission(0x28); //LCD on address 80D (0x50)
Wire.send(0xFE);
Wire.send(0x45);
Wire.send(cursorPos);
Wire.endTransmission();
}

void lcd_print(char *s, int n)
{
Wire.beginTransmission(0x28); //LCD on address 80D (0x50)
for(int i=0; i<n; i++) Wire.send(*s++);
Wire.endTransmission();
}

//---------------------------------------

void loop()
{
counter++;
floater=(float)counter/10.0;
lcd_XYint(1,0,counter);
lcd_XYfloat(1, 8, floater);
delay(1);
lcd_XYint(2,0,counter);
lcd_XYfloat(2, 8, floater);
delay(1);
lcd_XYint(3,0,counter);
lcd_XYfloat(3, 8, floater);
delay(1);
}

Try clearing the display in your main loop, for example after the last delay (1). Also increase the last delay to, 10-20ms, too fast for the eye to see any way.

I've just seen that the a array in the lcd_XYfloat and int method is too small. When you int gets larger than 9999, the array is going to over run with the /0 inserted at the end of the string. Results will depend on where that variable goes in the stack, ie un predictable behaviour foreseen, any way. I suppose that the return value on the stack from sprintf is over writing your /0 when values are larger than 9999. Therefore the print loop extends until it finds an /0.

Hope it helps.