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 12:42] – [Utilisation] 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:// | ||
</ | </ | ||
===== Carte utilisée pour les essais ===== | ===== Carte utilisée pour les essais ===== | ||
- | * **[[https:// | + | * **[[https:// |
{{ : | {{ : | ||
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:// | + | [[https:// |
+ | ====Documentation sur la MPU 6050==== | ||
+ | * https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
- | https://maker.pro/arduino/tutorial/ | + | ====Branchement de la MPU 6050à la pyboard lite==== |
+ | La communication entre les 2 cartes se fait en **[[https://fr.wikipedia.org/wiki/I2C|I2C: Inter-Integrated Circuit]]**. Il permet de relier facilement un microprocesseur et différents circuits. \\ Il existe d’innombrables périphériques exploitant ce bus, il est même implémentable par logiciel dans n’importe quel microcontrôleur. Le poids de l’industrie de l’électronique grand public a permis des prix très bas grâce à ces nombreux composants. | ||
- | https://playground.arduino.cc/Main/MPU-6050/ | + | Le [[https://forum.micropython.org/viewtopic.php? |
+ | * 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 | ||
+ | </code> | ||
{{tag> | {{tag> | ||
+ | |||
+ | |||
+ |
micropython.txt · Dernière modification : 2020/10/19 07:14 de serge