Différences entre versions de « Rasp-Hack-Afficheur-LCD-Python »

De MCHobby - Wiki
Sauter à la navigation Sauter à la recherche
Ligne 4 : Ligne 4 :
  
 
{{bloc-etroit
 
{{bloc-etroit
   |text = The Python code for Adafruit's Character LCDs on the Pi is available on Github at
+
   |text = Le code Python Raspberry-Pi produit par Adafruit pour l'afficheur LCDest disponible sur Github à
 
[https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code]
 
[https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code]
  
There are two files we will be working with:
+
Nous allons travailler avec deux fichiers:
  
* '''Adafruit_CharLCD.py''' : contains python class for LCD control
+
* '''Adafruit_CharLCD.py''' : contient la classe python pour le contrôle LCD
* '''Adafruit_CharLCD_IPclock_example.py''' : code for IP address and date/time calls methods from Adafruit_CharLCD.py
+
* '''Adafruit_CharLCD_IPclock_example.py''' : Code pour l'affichage de l'adresse IP et date/heure. Appelle les méthodes de  Adafruit_CharLCD.py
  
  
The first file Adafruit_CharLCD.py is a mashup from two different sources of LCD code. Github user lrvick put together a [https://github.com/lrvick/raspi-hd44780/blob/master/hd44780.py nice python class]. His work is the baseline that is slowly being changed as we are bringing in more elements from the [https://github.com/arduino/Arduino/tree/master/libraries/LiquidCrystal Arduino LiquidCrystal library].  
+
Le premier fichier Adafruit_CharLCD.py est un mélange de deux code sources LCD différent. L'utilisateur lrvick sur Github à rassembler ces deux sources dans [https://github.com/lrvick/raspi-hd44780/blob/master/hd44780.py une excellente classe python]. Son travail est à la base de la librairie que nous proposons. Nous avons en effet adapté le code pour y inclure plus d'éléments de [https://github.com/arduino/Arduino/tree/master/libraries/LiquidCrystal la librairie LiquidCrystal d'Arduino].  
  
The easiest way to get the code onto your Pi is to hook up an Ethernet cable, and clone it directly using 'git', which is installed by default on most distros. Simply run the following commands from an appropriate location (ex. "/home/pi"):
+
La meilleure façon d'installer ce code sur votre Pi est d'y raccorder un cable Ethernet, et d'en prendre une copie (clone) directement en utilisant 'git', qui est installé par défaut sur beaucoup de distributions. Exécutez les commandes suivantes depuis un répertoire approprié (ex: "/home/pi"):
 
}}
 
}}
  
Ligne 25 : Ligne 25 :
 
== Tester ==
 
== Tester ==
  
You can test the wiring from the previous step by simply running the  Adafruit_CharLCD.py python code, as it has a little code it in that will simply display a test message when wired correctly
+
Vous pouvez tester le câblage réalisé lors des étapes précédentes en exécutant le code python de Adafruit_CharLCD.py . Il ne dispose que d'un peu de code... et si tout est raccordé correctement, vous verrez apparaître un message de test.
  
If you're using a '''Version 2 Raspberry Pi''', pin '''#21''' has been replaced with pin '''#27''' so edit Adafruit_CharLCD.py and change:
+
Si vous utilisez un '''Raspberry Pi Version 2''',alors la broche '''#21''' de la carte à été remplacée avec la broche '''#27'''. Il faudra donc modifier Adafruit_CharLCD.py et changer la ligne:
  
 
  def __init__(self, pin_rs=25, pin_e=24, pins_db=[23, 17, '''21''', 22], GPIO = None):
 
  def __init__(self, pin_rs=25, pin_e=24, pins_db=[23, 17, '''21''', 22], GPIO = None):
  
to
+
par
  
 
  def __init__(self, pin_rs=25, pin_e=24, pins_db=[23, 17, '''27''', 22], GPIO = None):
 
  def __init__(self, pin_rs=25, pin_e=24, pins_db=[23, 17, '''27''', 22], GPIO = None):
  
  
you can use '''nano Adafruit_CharLCD.py''' to edit
+
vous pouvez utiliser la commande '''nano Adafruit_CharLCD.py''' pour modifier le fichier
  
 
  <nowiki>chmod +x Adafruit_CharLCD.py
 
  <nowiki>chmod +x Adafruit_CharLCD.py
Ligne 47 : Ligne 47 :
 
| image      = [[File:StopHand.png|40px|alt=Stop]]
 
| image      = [[File:StopHand.png|40px|alt=Stop]]
 
| textstyle  = color: red; font-weight: bold; font-style: italic;
 
| textstyle  = color: red; font-weight: bold; font-style: italic;
| text      = This script assumes you'll want to display the Ethernet (eth0) IP address. You may want to replace eth0 with wlan0 or wlan1 (etc) for Wireless IP address!  
+
| text      = Ce script par du principe que c'est l'adresse IP de la connexion filaire Ethernet (eth0) qui sera affichée. Vous pourriez avoir envie de remplacer eth0 par wlan0 ou wlan1 (etc) pour les adresses IP des réseaux Wifi!  
 
}}
 
}}
  

