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();
}