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édenteDernière révisionLes deux révisions suivantes | ||
micropython [2020/02/24 15:32] – [Exemple] serge | micropython [2020/10/04 10:13] – ↷ Liens modifiés en raison d'un déplacement. 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==== | ||
+ | * https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | |||
====Branchement de la MPU 6050à la pyboard lite==== | ====Branchement de la MPU 6050à la pyboard lite==== | ||
La communication entre les 2 cartes se fait en **[[https:// | 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 | ||
{{ : | {{ : | ||
- | https://www.invensense.com/wp-content/uploads/ | + | ====Les fichiers==== |
+ | * **[[https://github.com/sergeLabo/micropython_mpu6050|micropython_mpu6050 sur GitHub]]** | ||
- | https://maker.pro/arduino/tutorial/how-to-interface-arduino-and-the-mpu-6050-sensor | + | Les fichiers du [[https://github.com/sergeLabo/micropython_mpu6050/tree/ |
- | https://playground.arduino.cc/Main/MPU-6050/ | + | Le fichier [[https://github.com/ |
+ | |||
+ | =====USB_VCP – USB virtual comm port===== | ||
+ | **Communication entre la PyBoard et le PC en USB** | ||
+ | |||
+ | * [[http://docs.micropython.org/ | ||
+ | * [[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 | ||
+ | </code> | ||
{{tag> | {{tag> | ||
+ | |||
+ | |||
+ |
micropython.txt · Dernière modification : 2020/10/19 07:14 de serge