Version du 30 janvier 2013 à 12:09

Code Python

Le code Python Raspberry-Pi produit par Adafruit pour l'afficheur LCDest disponible sur Github à https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code

Nous allons travailler avec deux fichiers:

  • Adafruit_CharLCD.py : contient la classe python pour le contrôle LCD
  • Adafruit_CharLCD_IPclock_example.py : Code pour l'affichage de l'adresse IP et date/heure. Appelle les méthodes de Adafruit_CharLCD.py


Le premier fichier Adafruit_CharLCD.py est un mélange de deux code sources LCD différent. L'utilisateur lrvick sur Github à rassembler ces deux sources dans une excellente classe python. Son travail est à la base de la librairie que nous proposons. Nous avons en effet adapté le code pour y inclure plus d'éléments de la librairie LiquidCrystal d'Arduino.

La meilleure façon d'installer ce code sur votre Pi est d'y raccorder un cable Ethernet, et d'en prendre une copie (clone) directement en utilisant 'git', qui est installé par défaut sur beaucoup de distributions. Exécutez les commandes suivantes depuis un répertoire approprié (ex: "/home/pi"):

apt-get install git
git clone git://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code.git
cd Adafruit-Raspberry-Pi-Python-Code
cd Adafruit_CharLCD

Tester

Vous pouvez tester le câblage réalisé lors des étapes précédentes en exécutant le code python de Adafruit_CharLCD.py . Il ne dispose que d'un peu de code... et si tout est raccordé correctement, vous verrez apparaître un message de test.

Si vous utilisez un Raspberry Pi Version 2,alors la broche #21 de la carte à été remplacée avec la broche #27. Il faudra donc modifier Adafruit_CharLCD.py et changer la ligne:

def __init__(self, pin_rs=25, pin_e=24, pins_db=[23, 17, 21, 22], GPIO = None):

par

def __init__(self, pin_rs=25, pin_e=24, pins_db=[23, 17, 27, 22], GPIO = None):


vous pouvez utiliser la commande nano Adafruit_CharLCD.py pour modifier le fichier

chmod +x Adafruit_CharLCD.py
sudo ./Adafruit_CharLCD.py

L'exemple Horloge + IP

#!/usr/bin/python
     
from Adafruit_CharLCD import Adafruit_CharLCD
from subprocess import *
from time import sleep, strftime
from datetime import datetime
     
lcd = Adafruit_CharLCD()
     
cmd = "ip addr show eth0 | grep inet | awk '{print $2}' | cut -d/ -f1"
     
lcd.begin(16,1)
     
def run_cmd(cmd):
    p = Popen(cmd, shell=True, stdout=PIPE)
    output = p.communicate()[0]
    return output
     
while 1:
    lcd.clear()
    ipaddr = run_cmd(cmd)
    lcd.message(datetime.now().strftime('%b %d %H:%M:%S\n'))
    lcd.message('IP %s' % ( ipaddr ) )
    sleep(2)

Executer le code

Démarrer l'exemple IP + horloge

$ sudo ./Adafruit_CharLCD_IPclock_example.py 

Résultat

Ce que vous devriez voir:

Rasp-Hack-Afficheur-LCD-Python-01.jpg


Source: Character LCD with Raspberry Pi or BeagleBone Black écrit par Tony Dicola pour Adafruit Industries.

Traduit avec l'autorisation d'AdaFruit Industries - Translated with the permission from Adafruit Industries - www.adafruit.com

Toute référence, mention ou extrait de cette traduction doit être explicitement accompagné du texte suivant : «  Traduction par MCHobby (www.MCHobby.be) - Vente de kit et composants » avec un lien vers la source (donc cette page) et ce quelque soit le média utilisé.

L'utilisation commercial de la traduction (texte) et/ou réalisation, même partielle, pourrait être soumis à redevance. Dans tous les cas de figures, vous devez également obtenir l'accord du(des) détenteur initial des droits. Celui de MC Hobby s'arrêtant au travail de traduction proprement dit.