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 12:24] – [Micro Python] 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:// | ||
</ | </ | ||
+ | ===== Carte utilisée pour les essais ===== | ||
- | https:// | + | * **[[https://store.micropython.org/product/ |
- | https:// | + | {{ :media_10: |
- | https://github.com/ | + | {{:media_10: |
- | http:// | ||
+ | ===== Ressources ===== | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[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, | ||
- | screen | + | ===En terminal=== |
+ | 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===== |
+ | * **MPU 6050** Accéléromètre et Gyroscope | ||
+ | |||
+ | [[https:// | ||
+ | ====Documentation sur la MPU 6050==== | ||
+ | * https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | |||
+ | ====Branchement de la MPU 6050à la pyboard lite==== | ||
+ | La communication entre les 2 cartes se fait en **[[https:// | ||
+ | |||
+ | Le [[https:// | ||
+ | * SDA sur Y10 (Serial Data Line) : ligne de données bidirectionnelle | ||
+ | * SCL sur Y9 | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | ====Les fichiers==== | ||
+ | * **[[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.1582547050.txt.gz · Dernière modification : 2020/02/24 12:24 de serge