Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
python:micropython:materiel:ssd1306 [2023/04/28 16:49] – phil | python:micropython:materiel:ssd1306 [Date inconnue] (Version actuelle) – supprimée - modification externe (Date inconnue) 127.0.0.1 | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | [[: | ||
- | |||
- | ===== MicroPython - Afficheurs à circuit SSD1306 ===== | ||
- | {{ : | ||
- | |||
- | [Mise à jour le : 28/ | ||
- | |||
- | * **Ressources** | ||
- | * < | ||
- | * < | ||
- | * < | ||
- | * < | ||
- | |||
- | * **Lectures connexes** | ||
- | * **Installer MicroPython** - [[python: | ||
- | * **Programmez** ! Juillet/ | ||
- | * **Elektor 489** Mai/Juin 2021 | ||
- | |||
- | ---- | ||
- | |||
- | |||
- | {{ : | ||
- | ==== 1. Présentation ==== | ||
- | Les exemples de code de cette page ont été testés sur un afficheur < | ||
- | |||
- | <callout type=" | ||
- | |||
- | * **Organisation de l' | ||
- | * **x** : position du point par rapport au côté gauche de l' | ||
- | * **y** : position du point par rapport au dessus de l' | ||
- | * **w** : largeur (du mot Width). | ||
- | * **h** : hauteur (du mot Height). | ||
- | * **c** : couleur (1=point allumé, 0=point éteint) | ||
- | |||
- | * **Méthodes de la bibliothèque SSD1306** | ||
- | |||
- | ^ Prototype | ||
- | | **fill**( c ) | Remplit l' | ||
- | | **fill_rect**(x, | ||
- | | **hline**(x, | ||
- | | **line**(x1, | ||
- | | **pixel**(x, | ||
- | | **scroll**(depl.horiz, | ||
- | | **show**() | ||
- | | **text**(" | ||
- | | **vline**(x, | ||
- | |||
- | |||
- | ==== 2. Programmation ==== | ||
- | <callout type=" | ||
- | |||
- | === 2.1 Configurations === | ||
- | |||
- | <callout type=" | ||
- | |||
- | // Exemple pour un **ESP32 Feather Huzzah**// | ||
- | |||
- | <code python main.py> | ||
- | from machine import Pin, SoftI2C | ||
- | import ssd1306 | ||
- | import time | ||
- | import urandom | ||
- | |||
- | # Configuration du bus i2c sur l' | ||
- | i2c = SoftI2C(scl=Pin(22), | ||
- | |||
- | # Dimension de l' | ||
- | oled_width = 128 # px | ||
- | oled_height = 64 # px | ||
- | |||
- | # Construction de l' | ||
- | oled = ssd1306.SSD1306_I2C(oled_width, | ||
- | </ | ||
- | |||
- | // Exemple pour un **Raspberry Pi Pico**// | ||
- | <code python main.py> | ||
- | # Modifications à apporter au code ci-dessus | ||
- | from machine import Pin, I2C | ||
- | ... | ||
- | |||
- | # Configuration du bus i2c sur le Raspberry Pi Pico | ||
- | i2c = I2C(0) | ||
- | ... | ||
- | |||
- | </ | ||
- | |||
- | Une fois créée, l' | ||
- | |||
- | === 2.2 Démos === | ||
- | * **Démo 1** : affichage d'un texte | ||
- | |||
- | <code python main.py> | ||
- | # A ajouter au code du §2.1 | ||
- | # Division de l' | ||
- | lin_hight = 9 | ||
- | col_width = 8 | ||
- | def text_write(text, | ||
- | oled.text(text, | ||
- | |||
- | oled.fill(0) # Extinction de l' | ||
- | text_write(" | ||
- | text_write(" | ||
- | text_write(" | ||
- | oled.show() | ||
- | |||
- | time.sleep(1) | ||
- | </ | ||
- | |||
- | * **Démo 2** : affichage de lignes | ||
- | |||
- | <code python main.py> | ||
- | # A ajouter au code du §2.1 | ||
- | # ligne horizontale : hline(pos_x1, | ||
- | # ligne verticale : vline(pos_x1, | ||
- | # c=0=> | ||
- | |||
- | oled.hline(0, | ||
- | oled.hline(0, | ||
- | oled.vline(0, | ||
- | oled.vline(oled_width-1, | ||
- | oled.show() | ||
- | |||
- | time.sleep(3) | ||
- | </ | ||
- | |||
- | * **Démo 3** : affichage aléatoire de pixels | ||
- | |||
- | <code python main.py> | ||
- | # A ajouter au code du §2.1 | ||
- | oled.fill(0) # Ecran noir | ||
- | |||
- | for n in range(50): | ||
- | pos_x = urandom.randint(1, | ||
- | pos_y = urandom.randint(1, | ||
- | oled.pixel(pos_x, | ||
- | oled.show() | ||
- | |||
- | time.sleep(3) | ||
- | </ | ||
- | |||
- | * **Démo 4** : affichage d'une icône | ||
- | |||
- | <code python main.py> | ||
- | # A ajouter au code du §2.1 | ||
- | ICON = [ | ||
- | [0, | ||
- | [0, | ||
- | [0, | ||
- | [0, | ||
- | [1, | ||
- | [1, | ||
- | [0, | ||
- | [0, | ||
- | [0, | ||
- | [0, | ||
- | [0, | ||
- | ] | ||
- | |||
- | # Démo 4a : affichage d'une icône au centre | ||
- | oled.fill(0) # Extinction de l' | ||
- | for y in range (11): | ||
- | for x in range (11): | ||
- | oled.pixel(x+64, | ||
- | oled.show() | ||
- | |||
- | time.sleep(2) | ||
- | |||
- | # Démo 4b : affichage d' | ||
- | for n in range(12): | ||
- | pos_x = urandom.randint(1, | ||
- | pos_y = urandom.randint(1, | ||
- | for y, ligne in enumerate(ICON): | ||
- | for x, c in enumerate(ligne): | ||
- | oled.pixel(x+pos_x, | ||
- | oled.show() | ||
- | | ||
- | time.sleep(3) | ||
- | </ | ||
- | |||
- | {{ : | ||
- | <callout type=" | ||
- | |||
- | * **Démo 5 ** : affichage d'une icône avec canal alpha \\ Modifier l' | ||
- | |||