micropython
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
micropython [2020/02/24 15:57] – [Branchement de la MPU 6050à la pyboard lite] serge | micropython [2020/10/19 07:14] (Version actuelle) – Tag0 Removed: python3 serge | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
====== Micropython ====== | ====== Micropython ====== | ||
- | {{ :: | + | {{ media_02: |
<WRAP center round box 60% centeralign> | <WRAP center round box 60% centeralign> | ||
- | Python pour Micro Controlers | + | Python pour Micro Controlers\\ |
+ | [[http:// | ||
</ | </ | ||
Ligne 18: | Ligne 19: | ||
===== Ressources ===== | ===== Ressources ===== | ||
- | * https:// | + | * [[https:// |
- | * https:// | + | * [[https:// |
- | * https:// | + | * [[https:// |
- | * http:// | + | * [[http:// |
+ | * [[https:// | ||
+ | * [[https:// | ||
=====Installation pour Linux===== | =====Installation pour Linux===== | ||
- | sudo apt install | + | sudo apt install |
sudo usermod -a -G dialout $USER | sudo usermod -a -G dialout $USER | ||
Se déconnecter, | Se déconnecter, | ||
+ | ===En terminal=== | ||
picocom / | picocom / | ||
+ | ===Reset=== | ||
+ | Ctrl + D ou appuyer sur le button derrière le micro-usb | ||
+ | =====Communication entre la pyboard et le PC===== | ||
- | =====Utilisation===== | ||
- | |||
- | Soft reboot: Ctrl + D | ||
=====Exemple===== | =====Exemple===== | ||
* **MPU 6050** Accéléromètre et Gyroscope | * **MPU 6050** Accéléromètre et Gyroscope | ||
+ | |||
+ | [[https:// | ||
====Documentation sur la MPU 6050==== | ====Documentation sur la MPU 6050==== | ||
* https:// | * https:// | ||
Ligne 52: | Ligne 57: | ||
====Les fichiers==== | ====Les fichiers==== | ||
* **[[https:// | * **[[https:// | ||
+ | |||
+ | Les fichiers du [[https:// | ||
+ | |||
+ | Le fichier [[https:// | ||
+ | |||
+ | =====USB_VCP – USB virtual comm port===== | ||
+ | **Communication entre la PyBoard et le PC en USB** | ||
+ | |||
+ | * [[http:// | ||
+ | * [[https:// | ||
+ | |||
+ | ===pyboard=== | ||
+ | <code python boot.py> | ||
+ | import pyb | ||
+ | </ | ||
+ | <code python main.py> | ||
+ | usb = pyb.USB_VCP() | ||
+ | |||
+ | def send_data(data): | ||
+ | global usb | ||
+ | print(data) | ||
+ | toto = ujson.dumps(data) | ||
+ | usb.write(toto + " | ||
+ | </ | ||
+ | | ||
+ | ===PC=== | ||
+ | <code python boot.py> | ||
+ | from time import sleep | ||
+ | import serial | ||
+ | import ast | ||
+ | |||
+ | |||
+ | def datagram_to_dict(data): | ||
+ | """ | ||
+ | Retourne un dict ou None | ||
+ | """ | ||
+ | |||
+ | try: | ||
+ | dec = data.decode(" | ||
+ | except: | ||
+ | print(" | ||
+ | dec = data | ||
+ | |||
+ | try: | ||
+ | msg = ast.literal_eval(dec) | ||
+ | except: | ||
+ | print(" | ||
+ | print(" | ||
+ | msg = dec | ||
+ | |||
+ | if isinstance(msg, | ||
+ | return msg | ||
+ | else: | ||
+ | print(" | ||
+ | return None | ||
+ | |||
+ | init = 1 | ||
+ | while init: | ||
+ | try: | ||
+ | print(" | ||
+ | sleep(1) | ||
+ | seri = serial.Serial('/ | ||
+ | print(" | ||
+ | init = 0 | ||
+ | except: | ||
+ | print(" | ||
+ | |||
+ | while True: | ||
+ | rcv = seri.readline() | ||
+ | |||
+ | data = datagram_to_dict(rcv) | ||
+ | </ | ||
+ | |||
+ | ===== Entrée analogique pour capter un potentiomètre ===== | ||
+ | * https:// | ||
+ | |||
+ | Les broches analogiques sont: X1 à X8, X11, X12, Y11, Y12 | ||
+ | |||
+ | Les broches analogiques mesurent en 3.3V sur 12 bits (0-4095) soit une précision de 0,8 mV = 0.0008 V! | ||
+ | |||
+ | |||
+ | === ADC === | ||
+ | * [[https:// | ||
+ | |||
+ | <code python> | ||
+ | See pyb.Pin and pyb.ADC. | ||
+ | |||
+ | from pyb import Pin, ADC | ||
+ | |||
+ | adc = ADC(Pin(' | ||
+ | adc.read() # read value, 0-4095 | ||
+ | </ | ||
+ | |||
+ | === DAC === | ||
+ | * [[https:// | ||
+ | <code python> | ||
+ | from pyb import Pin, DAC | ||
+ | |||
+ | dac = DAC(Pin(' | ||
+ | dac.write(120) # output between 0 and 255 | ||
+ | </ | ||
+ | |||
+ | |||
+ | {{tag> micro_controleur python sb }} | ||
- | {{tag> |
micropython.txt · Dernière modification : 2020/10/19 07:14 de serge