Différences entre versions de « Rasp-Hack-Afficheur-LCD-Python »
(Page créée avec « {{Rasp-Hack-Afficheur-LCD-NAV}} xx {{Rasp-Hack-Afficheur-LCD-TRAILER}} ») |
|||
Ligne 1 : | Ligne 1 : | ||
{{Rasp-Hack-Afficheur-LCD-NAV}} | {{Rasp-Hack-Afficheur-LCD-NAV}} | ||
− | + | The Python code for Adafruit's Character LCDs on the Pi is available on Github at [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: | ||
+ | |||
+ | * '''Adafruit_CharLCD.py''' : contains python class for LCD control | ||
+ | * '''Adafruit_CharLCD_IPclock_example.py''' : code for IP address and date/time calls methods from 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]. | ||
+ | |||
+ | 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"): | ||
+ | |||
+ | <nowiki>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</nowiki> | ||
+ | |||
+ | == 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 | ||
+ | |||
+ | If you're using a '''Version 2 Raspberry Pi''', pin '''#21''' has been replaced with pin '''#27''' so edit Adafruit_CharLCD.py and change: | ||
+ | |||
+ | def __init__(self, pin_rs=25, pin_e=24, pins_db=[23, 17, '''21''', 22], GPIO = None): | ||
+ | |||
+ | to | ||
+ | |||
+ | 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 | ||
+ | |||
+ | <nowiki>chmod +x Adafruit_CharLCD.py | ||
+ | sudo ./Adafruit_CharLCD.py</nowiki> | ||
+ | |||
+ | == L'exemple Horloge + IP == | ||
+ | |||
+ | {{Ambox | ||
+ | | type = delete | ||
+ | | image = [[File:StopHand.png|40px|alt=Stop]] | ||
+ | | 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! | ||
+ | }} | ||
+ | |||
+ | <nowiki>#!/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) | ||
+ | </nowiki> | ||
+ | |||
+ | == Executer le code == | ||
+ | |||
+ | === Démarrer l'exemple IP + horloge === | ||
+ | |||
+ | $ sudo ./Adafruit_CharLCD_IPclock_example.py | ||
+ | |||
+ | === Résultat === | ||
+ | |||
+ | Ce que vous devriez voir: | ||
+ | |||
+ | [[Fichier:Rasp-Hack-Afficheur-LCD-Python-01.jpg]] | ||
{{Rasp-Hack-Afficheur-LCD-TRAILER}} | {{Rasp-Hack-Afficheur-LCD-TRAILER}} |
Version du 27 janvier 2013 à 17:10
The Python code for Adafruit's Character LCDs on the Pi is available on Github at [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:
- Adafruit_CharLCD.py : contains python class for LCD control
- Adafruit_CharLCD_IPclock_example.py : code for IP address and date/time calls methods from 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 nice python class. His work is the baseline that is slowly being changed as we are bringing in more elements from the Arduino LiquidCrystal library.
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"):
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
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
If you're using a Version 2 Raspberry Pi, pin #21 has been replaced with pin #27 so edit Adafruit_CharLCD.py and change:
def __init__(self, pin_rs=25, pin_e=24, pins_db=[23, 17, 21, 22], GPIO = None):
to
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
chmod +x Adafruit_CharLCD.py sudo ./Adafruit_CharLCD.py
L'exemple Horloge + IP
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! |
#!/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:
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.