Bibliothèque commune schemas/outils.py (boîtes, flèches, chronogrammes, séquences). M0 : chaîne de développement, séquence BOOT/RESET. M1 : architecture, comparatif Uno/ESP32-S3, diviseur de tension. M2 : pull-up, rebonds, chenillard, protocole WS2812. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
86 lines
3.9 KiB
Python
86 lines
3.9 KiB
Python
"""Module 1 — Découverte du microcontrôleur ESP32-S3."""
|
||
import matplotlib.pyplot as plt
|
||
import schemdraw
|
||
import schemdraw.elements as elm
|
||
|
||
from outils import boite, fleche, toile
|
||
from style import BLEU, CM, ENCRE, GRIS, ORANGE, VERT, Figure
|
||
|
||
schemdraw.use("matplotlib")
|
||
|
||
|
||
def architecture():
|
||
fig, ax = toile(16, 8.2)
|
||
boite(ax, 6.6, 4.2, 12.6, 7.6, couleur=BLEU, fond="#f5f8fe")
|
||
ax.text(0.6, 7.6, "ESP32-S3 (puce)", fontsize=10, color=BLEU, fontweight="bold")
|
||
# Cœurs et mémoire
|
||
boite(ax, 2.6, 6.2, 3.8, 1.0, "Cœur 0\nXtensa LX7", couleur=BLEU, taille=8.5)
|
||
boite(ax, 2.6, 5.0, 3.8, 1.0, "Cœur 1\nXtensa LX7", couleur=BLEU, taille=8.5)
|
||
ax.text(2.6, 4.2, "240 MHz max · FreeRTOS", ha="center", fontsize=7.5, color=GRIS)
|
||
sram = boite(ax, 6.6, 5.6, 3.0, 2.2, "SRAM interne\n≈ 512 Ko\n(données +\ninstructions)", couleur=VERT, taille=8.5)
|
||
# Radio
|
||
boite(ax, 10.6, 6.2, 3.6, 1.0, "Wi-Fi 802.11 b/g/n\n2,4 GHz", couleur=ORANGE, taille=8)
|
||
boite(ax, 10.6, 5.0, 3.6, 1.0, "Bluetooth 5 LE\n(pas de Classic)", couleur=ORANGE, taille=8)
|
||
# Périphériques
|
||
periph = ["GPIO", "ADC 12 bits", "LEDC (PWM)", "UART", "I2C", "SPI", "Timers", "USB OTG"]
|
||
for i, p in enumerate(periph):
|
||
x = 1.35 + (i % 4) * 2.85
|
||
yy = 2.55 if i < 4 else 1.35
|
||
boite(ax, x, yy, 2.55, 0.9, p, couleur=GRIS, taille=8.5)
|
||
ax.text(0.6, 3.25, "Périphériques intégrés", fontsize=8, color=GRIS, fontweight="bold")
|
||
# Bus interne
|
||
ax.plot([0.7, 12.5], [3.8, 3.8], color=BLEU, lw=2.2, alpha=0.5)
|
||
# Externe
|
||
flash = boite(ax, 14.75, 5.6, 2.45, 2.2, "Flash\nexterne\n8–16 Mo\n(programme,\nfichiers)", couleur=VERT, taille=7.5)
|
||
psram = boite(ax, 14.7, 2.9, 2.3, 1.2, "PSRAM\n(option)", couleur=VERT, taille=8, alpha=0.8)
|
||
ax.text(14.7, 7.15, "sur le module", ha="center", fontsize=7.5, color=GRIS, style="italic")
|
||
fleche(ax, (12.9, 5.6), flash["g"], double=True)
|
||
fleche(ax, (12.9, 2.9), psram["g"], double=True)
|
||
return fig
|
||
|
||
|
||
def uno_vs_s3():
|
||
fig, ax = plt.subplots(figsize=(16 * CM, 6.2 * CM))
|
||
criteres = ["Fréquence (MHz)", "RAM (Ko)", "Flash (Ko)"]
|
||
uno = [16, 2, 32]
|
||
s3 = [240, 512, 8192]
|
||
y = range(len(criteres))
|
||
ax.barh([i + 0.2 for i in y], uno, height=0.38, color=GRIS, label="Arduino Uno (ATmega328)")
|
||
ax.barh([i - 0.2 for i in y], s3, height=0.38, color=BLEU, label="ESP32-S3")
|
||
ax.set_xscale("log")
|
||
ax.set_xlim(1, 300000)
|
||
ax.set_yticks(list(y), criteres)
|
||
ax.invert_yaxis()
|
||
for i, (u, s) in enumerate(zip(uno, s3)):
|
||
ax.text(u * 1.15, i + 0.2, f"{u:g}", va="center", fontsize=8, color=ENCRE)
|
||
lib = f"{s:g}" if s < 8000 else "8192 (8 Mo)"
|
||
ax.text(s * 1.15, i - 0.2, f"{lib} × {s // u}", va="center", fontsize=8, color=BLEU,
|
||
fontweight="bold")
|
||
ax.set_xlabel("échelle logarithmique : chaque graduation = × 10")
|
||
ax.grid(axis="y", visible=False)
|
||
ax.legend(loc="lower center", bbox_to_anchor=(0.5, 1.0), ncol=2, fontsize=8, frameon=False)
|
||
fig.tight_layout()
|
||
return fig
|
||
|
||
|
||
def diviseur_tension():
|
||
d = schemdraw.Drawing(show=False)
|
||
d.config(fontsize=11, unit=2.6, color=ENCRE)
|
||
d += elm.Dot(open=True).label("Signal 5 V\n(module tiers)", loc="left")
|
||
d += elm.Resistor().right().label("R1 = 10 kΩ").color(ORANGE)
|
||
d += (noeud := elm.Dot())
|
||
d += elm.Line().right().length(2.2)
|
||
d += elm.Dot(open=True).label("GPIO\n(3,3 V max)", loc="right").color(BLEU)
|
||
d += elm.Resistor().down().at(noeud.center).label("R2 = 20 kΩ", loc="bottom").color(ORANGE)
|
||
d += elm.Ground()
|
||
d += elm.Label().at((noeud.center[0] + 1.2, noeud.center[1] - 2.2)).label(
|
||
r"$V_{GPIO} = 5\,V \times \frac{R2}{R1 + R2} \approx 3{,}3\,V$", fontsize=11, color=VERT)
|
||
return d.draw(show=False)
|
||
|
||
|
||
FIGURES = [
|
||
Figure("m01-architecture", architecture),
|
||
Figure("m01-uno-vs-s3", uno_vs_s3),
|
||
Figure("m01-diviseur-tension", diviseur_tension),
|
||
]
|