Arduino Nano - Écran OLED SSD1309 128x64 | Tutoriel OLED I2C 2.42 pouces

Un écran OLED (Organic Light-Emitting Diode) offre des pixels auto-émissifs qui fournissent des noirs profonds, un contraste élevé et de larges angles de vision — ce qui en fait une excellente amélioration par rapport aux écrans LCD traditionnels. Le SSD1309 est le circuit intégré pilote couramment trouvé sur les modules OLED I2C de 2.42 pouces (parfois étiquetés 2.4 pouces) 128×64.

Dans ce guide étape par étape, vous apprendrez comment connecter et programmer l'écran OLED SSD1309 128×64 avec une carte Arduino Nano en utilisant la bibliothèque DIYables_OLED_SSD1309. Plus précisément, nous couvrirons :

Matériel requis

1×Official Arduino Nano
1×Alternativement: DIYables ATMEGA328P Nano Development Board
1×Câble USB A vers Mini-B USB
1×Écran OLED I2C SSD1309 128x64 (2.42 pouces)
1×Fils de connexion
1×Recommandé: Carte d'extension à bornier à vis pour Arduino Nano
1×Recommandé: Carte d'extension breakout pour Arduino Nano
1×Recommandé: Répartiteur d'alimentation pour Arduino Nano

Ou vous pouvez acheter les kits suivants:

1×Kit de Capteurs DIYables (30 capteurs/écrans)
1×Kit de Capteurs DIYables (18 capteurs/écrans)
Divulgation : Certains des liens fournis dans cette section sont des liens affiliés Amazon. Nous pouvons recevoir une commission pour tout achat effectué via ces liens, sans coût supplémentaire pour vous. Nous vous remercions de votre soutien.

À propos de l'écran OLED SSD1309 2.42 pouces

Le SSD1309 est un circuit intégré pilote OLED CMOS sur puce unique conçu pour les panneaux à matrice de points 128×64. Il est compatible au niveau des registres avec le SSD1306 largement utilisé, donc de nombreux exemples de code existants peuvent être transférés avec des modifications minimales. Les principales différences matérielles sont :

  • Pas de pompe de charge intégrée — le SSD1309 nécessite un rail VCC externe, bien que pratiquement toutes les cartes de développement (y compris les modules 2.42 pouces et 2.4 pouces) soient livrées avec un convertisseur boost intégré, donc cela est transparent pour vous.
  • Tolérance de tension plus élevée — le SSD1309 accepte jusqu'à 16 V VCC, tandis que le SSD1306 est limité à environ 4.2 V.

Le module OLED 2.42 pouces (2.4 pouces) utilise couramment le pilote SSD1309 et dispose d'une résolution de 128×64 pixels avec interface I2C. La couleur du panneau (blanc, bleu, jaune, vert ou double zone) est déterminée par le matériau OLED physique et n'est pas contrôlable par logiciel.

Ce tutoriel communique avec l'écran via le bus I2C, qui ne nécessite que deux fils de signal (SDA et SCL) et peut partager le bus avec d'autres périphériques I2C.

Brochage de l'écran OLED SSD1309 (Module I2C)

  • Broche GND : Celle-ci doit être connectée à la masse de l'Arduino Nano.
  • Broche VCC : Il s'agit de l'alimentation pour l'écran qui doit être connectée au 5V.
  • Broche SCL : Il s'agit d'une broche d'horloge série pour l'interface I2C. Connecter à A5.
  • Broche SDA : Il s'agit d'une broche de données série pour l'interface I2C. Connecter à A4.
SSD1309 OLED Pinout

※ Note:

  • Les broches du module OLED peuvent différer selon le fabricant et le type. Veuillez utiliser les étiquettes imprimées sur le module OLED. Veuillez regarder attentivement !
  • Ce tutoriel utilise l'écran OLED qui est piloté par le pilote I2C SSD1309. Nous l'avons testé avec l'écran OLED de DIYables et il fonctionne parfaitement.

