oled i2c 128x64 ( and 128x128 after) and u8g2 librarie

Hello

I have screen oled i2c 128 x 64 (oled i2c 128 x 128 in second time)
and i want use the u8g2 library.

Here for the setup and the screen

fonts fntlistall · olikraus/u8g2 Wiki · GitHub
screen u8g2setupc · olikraus/u8g2 Wiki · GitHub

When I compile the code no problems
But there is nothing on the screen.

I am sure not to have taken the good screen.

Please, Could You tell me which one to take ?

1 for screen oled 128x64
https://fr.aliexpress.com/item/Free-shipping-Yellow-blue-double-color-128X64-OLED-LCD-LED-Display-Module-For-Arduino-0-96/32665937977.html?spm=a2g0s.9042311.0.0.40696c37tiM4rl

2 for screen oled 128x128 ( for my second project)

Thank you at all

The screen is connecting like this.
It works with addafruit Library.
(See the second code which works, Writing on the screen)

VCC / +5
GND / GND
SCL / A5
SDA / A4

The code is original code of the library.

My code

// Pour l'écran
#include <Arduino.h>
#include <U8g2lib.h>


// pour les fontes  https://github.com/olikraus/u8g2/wiki/fntlistall
// poue l'écran     https://github.com/olikraus/u8g2/wiki/u8g2setupc


// Déclaratipon de l'écran 128x64
U8G2_SSD1306_128X64_NONAME_2_SW_I2C u8g2 (U8G2_R0, A5, A4);

// Déclaration de l'écran 128x128 à venir
/* Constructor */
//U8G2_SSD1327_EA_W128128_1_SW_I2C(U8G2_R0, A5, A4);
// si ne marche pas :
//U8G2_SSD1327_MIDAS_128X128_1_SW_I2C(U8G2_R0, A5, A4);


void setup(void)
{
  /* U8g2 Project: SSD1306 Test Board */
  pinMode(A4, OUTPUT);
  digitalWrite(A4, 0);
  u8g2.begin();
  u8g2.setPowerSave(0);




}

void loop(void)
{
u8g2.serial.print (test);

 // modele d'écriture
  u8g2.setFont(u8g2_font_ncenB14_tr);
  u8g2.setCursor(0, 15);
  u8g2.print("Hello World!");



}

Code addafruit

#include <DallasTemperature.h>     //DS18B20 pour température de l'eau et de l'air
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>



  //les librairies de l'écran
  //https://github.com/adafruit/Adafruit_SSD1306
  //https://github.com/adafruit/Adafruit-GFX-Library

// les branchements

//  L'écran OLED
#define OLED_RESET 8          // pin 8 'virtuel' ?                                  
Adafruit_SSD1306 display(OLED_RESET);

//définition de la taille de l'écran
#define SSD1306_128_64 

// les 2 sondes DS18B20
#define ONE_WIRE_BUS_1 2               // sonde pour l'eau pin 2 
#define ONE_WIRE_BUS_2 4               // sonde pour l'air pin 4
OneWire oneWire_in(ONE_WIRE_BUS_1);    // sonde pour l'eau
OneWire oneWire_out(ONE_WIRE_BUS_2);   // sonde pour l'air
DallasTemperature sensor_eau(&oneWire_in);     // sonde pour l'eau
DallasTemperature sensor_air(&oneWire_out);    // sonde pour l'air


// OLED display TWI address
#define OLED_ADDR   0x3C 




void setup() {
  // initialize and clear display
  display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);//   programme scanner
  display.clearDisplay();
  display.display();

  // start serial port
  Serial.begin(115200);
  Serial.println("Dallas Temperature Control Library Demo - TwoPin_DS18B20");

  // Start up the library
  sensor_eau.begin();    // sonde pour l'eau
  sensor_air.begin();    // sonde pour l'air

  // déclaration de la pin 2 et 4
  pinMode(2, INPUT);
  pinMode(4, INPUT);

  int readValEau = analogRead(2);// met à zéro la sonde EAU
  int readValAir = analogRead(4);// met à zéro la sonde AIR
}


