python:micropython:comserie

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision
Révision précédente
Dernière révisionLes deux révisions suivantes
python:micropython:comserie [2021/08/11 09:19] – modification externe 127.0.0.1python:micropython:comserie [2023/06/04 15:54] – [MicroPython - Communication série] phil
Ligne 1: Ligne 1:
-{{ :suivant.png?nolink&30|}} {{ :retour.png?nolink&30|}} [[:python:micropython:accueil|{{ :iconemaison.jpg?nolink&30|Sommaire MicroPython, CircuitPython}}]]+[[:python:micropython:accueil|{{ :iconemaison.jpg?nolink&30|Sommaire MicroPython, CircuitPython}}]]
  
 ===== MicroPython - Communication série ===== ===== MicroPython - Communication série =====
 {{ :micropython:logomicropython.png?nolink&120|}} {{ :micropython:logomicropython.png?nolink&120|}}
  
-[Mise à jour le : 8/7/2021] <html><span style="color:red">En cours de rédaction</span></html>+[Mise à jour le : 4/6/2023 
 + 
 +<color #ff7f27>En cours de rédaction</color>
  
   * **Ressources**   * **Ressources**
Ligne 14: Ligne 16:
 ==== 1. Présentation ==== ==== 1. Présentation ====
  
 +==== 2 Communication synchrone ====
 +=== 2.1 Bus I2C ===
 +
 +== Outils ==
 +<button type="default" collapse="scan">Scanner I2C</button>
 +<collapse id="scan" collapsed="true">
 +<code python scan.py>
 +# --------------------------------------------------------------------------------
 +# Titre : Scanner I2C
 +# Source : adafruit
 +# Langage : CircuitPython
 +# Circuit : Raspberry Pi Pico
 +#
 +# Remarques
 +# Si le bus I2C semble bloqué, utiliser le code si dessous dans la console
 +#  >>> import busio
 +#  >>> busio.I2C().unlock()
 +# --------------------------------------------------------------------------------
 +import time
 +import board
 +import busio
 +
 +i2c_0 = busio.I2C(board.GP9, board.GP8)   # Accès I2C0 sur le Grove Shield Pi Pico
 +i2c_1 = busio.I2C(board.GP7, board.GP6)   # Accès I2C1 
 +
 +while not i2c_0.try_lock():
 +    pass
 +
 +while not i2c_1.try_lock():
 +    pass
 +
 +try:
 +    while True:
 +        print(
 +            "Adresses:",
 +            [hex(device_address_0) for device_address_0 in i2c_0.scan()]," sur I2C0",
 +            [hex(device_address_1) for device_address_1 in i2c_1.scan()]," sur I2C1",
 +        )
 +        time.sleep(2)
 +
 +finally:  # unlock the i2c bus when ctrl-c'ing out of the loop
 +    i2c_0.unlock()
 +    i2c_1.unlock()
 +</code> 
 +</collapse>
  
  
 +==== 3. Communication asynchrone ====