Schéma de câblage

  • Schéma de câblage entre Arduino Nano et écran OLED SSD1309 128x64
Arduino Nano SSD1309 OLED wiring diagram

Cette image a été créée avec Fritzing. Cliquez pour agrandir l'image.

Voir Comment alimenter un Arduino Nano..

Le tableau de câblage entre Arduino Nano et l'écran OLED SSD1309 :

Module OLED Arduino Nano
VCC 5V
GND GND
SDA A4
SCL A5

Comment programmer l'Arduino Nano pour l'écran OLED SSD1309

Installer la bibliothèque DIYables_OLED_SSD1309

La bibliothèque DIYables_OLED_SSD1309 est spécialement conçue pour les écrans SSD1309 et étend Adafruit_GFX pour un support graphique plus riche.

  • Cliquez sur l'icône Libraries dans la barre de gauche de l'IDE Arduino.
  • Recherchez DIYables_OLED_SSD1309, puis cherchez la bibliothèque DIYables OLED SSD1309 par DIYables
  • Cliquez sur le bouton Install pour installer la bibliothèque DIYables_OLED_SSD1309.
Arduino Nano SSD1309 OLED library
  • Il vous sera demandé d'installer les dépendances pour la bibliothèque
  • Installez toutes les dépendances en cliquant sur le bouton Install All.
Arduino Nano Adafruit GFX library

Étapes de programmation

  1. Inclure les bibliothèques requises
#include <Wire.h> #include <Adafruit_GFX.h> #include <DIYables_OLED_SSD1309.h>
  1. Définir les dimensions de l'écran
#define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64
  1. Déclarer l'objet d'affichage
#define OLED_RESET -1 // Reset pin not used on most I2C modules #define SCREEN_ADDRESS 0x3C DIYables_OLED_SSD1309 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
  1. Initialiser l'OLED dans setup()