void loop() {
  // AFFICHAGE SUR SERIAL
  Serial.print("Recherceh des temperatures...");
  sensor_eau.requestTemperatures();
  sensor_air.requestTemperatures();
  Serial.println(" done");

  // sonde EAU
  Serial.print("Température eau: ");
  Serial.println(sensor_eau.getTempCByIndex(0));

  // sonde AIR
  Serial.print("Température air: ");
  Serial.println(sensor_air.getTempCByIndex(0));




  // AFFICHAGE SUR ECRAN
  delay(1);//delay time 1 milli second
  display.clearDisplay();

  display.setTextSize(1);//text size
  display.setTextColor(WHITE);//text color
  display.setCursor(0, 0);
  display.println("NIVEAU BATTERIE");//affiche texte 1ere ligne 8 pixels
  //*****************************
  //display.setTextColor(BLACK, WHITE);
  //display.println(); // affiche une ligne noire
  //*****************************
  
  // Affichage sur la même ligne des 2 températures Air et Eau
  display.setTextSize(1);//text size        // mettre 2 pour 16 pixels
  display.setCursor(0, 42);                 // position du curseur
  display.print("TEMP. AIR   ");//affiche texte 1ere ligne 8 pixels
  //display.print( temp );                    // ici on met la 1° température air(sonde étanche)(pin4)
  display.println(sensor_air.getTempCByIndex(0));
  display.print("'");                       //Affichage du symbole <C>
  display.print("C");                       //Affichage du symbole <C>

  display.setTextSize(1);//text size        // mettre 2 pour 16 pixels
  display.setCursor(0, 57);                 // position du curseur
  display.print("TEMP. EAU   ");//affiche texte 1ere ligne 8 pixels
  //display.print(dTempWater);              // ici on met la 2° température eau (sonde étanche)(pin2)
  display.println(sensor_eau.getTempCByIndex(0));
  display.print("'");                       //Affichage du symbole <C>
  display.print("C");                       //Affichage du symbole <C>
  delay(500);                               // Attente 0,5 sec pour réactualiser


  // pour le voltage de la batterie
  // Conversion du signal (which goes from 0 - 1023) to a voltage (0 - (V):
  int sensorValue = analogRead(A0);//*******************************************************  A3 pour la voiture bateau
  // écrit la valeur lue
  float voltage = sensorValue * (5.0 / 1023.0);
  display.setTextSize(1);//text size         // mettre 2 pour 16 pixels
  display.setCursor(0, 16);
  display.print(voltage);
  display.print(" V");
  display.display();


}

Your 128x64 is SSD1306
Your 128x128 is SSD1327

If you really are using a Uno, you will have to use the restricted buffers constructor e.g.

U8G2_SSD1306_128X64_NONAME_1_HW_I2C(rotation, [reset [, clock, data]]) page buffer, size = 128 bytes


U8G2_SSD1327_MIDAS_128X128_1_HW_I2C(rotation, [reset [, clock, data]]) page buffer, size = 128 bytes

There appear to be a MIDAS and a EA version. Oliver can explain the difference.

You must use different I2C addresses for each display if you are using both in the same project.

David.

thank you

I try this

U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2 (U8G2_R0, A5, A4);

I compile the code no problems
But there is nothing on the screen too.

I use this with a regular Ebay I2C display.

//use full 1024 byte buffer
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

Life is simpler with a Full Buffer. But Oliver's examples should all work with restricted buffers e.g. the 1 and 2 alternatives to the F

You have omitted the reset argument. I certainly would not specify the SDA, SCL pins in the constructor.
But it should not matter if you use the full-fat constructor e.g.

U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2 (U8G2_R0, U8X8_PIN_NONE, A5, A4);

You have specified some "other" constructor.

I chose the most appropriate constructor from the long choice in Oliver's examples.

