| |
python:micropython:es [2023/08/20 09:32] – [2.3 Interruption] phil | python:micropython:es [Date inconnue] (Version actuelle) – supprimée - modification externe (Date inconnue) 127.0.0.1 |
---|
[[:python:micropython:accueil|{{ :iconemaison.jpg?nolink&30|Sommaire MicroPython, CircuitPython}}]] | |
| |
===== MicroPython - Entrées, Sorties (GPIO) ===== | |
{{ :micropython:logomicropython.png?nolink&120|}} | |
| |
[Mise à jour le : 1/6/2023] <html><span style="color:red">En cours de rédaction</span></html> | |
| |
* **Ressources** | |
* <html><a href="https://micropython.org/" target="_blank">MicroPython.org</a></html> | |
* <html><a href="https://docs.micropython.org/en/latest/index.html#" target="_blank">MicroPython documentation</a></html> | |
* <html><a href="https://thonny.org/" target="_blank">IDE Thonny</a></html> | |
| |
* **Lectures connexes** | |
* <html><a href="https://randomnerdtutorials.com/esp32-esp8266-digital-inputs-digital-outputs-micropython/" target="_blank">ESP32/ESP8266 Digital Inputs and Digital Outputs with MicroPython</a></html> | |
* <html><a href="https://randomnerdtutorials.com/micropython-gpios-esp32-esp8266/" target="_blank">MicroPython with ESP32 and ESP8266: Interacting with GPIOs</a></html> | |
* <html><a href="https://randomnerdtutorials.com/esp32-esp8266-pwm-micropython/" target="_blank">ESP32/ESP8266 PWM with MicroPython – Dim LED</a></html> | |
* <html><a href="https://randomnerdtutorials.com/esp32-esp8266-analog-readings-micropython/" target="_blank">ESP32/ESP8266 Analog Readings with MicroPython</a></html> | |
* <html><a href="https://randomnerdtutorials.com/micropython-interrupts-esp32-esp8266/" target="_blank">MicroPython: Interrupts with ESP32 and ESP8266</a></html> | |
| |
| |
==== 2. Entrées, sorties numériques ==== | |
| |
{{ :python:micropython:materiel:led.jpg?nolink&100|LED}} | |
{{ :python:micropython:pmod_btn_25707.png?nolink&90|Digilent Pmod BTN: 4 User Pushbuttons}} | |
| |
| |
{{ :materiels:capteurs:environnement:code.png?nolink|}} | |
| |
| |
| |
| |
{{ :materiels:capteurs:potentiometre.png?nolink&80|Potentiomètre}} | |
==== 3. Entrées analogiques ==== | |
* **Ressource** | |
* <html><a href="https://docs.micropython.org/en/latest/rp2/quickref.html#pins-and-gpio" target="_blank"><strong>Quick reference for the RP2</strong>, Pins and GPIO </a>sur Micropython.org.</html>, potentiomètre 10kOhm. | |
| |
=== 3.1 Présentation === | |
* **Ressource** | |
* <html><a href="https://zestedesavoir.com/tutoriels/686/arduino-premiers-pas-en-informatique-embarquee/745_les-grandeurs-analogiques/3430_les-entrees-analogiques-de-larduino/" target="_blank">Un signal analogique : petits rappels</a></html> sur le site Zeste de savoir. | |
{{ :materiels:capteurs:environnement:code.png?nolink|}} | |
=== 3.2 Exemples de code === | |
<tabs> | |
* [[#tab-pico_4|RPi Pico]] | |
* [[#tab-esp32_4|ESP32]] | |
| |
<pane id="tab-pico_4"> | |
* **Ressource** | |
* <html><a href="https://docs.micropython.org/en/latest/esp32/quickref.html#adc-analog-to-digital-conversion" target="_blank">ADC (analog to digital conversion)</a></html> | <html><a href="https://docs.micropython.org/en/latest/library/machine.Pin.html" target="_blank">class Pin – control I/O pins</a></html> sur Micropython.org. | |
//Exemple de code pour un **Raspberry Pi Pico**// | |
<code python *.py> | |
# ------------------------------------------------------------------------------- | |
# Lecture et affichage dans la console de la tension issue d'un potentiomètre | |
# Date : 22/5/2023 | |
# Matériels : Raspberry Pi Pico, Shield Grove, pot. 10k | |
# ADC accessibles sur le shield Grove pour RP2 : | |
# Connecteur: ADC : GPIO | |
# A0 : ADC0 : 26 | |
# A1 : ADC0,ADC1: 26,27 | |
# A2 : ADC1,ADC2: 27,28 | |
# IDE : Thonny | |
# ------------------------------------------------------------------------------- | |
from machine import ADC, Pin | |
import time | |
| |
# Le potentiomètre 10kOhm est connecté à l'entrée analogique A0 du shield. | |
# Attention : La tension doit être comprise entre 0 - 3,3V (3,6V max !) | |
# sur une entrée analogique. | |
# Configuration | |
pot = ADC(Pin(26)) | |
| |
while (True): | |
val=pot.read_u16() # lecture de l'ADC | |
U = val*3.3/65535 # Calcul de la tension | |
print("%.2f" % U) # Affichage dans la console (formaté à 2 décimales) | |
time.sleep(1) | |
</code> | |
</pane> | |
| |
<pane id="tab-esp32_4"> | |
* **Ressource** | |
* <html><a href="https://docs.micropython.org/en/latest/esp32/quickref.html#adc-analog-to-digital-conversion" target="_blank">ADC (analog to digital conversion)</a></html> sur Micropython.org. | |
//Exemple de code pour un **ESP32 Feather Huzzah**// | |
<code python *.py> | |
# ADC accessibles en Python sur la carte ESP32 Feather Huzzah : | |
# ADC:GPIO | |
# A2 : 34 | |
# A3 : 39 | |
# A4 : 36 | |
# A7 : 32 | |
# A9 : 33 | |
| |
from machine import ADC, Pin | |
| |
# Le potentiomètre 10kOhm est connecté à l'entrée analogique A2 de l'ESP32. | |
# Configuration | |
adc = ADC(Pin(34)) | |
# Sur une entrée analogique, la tension doit | |
# être comprise entre 0 - 3,3V (3,6V max !) | |
adc.atten(ADC.ATTN_11DB) # voir doc | |
# Mesure | |
value = adc.read() | |
| |
print(value) # affichage dans la console | |
</code> | |
</pane> | |
</tabs> | |
| |
| |