From b0909e930f66773ecb546d06dab896c65cfc7f74 Mon Sep 17 00:00:00 2001 From: Raymond Bourges Date: Sat, 29 Nov 2025 21:06:59 +0100 Subject: [PATCH] Boutons et relais OK --- .gitignore | 1 + .micropico | 3 +++ .vscode/extensions.json | 8 +++++++ .vscode/settings.json | 15 +++++++++++++ main.py | 49 +++++++++++++++++++++++++++++++++++++++++ notes.md | 7 ++++++ requirements.txt | 16 ++++++++++++++ 7 files changed, 99 insertions(+) create mode 100644 .gitignore create mode 100644 .micropico create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json create mode 100644 main.py create mode 100644 notes.md create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e540f5b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +tmp/* \ No newline at end of file diff --git a/.micropico b/.micropico new file mode 100644 index 0000000..3de3977 --- /dev/null +++ b/.micropico @@ -0,0 +1,3 @@ +{ + "info": "This file is just used to identify a project folder." +} \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..fbc7999 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,8 @@ +{ + "recommendations": [ + "ms-python.python", + "visualstudioexptteam.vscodeintellicode", + "ms-python.vscode-pylance", + "paulober.pico-w-go" + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..03be782 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,15 @@ +{ + "python.languageServer": "Pylance", + "python.analysis.typeCheckingMode": "basic", + "python.analysis.diagnosticSeverityOverrides": { + "reportMissingModuleSource": "none" + }, + "python.terminal.activateEnvironment": false, + "micropico.openOnStart": true, + "python.analysis.typeshedPaths": [ + "~/.micropico-stubs/included" + ], + "python.analysis.extraPaths": [ + "~/.micropico-stubs/included" + ] +} \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..bab8958 --- /dev/null +++ b/main.py @@ -0,0 +1,49 @@ +from machine import Pin, I2C +import time + +led_jaune = Pin(0, Pin.OUT) +led_bleue = Pin(2, Pin.OUT) +led_rouge = Pin(19, Pin.OUT) +button_jaune = Pin(1, Pin.IN, Pin.PULL_UP) +button_bleu = Pin(21, Pin.IN, Pin.PULL_UP) +button_rouge = Pin(20, Pin.IN, Pin.PULL_UP) + +i2c = I2C(scl=Pin(23), sda=Pin(22), freq=20000) + +I2C_ADDR = 0x11 + +def button_jaune_presse(pin): + print("Bouton jaune pressé !") + led_jaune.on() + led_bleue.off() + led_rouge.off() + set_relays(0b0011) + +button_jaune.irq(trigger=Pin.IRQ_FALLING, handler=button_jaune_presse) + +def button_bleu_presse(pin): + print("Bouton bleu !") + led_jaune.off() + led_bleue.on() + led_rouge.off() + set_relays(0b1100) + +button_bleu.irq(trigger=Pin.IRQ_FALLING, handler=button_bleu_presse) + +def button_rouge_presse(pin): + print("Bouton rouge pressé !") + led_jaune.off() + led_bleue.off() + led_rouge.on() + set_relays(0b1100) + +button_rouge.irq(trigger=Pin.IRQ_FALLING, handler=button_rouge_presse) + + +def set_relays(mask): + """mask = bits 0..3 (1=ON, 0=OFF)""" + i2c.writeto_mem(I2C_ADDR, 0x10, bytes([mask])) + +while True: + time.sleep(1) + \ No newline at end of file diff --git a/notes.md b/notes.md new file mode 100644 index 0000000..3c8088d --- /dev/null +++ b/notes.md @@ -0,0 +1,7 @@ +esptool --port /dev/ttyACM0 erase-flash + +cd tmp +wget https://micropython.org/resources/firmware/ESP32_GENERIC_C6-20250911-v1.26.1.bin +cd - + +esptool --port /dev/ttyACM0 --baud 460800 write-flash 0 ./tmp/ESP32_GENERIC_C6-20250911-v1.26.1.bin \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2d31a28 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,16 @@ +bitarray==3.8.0 +bitstring==4.3.1 +cffi==2.0.0 +click==8.3.1 +cryptography==46.0.3 +esptool==5.1.0 +intelhex==2.3.0 +markdown-it-py==4.0.0 +mdurl==0.1.2 +pycparser==2.23 +Pygments==2.19.2 +pyserial==3.5 +PyYAML==6.0.3 +reedsolo==1.7.0 +rich==14.2.0 +rich-click==1.9.4