David.

@ArduinoFree

Will the HelloWorld U8g2 Library Example work for your?
Your code, posted initially, will not work. It neither has the page-while loop nor a send buffer command.

Oliver

olikraus:
@ArduinoFree

Will the HelloWorld U8g2 Library Example work for your?
Your code, posted initially, will not work. It neither has the page-while loop nor a send buffer command.

Oliver

I am tall beginning and I took this example by thinking that it worked.
The example Don't work.

I try David's code, it Don't work.

// Pour l'écran
#include <Arduino.h>
#include <U8g2lib.h>


// pour les fontes  https://github.com/olikraus/u8g2/wiki/fntlistall
// poue l'écran     https://github.com/olikraus/u8g2/wiki/u8g2setupc


// Déclaratipon de l'écran 128x64
//use full 1024 byte buffer
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);


void setup(void)
{
  /* U8g2 Project: SSD1306 Test Board */
  pinMode(A4, OUTPUT);
  digitalWrite(A4, 0);
  u8g2.begin();
  u8g2.setPowerSave(0);

}

void loop(void)
{


 // modele d'écriture
  u8g2.setFont(u8g2_font_ncenB14_tr);
  u8g2.setCursor(0, 15);
  u8g2.print("Hello World!");



}

It's work

thank you at all

Here the code

// For screen
#include <Arduino.h>
#include <U8g2lib.h>


//screen libraries
// pour les fontes  https://github.com/olikraus/u8g2/wiki/fntlistall
// poue l'écran     https://github.com/olikraus/u8g2/wiki/u8g2setupc


// screen oled i2c  128x64 Declaration
U8G2_SSD1306_128X64_NONAME_2_SW_I2C u8g2 (U8G2_R0, A5, A4);




void setup(void)
{
  /* U8g2 Project: SSD1306 Test Board */
  pinMode(A4, OUTPUT);
  digitalWrite(A4, 0);
  u8g2.begin();
  u8g2.setPowerSave(0);
}


void loop(void)
{
  int sensorValue = analogRead(A0); //A0
  u8g2.firstPage();
  do {
    // Your code
    //modele d'écriture
    u8g2.setFont(u8g2_font_ncenB14_tr);
    u8g2.setCursor(0, 15);
    u8g2.print("Hello World!");



  } while ( u8g2.nextPage() );

}

This sketch will show you how the screen is written.

#include <U8g2lib.h>

// screen oled i2c  128x64 Declaration
U8G2_SSD1306_128X64_NONAME_2_SW_I2C u8g2 (U8G2_R0, A5, A4);

// A5, A4 on a Uno are hardware SCL, SDA pins
//U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2 (U8G2_R0);
//U8G2_SSD1306_128X64_NONAME_2_HW_I2C u8g2 (U8G2_R0);
//U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2 (U8G2_R0);

void setup(void)
{
    /* U8g2 Project: SSD1306 Test Board */
    pinMode(A4, OUTPUT);
    digitalWrite(A4, 0);
    u8g2.begin();
    u8g2.setPowerSave(0);
    //modele d'écriture
    u8g2.setFont(u8g2_font_ncenB14_tr);
}

void loop(void)
{
    u8g2.firstPage();
    do {
        u8g2.setCursor(0, 20);
        u8g2.print("Hello World!");
        u8g2.setCursor(0, 40);
        u8g2.print("Buffered");
        u8g2.setCursor(0, 60);
        u8g2.print("Page Writes");
        delay(500);
    } while ( u8g2.nextPage() );
    //draw empty screen
    u8g2.firstPage();
    do {
        delay(500);
    } while ( u8g2.nextPage() );
}

Now try the other constructors. You can see the difference.

Life is easier with the F full-size buffer. But the firstPage(), nextPage() sequence is useful when you are short of SRAM memory.

If you are wired to the hardware I2C pins, it is better to use the _HW_I2C constructors.

David.

thank you for explain of next pages