Outils pour utilisateurs

Outils du site


micropython

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
micropython [2020/02/24 12:24] – [Micro Python] sergemicropython [2020/10/19 07:14] (Version actuelle) – Tag0 Removed: python3 serge
Ligne 1: Ligne 1:
 ====== Micropython ====== ====== Micropython ======
  
-{{ ::6298560.jpeg?200 |}}+{{ media_02:6298560.jpeg?200 |}}
  
  
 <WRAP center round box 60% centeralign> <WRAP center round box 60% centeralign>
-Python pour Micro Controlers+Python pour Micro Controlers\\ 
 +[[http://translate.google.com/translate?hl=&sl=auto&tl=en&u=https%3A%2F%2Fressources.labomedia.org%2Fmicropython|English Version]]
 </WRAP> </WRAP>
  
 +===== Carte utilisée pour les essais =====
  
-https://micropython.fr/+  * **[[https://store.micropython.org/product/PYBLITEv1.0H|MicroPython pyboard lite v1.0 with headers]]** à 37€ avec le port.
  
-https://micropython.org/+{{ :media_10:pyblitev1_0-d.jpg?400 |}} 
  
-https://github.com/micropython/micropython+{{:media_10:pyblitev10-schematics.pdf|pyblitev10-schematics.pdf}}
  
-http://docs.micropython.org/en/latest/ 
  
 +===== Ressources =====
 +  * [[https://micropython.fr/|micropython.fr]]
 +  * [[https://micropython.org/|micropython.org]]
 +  * [[https://github.com/micropython/micropython|github.com/micropython]]
 +  * [[http://docs.micropython.org/en/latest/|docs.micropython.org/en]]
 +  * [[https://docs.micropython.org/en/latest/pyboard/tutorial/reset.html|Reset]] pour revenir à l'état sortie usine
 +  * [[https://micropython-workshop.readthedocs.io/en/latest/pages/intro.html|MicroPython Workshop : des exemples dont le RGB LED Shield Lolin et +]]
 =====Installation pour Linux===== =====Installation pour Linux=====
-  sudo apt install screen+  sudo apt install picocom
   sudo usermod -a -G dialout $USER   sudo usermod -a -G dialout $USER
 Se déconnecter, se reconnecter Se déconnecter, se reconnecter
-  screen /dev/ttyACM0+===En terminal=== 
 +  picocom /dev/ttyACM0 -b9600 
 +===Reset=== 
 +Ctrl + D ou appuyer sur le button derrière le micro-usb
  
 +=====Communication entre la pyboard et le PC=====
  
-=====Utilisation===== 
  
-Soft rebootCtrl D+=====Exemple===== 
 +  * **MPU 6050** Accéléromètre et Gyroscope  
 + 
 +[[https://itechnofrance.wordpress.com/2018/02/15/utilisation-du-capteur-mpu6050-en-micropython|Inspiré de itechnofrance]] 
 +====Documentation sur la MPU 6050==== 
 +  * https://www.invensense.com/wp-content/uploads/2015/02/MPU-6000-Datasheet1.pdf 
 +  * [[https://maker.pro/arduino/tutorial/how-to-interface-arduino-and-the-mpu-6050-sensor|how to interface arduino and the mpu 6050 sensor]] 
 +  * [[https://playground.arduino.cc/Main/MPU-6050/|arduino.cc MPU-6050]] 
 + 
 +====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.  
 + 
 +Le [[https://forum.micropython.org/viewtopic.php?t=1363|système de la PyBoard]] est écrit pour communiquer en I2C avec: 
 +  * SDA sur Y10  (Serial Data Line)  : ligne de données bidirectionnelle 
 +  * SCL sur Y9   (Serial Clock Line) : ligne d'horloge de synchronisation bidirectionnelle 
 + 
 +{{ :media_10:pyboard_mpu6050.svg?600 |Branchement de la MPU 6050à la pyboard lite}} 
 + 
 +====Les fichiers==== 
 +  * **[[https://github.com/sergeLabo/micropython_mpu6050|micropython_mpu6050 sur GitHub]]** 
 + 
 +Les fichiers du [[https://github.com/sergeLabo/micropython_mpu6050/tree/master/pyboard|dossier pyboard]] doivent être copié sur la pyboard. 
 + 
 +Le fichier [[https://github.com/sergeLabo/micropython_mpu6050/blob/master/mpu6050_receiver.py|mpu6050_receiver.py]] doit être excécuté sue le PC relié en USB à la pyboard. 
 + 
 +=====USB_VCP – USB virtual comm port===== 
 +**Communication entre la PyBoard et le PC en USB** 
 + 
 +  * [[http://docs.micropython.org/en/latest/library/pyb.USB_VCP.html|The USB_VCP]] allows creation of a stream-like object representing the **USB Virtual Comm Port**. It can be used to read and write data over USB to the connected host. 
 +  * [[https://forum.micropython.org/viewtopic.php?f=2&t=423&sid=6c4720ea85f2112b42bab2971b57003f|Une discussion sur forum.micropython.org]] 
 + 
 +===pyboard=== 
 +<code python boot.py> 
 +import pyb 
 +</code> 
 +<code python main.py> 
 +usb = pyb.USB_VCP() 
 + 
 +def send_data(data): 
 +    global usb 
 +    print(data) 
 +    toto = ujson.dumps(data) 
 +    usb.write(toto "\n"
 +</code> 
 +     
 +===PC=== 
 +<code python boot.py> 
 +from time import sleep 
 +import serial 
 +import ast 
 + 
 + 
 +def datagram_to_dict(data): 
 +    """Décode le message. 
 +    Retourne un dict ou None 
 +    """ 
 + 
 +    try: 
 +        dec = data.decode("utf-8"
 +    except: 
 +        print("Décodage UTF-8 impossible"
 +        dec = data 
 + 
 +    try: 
 +        msg = ast.literal_eval(dec) 
 +    except: 
 +        print("ast.literal_eval impossible"
 +        print("Ajouter ast dans les import"
 +        msg = dec 
 + 
 +    if isinstance(msg, dict): 
 +        return msg 
 +    else: 
 +        print("Message reçu: None"
 +        return None 
 + 
 +init = 1 
 +while init: 
 +    try: 
 +        print("Connexion à ttyACM0 ...."
 +        sleep(1) 
 +        seri = serial.Serial('/dev/ttyACM0', 9600, timeout=1) 
 +        print("Connecté à ttyACM0"
 +        init = 0 
 +    except: 
 +        print("Connexion impossibble à ttyACM0"
 + 
 +while True: 
 +    rcv = seri.readline() 
 + 
 +    data = datagram_to_dict(rcv) 
 +</code> 
 + 
 +===== Entrée analogique pour capter un potentiomètre ===== 
 +  * https://micropython.fr/micropython/les_bases/entrees_analogiques 
 + 
 +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://docs.micropython.org/en/latest/pyboard/quickref.html#adc-analog-to-digital-conversion|analog to digital conversion]] 
 + 
 +<code python> 
 +See pyb.Pin and pyb.ADC. 
 + 
 +from pyb import Pin, ADC 
 + 
 +adc = ADC(Pin('X19')) 
 +adc.read() # read value, 0-4095 
 +</code> 
 + 
 +=== DAC === 
 +  * [[https://docs.micropython.org/en/latest/pyboard/quickref.html#dac-digital-to-analog-conversion|digital to analog conversion]] 
 +<code python> 
 +from pyb import Pin, DAC 
 + 
 +dac = DAC(Pin('X5')) 
 +dac.write(120) # output between 0 and 255 
 +</code> 
 + 
 + 
 +{{tag> micro_controleur python sb }} 
  
  
-{{tag>micro_controleur python python3 sb}} 
micropython.1582547050.txt.gz · Dernière modification : 2020/02/24 12:24 de serge