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 Prochaine révisionLes deux révisions suivantes | ||
python:micropython:comserie [2021/08/11 09:19] – modification externe 127.0.0.1 | python:micropython:comserie [2023/06/04 15:54] – [2 Communication synchrone] phil | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | {{ : | + | [[: |
===== MicroPython - Communication série ===== | ===== MicroPython - Communication série ===== | ||
{{ : | {{ : | ||
- | [Mise à jour le : 8/7/2021] <html>< | + | [Mise à jour le : 4/6/2023] < |
* **Ressources** | * **Ressources** | ||
* < | * < | ||
Ligne 14: | Ligne 13: | ||
==== 1. Présentation ==== | ==== 1. Présentation ==== | ||
+ | ==== 2 Communication synchrone ==== | ||
+ | === 2.1 Bus I2C === | ||
+ | |||
+ | == Outils == | ||
+ | <button type=" | ||
+ | < | ||
+ | <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 time | ||
+ | import board | ||
+ | import busio | ||
+ | |||
+ | i2c_0 = busio.I2C(board.GP9, | ||
+ | i2c_1 = busio.I2C(board.GP7, | ||
+ | |||
+ | while not i2c_0.try_lock(): | ||
+ | pass | ||
+ | |||
+ | while not i2c_1.try_lock(): | ||
+ | pass | ||
+ | |||
+ | try: | ||
+ | while True: | ||
+ | print( | ||
+ | " | ||
+ | [hex(device_address_0) for device_address_0 in i2c_0.scan()]," | ||
+ | [hex(device_address_1) for device_address_1 in i2c_1.scan()]," | ||
+ | ) | ||
+ | time.sleep(2) | ||
+ | |||
+ | finally: | ||
+ | i2c_0.unlock() | ||
+ | i2c_1.unlock() | ||
+ | </ | ||
+ | </ | ||
+ | ==== 3. Communication asynchrone ==== | ||