Sketch crashing using U8g2lib.h library with GM12864-59N

Hi.
I have a problem whith my sketch that run on arduino nano.

I use a display "LCD Module 128X64 I2C ST7567S" whit a Logic Level Converter from 5V arduino to 3.3V for aupplier the LCD.

The problem is that after starting the sketch, after 5/10 minutes the sketch stops.
Do you have any suggestions for me?
Thanks so much.

#include <U8g2lib.h>
#include <Wire.h>

U8G2_ST7567_ENH_DG128064I_1_HW_I2C u8g2(U8G2_R0, SCL, SDA, U8X8_PIN_NONE);  // LCD GRANDE

int x = 0;

void setup()
{
  u8g2.setI2CAddress(0x3F * 2); 
  u8g2.setBusClock(400000);
  u8g2.begin();
  Serial.begin(9600);
}
  
void loop()
{

u8g2.firstPage();
  do {
   
    u8g2.clearBuffer();
      u8g2.setFont(u8g2_font_ncenB14_tr);
      u8g2.setCursor(25, 23); 
      u8g2.print(x);
      
  } while ( u8g2.nextPage() );   
  Serial.println(x);  
  x = x +1; 
  if (x > 500)
  { 
    x=0;
  }
}
  u8g2.setI2CAddress(0x3F * 2); 

This looks very odd

Why the multiplication ?

Hi , i have used other forms, but errors.
can you give a other solution?
thanks

What is the I2C address of the display ?

I don't know if this will help at all, but I don't think you need to call u8g2.clearBuffer() in your code, because you are using u8g2.firstPage() and u8g2.nextPage(). So try removing it.

Also I don't think you need to use u8g2.setFont() each time you print something. Use it only when you need to change to another font. In your code, you can put this in setup() instead.

U8G2_ST7567_ENH_DG128064I_1_HW_I2C u8g2(U8G2_R0, SCL, SDA, U8X8_PIN_NONE);  // LCD GRANDE

Does your display work properly at the start of the sketch? That constructor does not look correct, here is the code from U8g2lib.h, with the arguments (rotation, reset, clock, data), instead of the order you use of (rotation, clock, data, reset).

class U8G2_ST7567_ENH_DG128064I_1_HW_I2C : public U8G2 {
  public: U8G2_ST7567_ENH_DG128064I_1_HW_I2C(const u8g2_cb_t *rotation, uint8_t reset = U8X8_PIN_NONE, uint8_t clock = U8X8_PIN_NONE, uint8_t data = U8X8_PIN_NONE) : U8G2() {
    u8g2_Setup_st7567_i2c_enh_dg128064i_1(&u8g2, rotation, u8x8_byte_arduino_hw_i2c, u8x8_gpio_and_delay_arduino);
    u8x8_SetPin_HW_I2C(getU8x8(), reset, clock, data);
  }
};

Hi.
I have tried to delete:

 u8g2.clearBuffer();

and move in the setup.

  u8g2.setFont(u8g2_font_ncenB14_tr);

but the sketch crash again.
i think that is a proble of i2c connection.

If you have any other clues I would be very happy.
the constructor works well and immediately shows no problems at startup.
Thanks so much

So you do initially see the numbers on the display?

Have you tried with the I2C bus running at a lower speed?
How long are the wires between the nano and the display?
You are saturating the I2C bus with nearly constant usage, so that should show up any weaknesses in the communications with the display fairly quickly.

Had to look that one up, that is just the way the library function is implemented:

Hi.
i have tried the luetee library and these are more stable, i have tried the schetck for more one hour and it. The schetck not crasched.

#include"lcd_st7567s.h"
lcd_st7567s Lcd;

int x=0;
char myString[] = {72};

void setup() 
{
  Lcd.Init();
}
void loop() {
  Lcd.Cursor(x, x);      
  Lcd.Display(myString); 
  Lcd.Cursor(10, 10);      
  Lcd.Display(x);         
  x=x+1;
  if (x>8)
  {
    x=0;
    Lcd.Clear(false);
  }
  delay (5);
}

