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 15:57] – [Branchement de la MPU 6050à la pyboard lite] 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>
  
Ligne 18: Ligne 19:
  
 ===== Ressources ===== ===== Ressources =====
-  * https://micropython.fr/ +  * [[https://micropython.fr/|micropython.fr]] 
-  * https://micropython.org/ +  * [[https://micropython.org/|micropython.org]] 
-  * https://github.com/micropython/micropython +  * [[https://github.com/micropython/micropython|github.com/micropython]] 
-  * http://docs.micropython.org/en/latest/ +  * [[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 +  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
 +===En terminal===
   picocom /dev/ttyACM0 -b9600   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 reboot: Ctrl + D 
  
 =====Exemple===== =====Exemple=====
   * **MPU 6050** Accéléromètre et Gyroscope    * **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==== ====Documentation sur la MPU 6050====
   * https://www.invensense.com/wp-content/uploads/2015/02/MPU-6000-Datasheet1.pdf   * https://www.invensense.com/wp-content/uploads/2015/02/MPU-6000-Datasheet1.pdf
Ligne 52: Ligne 57:
 ====Les fichiers==== ====Les fichiers====
   * **[[https://github.com/sergeLabo/micropython_mpu6050|micropython_mpu6050 sur GitHub]]**   * **[[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.1582559842.txt.gz · Dernière modification : 2020/02/24 15:57 de serge