if (!display.begin(SSD1309_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1309 allocation failed")); for (;;); // halt }
  1. Afficher le contenu
display.clearDisplay(); display.setTextSize(2); display.setTextColor(SSD1309_PIXEL_ON); display.setCursor(0, 20); display.println(F("Hello Nano")); display.display(); // push buffer to screen

Code Arduino Nano — Hello World sur écran OLED SSD1309

Le point de départ le plus simple : imprimer quelques lignes de texte à différentes tailles.

/* * Ce code Arduino Nano a été développé par newbiely.fr * Ce code Arduino Nano est mis à disposition du public sans aucune restriction. * Pour des instructions complètes et des schémas de câblage, veuillez visiter: * https://newbiely.fr/tutorials/arduino-nano/arduino-nano-ssd1309-oled-display */ /* * DIYables OLED SSD1309 – Hello World * Prints text in two sizes on the 2.42 inch 128x64 I2C OLED with Arduino Nano. */ #include <Wire.h> #include <Adafruit_GFX.h> #include <DIYables_OLED_SSD1309.h> #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 #define SCREEN_ADDRESS 0x3C DIYables_OLED_SSD1309 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); void setup() { Serial.begin(9600); if (!display.begin(SSD1309_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1309 allocation failed")); for (;;); } display.clearDisplay(); display.setTextSize(1); // 6x8 pixels per character display.setTextColor(SSD1309_PIXEL_ON); // turn pixels on display.setCursor(0, 0); display.println(F("Hello, World!")); display.println(); display.setTextSize(2); // 12x16 pixels per character display.println(F("DIYables")); display.setTextSize(1); display.println(); display.println(F("SSD1309 OLED 128x64")); display.display(); // push buffer to screen } void loop() { }

Code Arduino Nano — Afficher du texte sur écran OLED SSD1309

L'exemple suivant démontre plus de fonctionnalités de texte — plusieurs tailles, formatage de nombres, et la macro F() pour économiser la RAM.

/* * Ce code Arduino Nano a été développé par newbiely.fr * Ce code Arduino Nano est mis à disposition du public sans aucune restriction. * Pour des instructions complètes et des schémas de câblage, veuillez visiter: * https://newbiely.fr/tutorials/arduino-nano/arduino-nano-ssd1309-oled-display */ /* * DIYables OLED SSD1309 – Display Text * Displays text in various sizes and formats on the 2.42" SSD1309 OLED with Arduino Nano. */ #include <Wire.h> #include <Adafruit_GFX.h> #include <DIYables_OLED_SSD1309.h> #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 #define SCREEN_ADDRESS 0x3C DIYables_OLED_SSD1309 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); void setup() { Serial.begin(9600); if (!display.begin(SSD1309_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1309 allocation failed")); for (;;); } display.clearDisplay(); // Various text sizes display.setTextSize(1); display.setTextColor(SSD1309_PIXEL_ON); display.setCursor(0, 0); display.println(F("Size 1 - DIYables")); display.setTextSize(2); display.println(F("Size 2")); display.setTextSize(3); display.println(F("Sz3")); display.display(); delay(3000); // Number formatting display.clearDisplay(); display.setTextSize(1); display.setCursor(0, 0); int value = 42; float pi = 3.14159; display.print(F("Integer: ")); display.println(value); display.print(F("Float: ")); display.println(pi, 2); // 2 decimal places display.print(F("Hex: 0x")); display.println(value, HEX); display.print(F("Binary: 0b")); display.println(value, BIN); display.display(); } void loop() { }

Référence des fonctions d'affichage utiles

Voici une liste de référence rapide des fonctions les plus fréquemment utilisées lors du travail avec l'écran OLED SSD1309 via la bibliothèque DIYables :

  • oled.clearDisplay() — efface le tampon de trame (tous les pixels éteints).
  • oled.display() — transfère le tampon vers l'OLED pour que les changements deviennent visibles.
  • oled.drawPixel(x, y, color) — définit ou efface un pixel individuel.
  • oled.setTextSize(n) — met à l'échelle la police par facteur *n* (1 = 6×8, 2 = 12×16, …, jusqu'à 8).
  • oled.setCursor(x, y) — déplace le curseur de texte aux coordonnées de pixel *(x, y)*.
  • oled.setTextColor(SSD1309_PIXEL_ON) — premier plan du texte uniquement (arrière-plan transparent).
  • oled.setTextColor(SSD1309_PIXEL_OFF, SSD1309_PIXEL_ON) — texte avec une couleur d'arrière-plan explicite.
  • oled.println("message") — imprime une chaîne et avance à la ligne suivante.
  • oled.println(number) — imprime un entier en décimal.
  • oled.println(number, HEX) — imprime un entier en hexadécimal.
  • oled.startscrollright(start, stop) — défilement matériel vers la droite entre la page *start* et la page *stop*.
  • oled.startscrollleft(start, stop) — défilement matériel vers la gauche.
  • oled.startscrolldiagright(start, stop) — défilement matériel en diagonal vers la droite.
  • oled.startscrolldiagleft(start, stop) — défilement matériel en diagonal vers la gauche.
  • oled.stopscroll() — arrête tout défilement matériel actif.
  • oled.setContrast(value) — ajuste la luminosité de l'écran (0–255).
  • oled.dim(true/false) — réduit rapidement l'écran au minimum ou restaure le contraste précédent.
  • oled.invertDisplay(true/false) — inversion des couleurs au niveau matériel (pixels allumés ↔ pixels éteints).

Comment centrer verticalement et horizontalement le texte sur l'écran OLED SSD1309

Voir Comment centrer verticalement/horizontalement sur OLED

Code Arduino Nano — Dessiner des formes sur écran OLED SSD1309

Parce que la bibliothèque DIYables_OLED_SSD1309 étend Adafruit_GFX, vous obtenez un ensemble complet de primitives de dessin de formes : pixels, lignes, rectangles, rectangles remplis, cercles, cercles remplis, triangles, triangles remplis, et rectangles arrondis. Le sketch ci-dessous parcourt toutes ces formes avec des démonstrations animées.

/* * Ce code Arduino Nano a été développé par newbiely.fr * Ce code Arduino Nano est mis à disposition du public sans aucune restriction. * Pour des instructions complètes et des schémas de câblage, veuillez visiter: * https://newbiely.fr/tutorials/arduino-nano/arduino-nano-ssd1309-oled-display */ /* * DIYables OLED SSD1309 – Draw Shapes * Demonstrates drawing pixels, lines, rectangles, circles, and triangles on the 2.42" OLED with Arduino Nano. */ #include <Wire.h> #include <Adafruit_GFX.h> #include <DIYables_OLED_SSD1309.h> #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 #define SCREEN_ADDRESS 0x3C DIYables_OLED_SSD1309 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); void setup() { Serial.begin(9600); if (!display.begin(SSD1309_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1309 allocation failed")); for (;;); } display.clearDisplay(); display.display(); } void loop() { // Draw pixels display.clearDisplay(); for (int i = 0; i < 20; i++) { display.drawPixel(random(SCREEN_WIDTH), random(SCREEN_HEIGHT), SSD1309_PIXEL_ON); } display.display(); delay(2000); // Draw lines display.clearDisplay(); for (int y = 0; y < SCREEN_HEIGHT; y += 8) { display.drawLine(0, 0, SCREEN_WIDTH - 1, y, SSD1309_PIXEL_ON); } display.display(); delay(2000); // Draw rectangles display.clearDisplay(); display.drawRect(10, 10, 40, 30, SSD1309_PIXEL_ON); // outline display.fillRect(60, 10, 40, 30, SSD1309_PIXEL_ON); // filled display.drawRoundRect(10, 45, 40, 15, 5, SSD1309_PIXEL_ON); // rounded corners display.display(); delay(2000); // Draw circles display.clearDisplay(); display.drawCircle(32, 32, 20, SSD1309_PIXEL_ON); // outline display.fillCircle(96, 32, 20, SSD1309_PIXEL_ON); // filled display.display(); delay(2000); // Draw triangles display.clearDisplay(); display.drawTriangle(20, 10, 10, 50, 30, 50, SSD1309_PIXEL_ON); // outline display.fillTriangle(90, 10, 70, 50, 110, 50, SSD1309_PIXEL_ON); // filled display.display(); delay(2000); }

Code Arduino Nano — Défilement matériel sur écran OLED SSD1309

Le SSD1309 a un moteur de défilement intégré qui décale le contenu de l'écran sans aucune charge CPU. La bibliothèque DIYables expose quatre directions de défilement : droite, gauche, diagonal-droite, et diagonal-gauche. Chacune prend un paramètre de page de début et page de fin (les pages sont des bandes horizontales de 8 pixels de haut numérotées 0–7 sur un écran de 64 pixels de haut).

※ Note:

Appelez toujours display() pour pousser votre contenu vers l'OLED avant de commencer un défilement. Évitez de dessiner du nouveau contenu pendant que le défilement est actif — appelez d'abord stopscroll().

/* * Ce code Arduino Nano a été développé par newbiely.fr * Ce code Arduino Nano est mis à disposition du public sans aucune restriction. * Pour des instructions complètes et des schémas de câblage, veuillez visiter: * https://newbiely.fr/tutorials/arduino-nano/arduino-nano-ssd1309-oled-display */ /* * DIYables OLED SSD1309 – Scroll Text * Demonstrates all four hardware scroll directions on the 2.42" OLED with Arduino Nano. */ #include <Wire.h> #include <Adafruit_GFX.h> #include <DIYables_OLED_SSD1309.h> #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 #define SCREEN_ADDRESS 0x3C DIYables_OLED_SSD1309 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); void setup() { Serial.begin(9600); if (!display.begin(SSD1309_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1309 allocation failed")); for (;;); } display.clearDisplay(); display.setTextSize(2); display.setTextColor(SSD1309_PIXEL_ON); display.setCursor(10, 24); display.println(F("DIYables")); display.display(); delay(2000); } void loop() { // Scroll right across all pages display.startscrollright(0x00, 0x07); delay(3000); display.stopscroll(); delay(500); // Scroll left display.startscrollleft(0x00, 0x07); delay(3000); display.stopscroll(); delay(500); // Diagonal scroll right display.startscrolldiagright(0x00, 0x07); delay(3000); display.stopscroll(); delay(500); // Diagonal scroll left display.startscrolldiagleft(0x00, 0x07); delay(3000); display.stopscroll(); delay(500); }

Code Arduino Nano — Afficher une image bitmap sur écran OLED SSD1309

Pour afficher un bitmap sur l'écran OLED SSD1309, vous devez d'abord convertir votre image en un tableau de bytes C. Utilisez l'outil gratuit en ligne image2cpp pour cette conversion :

  1. Téléversez votre fichier image (PNG, JPG, BMP, etc.).
  2. Définissez la taille du canvas à 128×64 (ou plus petit).
  3. Choisissez Arduino code comme format de sortie.
  4. Copiez le tableau généré dans votre sketch.
image to bitmap array

L'exemple ci-dessous alterne entre une icône de cœur 16×16 et un logo DIYables pleine largeur :

/* * Ce code Arduino Nano a été développé par newbiely.fr * Ce code Arduino Nano est mis à disposition du public sans aucune restriction. * Pour des instructions complètes et des schémas de câblage, veuillez visiter: * https://newbiely.fr/tutorials/arduino-nano/arduino-nano-ssd1309-oled-display */ /* * DIYables OLED SSD1309 – Display Bitmap Image * Shows a 16x16 heart icon and 128x64 DIYables logo on the 2.42" OLED with Arduino Nano. */ #include <Wire.h> #include <Adafruit_GFX.h> #include <DIYables_OLED_SSD1309.h> #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 #define SCREEN_ADDRESS 0x3C DIYables_OLED_SSD1309 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); // 16x16 heart icon bitmap const unsigned char heart_icon[] PROGMEM = { 0x00, 0x00, 0x0c, 0x30, 0x1e, 0x78, 0x3f, 0xfc, 0x7f, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xfe, 0x3f, 0xfc, 0x1f, 0xf8, 0x0f, 0xf0, 0x03, 0xc0, 0x00, 0x00 }; // 128x64 DIYables logo bitmap const unsigned char diyables_logo[] PROGMEM = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x07, 0xff, 0xc1, 0xff, 0xe0, 0x7f, 0xf0, 0x1f, 0xfc, 0x03, 0x00, 0x7f, 0xff, 0xff, 0xfc, 0x00, 0x1f, 0xff, 0xf7, 0xff, 0xf9, 0xff, 0xfc, 0x7f, 0xff, 0x0f, 0x80, 0x3f, 0xff, 0xff, 0xf8, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xfd, 0xff, 0xfe, 0xff, 0xff, 0x9f, 0xc0, 0x1f, 0xff, 0xff, 0xf8, 0x00, 0x7f, 0x80, 0xff, 0x00, 0x7f, 0xc0, 0x3f, 0xf0, 0x0f, 0xfc, 0x00, 0x1f, 0xff, 0xff, 0xf0, 0x00, 0xfe, 0x00, 0x7f, 0x00, 0x3f, 0x80, 0x1f, 0xe0, 0x07, 0xf8, 0x00, 0x0f, 0xff, 0xff, 0xe0, 0x01, 0xfc, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x0f, 0xff, 0xff, 0xe0, 0x03, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x07, 0xff, 0xff, 0xc0, 0x07, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x03, 0xff, 0xff, 0xc0, 0x0f, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x03, 0xff, 0xff, 0x80, 0x0f, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x01, 0xff, 0xff, 0x80, 0x1f, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x01, 0xff, 0xff, 0x00, 0x3f, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x00, 0xff, 0xff, 0x00, 0x3f, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x7f, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x00, 0xff, 0xfe, 0x00, 0x7f, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x00, 0xff, 0xfc, 0x00, 0xff, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x00, 0xff, 0xfc, 0x00, 0xff, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x00, 0xff, 0xfc, 0x01, 0xff, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x00, 0xff, 0xf8, 0x01, 0xff, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x00, 0xff, 0xf8, 0x03, 0xff, 0xf8, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x0f, 0xc0, 0x03, 0xf0, 0x00, 0x00, 0xff, 0xf0, 0x03, 0xff, 0xfc, 0x00, 0x7e, 0x00, 0x1f, 0x80, 0x1f, 0xe0, 0x07, 0xf8, 0x00, 0x00, 0xff, 0xf0, 0x07, 0xff, 0x7f, 0x80, 0xff, 0x00, 0x7f, 0xc0, 0x3f, 0xf0, 0x0f, 0xfc, 0x00, 0x00, 0xff, 0xf0, 0x07, 0xfe, 0x3f, 0xff, 0xff, 0xff, 0xfd, 0xff, 0xfe, 0xff, 0xff, 0x9f, 0xc0, 0x00, 0xff, 0xe0, 0x0f, 0xfc, 0x1f, 0xff, 0xf7, 0xff, 0xf9, 0xff, 0xfc, 0x7f, 0xff, 0x0f, 0x80, 0x00, 0xff, 0xe0, 0x0f, 0xf8, 0x07, 0xff, 0xc1, 0xff, 0xe0, 0x7f, 0xf0, 0x1f, 0xfc, 0x03, 0x00, 0x00, 0xff, 0xe0, 0x1f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x1f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x3f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x80, 0x7f, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x7f, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0xfe, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xfc, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0xf8, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0xf0, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x03, 0xe0, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x07, 0xc0, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x0f, 0x80, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x1f, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x3e, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x7c, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xf8, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x81, 0xf0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0xe0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; void setup() { Serial.begin(9600); if (!display.begin(SSD1309_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1309 allocation failed")); for (;;); } display.clearDisplay(); display.display(); } void loop() { // Display small heart icon centered display.clearDisplay(); display.drawBitmap((SCREEN_WIDTH - 16) / 2, (SCREEN_HEIGHT - 16) / 2, heart_icon, 16, 16, SSD1309_PIXEL_ON); display.display(); delay(3000); // Display full-screen DIYables logo display.clearDisplay(); display.drawBitmap(0, 0, diyables_logo, SCREEN_WIDTH, SCREEN_HEIGHT, SSD1309_PIXEL_ON); display.display(); delay(3000); // Invert display display.invertDisplay(true); delay(2000); display.invertDisplay(false); delay(1000); }

※ Note:

  • Les dimensions du bitmap ne doivent pas dépasser la résolution de l'écran (128×64 pour le module 2.42 pouces).

Code Arduino Nano — Contraste et gradation sur écran OLED SSD1309

Le SSD1309 supporte 256 niveaux de contraste (0–255). La bibliothèque DIYables fournit setContrast() pour un contrôle fin et dim() pour un basculement rapide entre la luminosité minimale et le niveau précédemment configuré.

/* * Ce code Arduino Nano a été développé par newbiely.fr * Ce code Arduino Nano est mis à disposition du public sans aucune restriction. * Pour des instructions complètes et des schémas de câblage, veuillez visiter: * https://newbiely.fr/tutorials/arduino-nano/arduino-nano-ssd1309-oled-display */ /* * DIYables OLED SSD1309 – Contrast & Dim * Sweeps contrast from 0→255→0 then toggles dim mode on the 2.42" OLED with Arduino Nano. */ #include <Wire.h> #include <Adafruit_GFX.h> #include <DIYables_OLED_SSD1309.h> #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 #define SCREEN_ADDRESS 0x3C DIYables_OLED_SSD1309 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); void setup() { Serial.begin(9600); if (!display.begin(SSD1309_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1309 allocation failed")); for (;;); } // Draw a test pattern so the contrast changes are visible display.clearDisplay(); display.fillRect(0, 0, 64, 32, SSD1309_PIXEL_ON); display.fillRect(64, 32, 64, 32, SSD1309_PIXEL_ON); display.setTextSize(1); display.setTextColor(SSD1309_PIXEL_INVERSE); display.setCursor(16, 28); display.println(F("Contrast Demo")); display.display(); delay(2000); } void loop() { // Ramp up for (int c = 0; c <= 255; c += 5) { display.setContrast((uint8_t)c); delay(30); } delay(1000); // Ramp down for (int c = 255; c >= 0; c -= 5) { display.setContrast((uint8_t)c); delay(30); } delay(1000); // Quick dim toggle display.dim(true); // minimum brightness delay(2000); display.dim(false); // restore delay(2000); }

Code Arduino Nano — Polices externes personnalisées sur écran OLED SSD1309

La bibliothèque Adafruit GFX est livrée avec des dizaines de polices de caractères FreeFont évolutives (Serif, Sans, Mono — chacune en Regular, Bold, Italic, et quatre tailles). Vous pouvez activer n'importe laquelle d'entre elles sur l'écran SSD1309 en incluant l'en-tête correspondant et en appelant setFont().

※ Note:

  • Quand une police externe est active, la coordonnée Y du curseur fait référence à la ligne de base du texte, pas au coin supérieur gauche. C'est différent de la police intégrée 5×7.
  • Les polices externes sont stockées en flash (PROGMEM). Sur les cartes AVR à mémoire limitée (Arduino Nano = 32 KB flash), utilisez-les avec parcimonie.
/* * Ce code Arduino Nano a été développé par newbiely.fr * Ce code Arduino Nano est mis à disposition du public sans aucune restriction. * Pour des instructions complètes et des schémas de câblage, veuillez visiter: * https://newbiely.fr/tutorials/arduino-nano/arduino-nano-ssd1309-oled-display */ /* * DIYables OLED SSD1309 – External Fonts * Cycles through three FreeFont typefaces on the 2.42" SSD1309 OLED with Arduino Nano. */ #include <Wire.h> #include <Adafruit_GFX.h> #include <DIYables_OLED_SSD1309.h> #include <Fonts/FreeSerif9pt7b.h> #include <Fonts/FreeSansBold12pt7b.h> #include <Fonts/FreeMono9pt7b.h> #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 #define SCREEN_ADDRESS 0x3C DIYables_OLED_SSD1309 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); void setup() { Serial.begin(9600); if (!display.begin(SSD1309_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1309 allocation failed")); for (;;); } display.clearDisplay(); display.display(); } void loop() { // ── Built-in 5×7 font ── display.clearDisplay(); display.setFont(NULL); display.setTextSize(1); display.setTextColor(SSD1309_PIXEL_ON); display.setCursor(0, 0); display.println(F("Built-in 5x7 font")); display.println(); display.setTextSize(2); display.println(F("DIYables")); display.display(); delay(3000); // ── FreeSerif 9pt ── display.clearDisplay(); display.setFont(&FreeSerif9pt7b); display.setTextSize(1); display.setTextColor(SSD1309_PIXEL_ON); display.setCursor(0, 14); // Y = baseline display.println(F("FreeSerif 9pt")); display.setCursor(0, 38); display.println(F("DIYables OLED")); display.setCursor(0, 58); display.println(F("Hello World!")); display.display(); delay(3000); // ── FreeSansBold 12pt ── display.clearDisplay(); display.setFont(&FreeSansBold12pt7b); display.setTextSize(1); display.setTextColor(SSD1309_PIXEL_ON); display.setCursor(0, 20); display.println(F("SansBold")); display.setCursor(0, 52); display.println(F("DIYables")); display.display(); delay(3000); // ── FreeMono 9pt ── display.clearDisplay(); display.setFont(&FreeMono9pt7b); display.setTextSize(1); display.setTextColor(SSD1309_PIXEL_ON); display.setCursor(0, 14); display.println(F("FreeMono 9pt")); display.setCursor(0, 34); display.println(F("0123456789")); display.setCursor(0, 54); display.println(F("!@#$%^&*()")); display.display(); delay(3000); }

Dépannage de l'écran OLED SSD1309 avec Arduino Nano

Si rien n'apparaît sur l'écran OLED SSD1309 2.42 pouces après avoir téléversé votre sketch, parcourez ces vérifications :

  • Vérifiez le câblage — confirmez que SDA, SCL, VCC et GND sont connectés aux bonnes broches de l'Arduino Nano.
  • Confirmez la puce pilote — cette bibliothèque est conçue pour le SSD1309. Si votre module utilise un contrôleur différent (par ex. SH1106), il ne répondra pas correctement.
  • Vérifiez l'adresse I2C — la plupart des modules SSD1309 utilisent par défaut 0x3C, mais certains utilisent 0x3D. Exécutez le sketch scanner I2C ci-dessous pour détecter l'adresse réelle :
// Scanner d'adresse I2C — imprime chaque périphérique détecté vers le moniteur série #include <Wire.h> void setup() { Wire.begin(); Serial.begin(9600); Serial.println("I2C Scanner"); } void loop() { byte error, address; int nDevices = 0; Serial.println("Scanning..."); for (address = 1; address < 127; address++) { Wire.beginTransmission(address); error = Wire.endTransmission(); if (error == 0) { Serial.print("I2C device found at address 0x"); if (address < 16) Serial.print("0"); Serial.print(address, HEX); Serial.println(" !"); nDevices++; } else if (error == 4) { Serial.print("Unknown error at address 0x"); if (address < 16) Serial.print("0"); Serial.println(address, HEX); } } if (nDevices == 0) Serial.println("No I2C devices found"); else Serial.println("done"); delay(5000); }

Sortie attendue du moniteur série quand le SSD1309 est détecté :

COM6
Send
Scanning... I2C device found at address 0x3C ! done
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  
  • Assurez-vous que display() est appelé — le SSD1309 utilise un tampon de trame. Les fonctions de dessin ne modifient que le tampon en RAM ; rien n'apparaît à l'écran jusqu'à ce que vous appeliez oled.display().
  • Vérifiez l'alimentation — le module 2.42 pouces consomme plus de courant que les écrans OLED plus petits. Assurez-vous que votre source d'alimentation peut fournir suffisamment de courant (typiquement 20–40 mA à pleine luminosité).

Tutoriel vidéo

Conclusion

Ce guide a couvert tous les éléments essentiels pour utiliser l'écran OLED SSD1309 2.42 pouces (128×64) avec Arduino Nano, incluant :

  • Les connexions matérielles et le câblage I2C
  • L'affichage de texte et de nombres avec plusieurs tailles
  • Le dessin de formes (rectangles, cercles, triangles)
  • Le rendu d'images bitmap
  • Le défilement matériel dans quatre directions
  • Le contrôle du contraste et de la luminosité
  • Les polices externes personnalisées

La bibliothèque DIYables_OLED_SSD1309 simplifie la programmation du SSD1309 en fournissant des fonctions de haut niveau pour le texte, les graphiques et le contrôle d'affichage tout en exploitant Adafruit GFX pour des capacités de dessin étendues.

Pour plus de projets et tutoriels Arduino Nano, visitez arduinogetstarted.com

※ NOS MESSAGES

  • N'hésitez pas à partager le lien de ce tutoriel. Cependant, veuillez ne pas utiliser notre contenu sur d'autres sites web. Nous avons investi beaucoup d'efforts et de temps pour créer ce contenu, veuillez respecter notre travail !