Exemple d'utilisation de l'écran des TTGO

Un petit tuto pas à pas pour jouer avec l'écran Oled des TTGO. On retrouvera le code sur le gitlab de l'ENSEEIHT (git@gitlab.enseeiht.fr:chaput/DemoOledTTGO.git).

Création du projet

On se crée un projet pour la bonne cible

$ mkdir DemoOledTTGO
$ cd DemoOledTTGO
$ pio project init --board ttgo-lora32-v2

On installe les libraires nécessaires

pio lib install "adafruit/Adafruit SSD1306"
pio lib install "adafruit/Adafruit BusIO"

Écriture du code

/*
 * Les includes nécessaires
 */
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

/*
 * Le brochage du bus de l'écran
 */
#define SDA_PIN 21
#define SCL_PIN 22 

/*
 * Les caractéristiques de l'écran
 */
#define LARGEUR_OLED 128
#define HAUTEUR_OLED 64

/*
 * Déclaration de l'écran
 */
Adafruit_SSD1306 ecranOled(LARGEUR_OLED, HAUTEUR_OLED, &Wire);

void setup() {
   Serial.begin(115200);

   // Initialisation de l'écran
   Wire.begin(SDA_PIN, SCL_PIN);
   if(!ecranOled.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)) {
      Serial.println(F("SSD1306 allocation failed"));
      while(1){};
   }

   // Affichage d'un message profond 
   ecranOled.clearDisplay();
   ecranOled.setTextColor(SSD1306_WHITE);
   ecranOled.setTextSize(1);
   ecranOled.setCursor(0,0);
   ecranOled.print("Salut le monde ! ");
   ecranOled.display();

}

void loop() {
   delay(1000);
}

Compilation et exécution

On compile la chose et, comme on y croit, on le lance :

pio run --target upload

C'est magnifique !