how to clear previous characters with u8g

hi
I’m using a 1.3 oled display with 4 wires.
I want to read the value on port A0.
I read and print the result. so far so good.
when I print the second reading the previous is not erased. so I get bizar results on the screen.

anybody knows whats wrong ?

thanks
Jean-Marie

#include <SoftwareSerial.h>

#include <U8glib.h>

#define OLED_RESET 4
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_DEV_0 | U8G_I2C_OPT_FAST); // Dev 0, Fast I2C / TWI
void setup()
{

  pinMode(A0, INPUT);
  u8g.firstPage();
  do {
    u8g.setFont(u8g_font_helvB12r);
    u8g.drawStr(5, 22, "POWER METER");
    u8g.drawStr(5, 52, "  by ON7EN");
  } while ( u8g.nextPage() );
  delay(1000);                // Wait 3 seconds
}


void loop() {
  u8g.firstPage();
  do {// the loop routine runs over and over again forever:
    //int P=0;
   
    u8g.setFont(u8g_font_helvB18);
    float sensorValue = analogRead(A0);// read the input on analog pin 0:
    float voltage = sensorValue * (5 / 1023.0);  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
    double dBm = (40 * voltage / 2 - 40); // calculate dBm
    double P = pow( 10.0, (dBm - 30.0) / 10.0);
    //Serial.print(voltage); Serial.print(" V    ");Serial.print(dBm);Serial.print("dBm   //");Serial.print(P);Serial.println("W");// print result
   

    u8g.setPrintPos(25, 25);
    u8g.print(P, 3);
    u8g.setPrintPos(95, 25);
    u8g.print("W");
    u8g.setFont(u8g_font_helvB12r);
    u8g.setPrintPos(55, 55);
    u8g.print(dBm,0);
    u8g.setPrintPos(75, 55);
    u8g.print("dBm");
    
  } while ( u8g.nextPage() );
delay(1000);


}
void loop() {
    float sensorValue = analogRead(A0);// read the input on analog pin 0:
    float voltage = sensorValue * (5 / 1023.0);  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
    double dBm = (40 * voltage / 2 - 40); // calculate dBm
    double P = pow( 10.0, (dBm - 30.0) / 10.0);
    //Serial.print(voltage); Serial.print(" V    ");Serial.print(dBm);Serial.print("dBm   //");Serial.print(P);Serial.println("W");// print result

  u8g.firstPage();
  do {// the loop routine runs over and over again forever:
    //int P=0;
   
    u8g.setFont(u8g_font_helvB18);
   

    u8g.setPrintPos(25, 25);
    u8g.print(P, 3);
    u8g.setPrintPos(95, 25);
    u8g.print("W");
    u8g.setFont(u8g_font_helvB12r);
    u8g.setPrintPos(55, 55);
    u8g.print(dBm,0);
    u8g.setPrintPos(75, 55);
    u8g.print("dBm");
   
  } while ( u8g.nextPage() );
delay(1000);

Set the variables outside the picture loop, do not modify variables inside the picture loop.

Consider to use U8g2, I do not support U8glib any more.

Oliver

thanks Oliver for your help
now it works like i wanted it

i will convert it to u8g2