now i have another problem i cn not show the number. i can show the x variable but i have a problem.

Also i can not change the dimension of the font.
can you help me?
thanks so much

I solved!
the solution is very simple, as he wrote @david_2018 david_2018](Profile - david_2018 - Arduino Forum) the speed was oo fast.

The problem is only due to unstable I2C communication.

It was too fast, and I first tried to set it to 100000 which was very stable then I tried to set it to 200000 which is just as stable.

The schetck has been working for hours without interruption.
A big thank you to everyone.

The final schetck.

#include <U8g2lib.h>
#include <Wire.h>

U8G2_ST7567_ENH_DG128064I_1_HW_I2C u8g2(U8G2_R0, SCL, SDA, U8X8_PIN_NONE);  // LCD GRANDE

void setup()
{
  u8g2.setI2CAddress(0x3F * 2); 
  u8g2.setBusClock(200000);
  u8g2.begin();
  u8g2.setFont(u8g2_font_ncenB14_tr);
}
  
void loop()
{

u8g2.firstPage();
  do {
   
      u8g2.setCursor(25, 23); 
      u8g2.print(x);
      
  } while ( u8g2.nextPage() );   
  x = x +1; 
  if (x > 500)
  { 
    x=0;
  }
}

Hi everyone.
I sold the bear skin too soon....

The GM12864-59N display with ST7567S-based unfortunately still turns off without apparent logic.
I thought I had little sram memory, since the arduino nano only has 2K, and the <U8g2lib.h> library uses a lot of it.

So I measured memory consumption using the <FreeMemory.h> library.

Arduino nano returns a value of 1201 free bites
Arduino mega 2560 returns a value of 7500 free bits.

so I think it's not a low memory problem.

Then I used the same sketch on the Arduino Nano 33 IoT and it works perfectly.
I removed the level translator because the Arduino nano 33 iot works at 3.3V and therefore compatible with the GM12864-59N display.
It ran for a few days without any sign of stopping. I turned it on and off several times to check the stability of the system.
The system is very stable.

Now the problem is that with the Arduino nano it freezes, and I've tried everything but I can't get it to work.
My project and the pcb I created only use arduino nano and I can't use other types of arduino.
I ran out of cartridges at my disposal.

Do you have suggestions?
Thank you.

Get the Nano Every, it's pin compatible with old Nano. And it got more program memory, is faster, etc etc.

Hi, yes it is a good alternative, but I would like to find a solution for the Arduino Nano also because I already have several at home.

However, alternatively if I can't solve the problem I will use your suggestion.
Thanks so much

Gotcha.

Do you run this check at regular interval?

Hi.
yes, the measurement of the amount of free memory is done every time the schematic sends the value to print on the LCD using u8g2.print(x);.

So once every cycle

Does the amount of free ram change between?

Hi.
The memory free is 1386 bite.
Every cicle the reas is the same.

the schetck is:

#include <U8g2lib.h>
#include <Wire.h>
#include <MemoryFree.h>

int x=0;

U8G2_ST7567_ENH_DG128064I_1_HW_I2C u8g2(U8G2_R0, SCL, SDA, U8X8_PIN_NONE); 

void setup()
{
  u8g2.setI2CAddress(0x3F * 2); 
  u8g2.setBusClock(200000);
  u8g2.begin();
  u8g2.setFont(u8g2_font_ncenB14_tr);
}
  
void loop()
{

u8g2.firstPage();
  do {
   
      u8g2.setCursor(25, 23); 
      u8g2.print(x);
      u8g2.setCursor(25, 55);
      u8g2.print(freeMemory());    
      
  } while ( u8g2.nextPage() );   
  x = x +1; 
  if (x > 500)
  { 
    x=0;
  }
}

What type of level translator are you using? How are you powering the display? I don't see anything in the code that would be causing a memory issue.

Good, this means your sketch doesn't have a memory leak.