Publié le : 05/02/2018 12:33:43
Catégories : Tutoriels
Raspbian Stretch v4.9
Raspberry Pi 3 Model B
Ce tuto aborde les étapes nécessaires à la mise en fonctionnement des modules intégrables au boitier Nuxii SG et XG avec Raspbian, une distribution issue d'un portage de Debian pour Raspberry Pi 3 !
Raspberry Pi 3, Bouton Nuxii, Module infrarouge Led + Télécommande, LCD16x2, LED RGB
Niveau de difficulté: 3/5
Accès ssh
Commandes de bases Unix
Versions utilisées :
- Raspbian Stretch téléchargé sur le site officiel de RasberryPi
- lircd 0.9.4c
- LCDd 0.5.7
CERTAINES ETAPES PEUVENT NÉCESSITER UN ACCES INTERNET
ATTENTION: LES MISES A JOURS PEUVENT SUPPRIMER CERTAINES CONFIGURATIONS. ASSUREZ-VOUS DE SUIVRE DE NOUVEAU CES ETAPES EN CAS PROBLEME APRES MAJ.
NOTE: CE TUTORIEL N'A ETE TESTE QUE SUR LA VERSION INDIQUEE EN TETE DE PAGE. AUCUN SUPPORT TECHNIQUE NE SERA APPORTE SUR LES PROBLEMES LIES AUX FUTURES MISES A JOUR
# Modification du mot de passe de l'utilisateur pi
sudo passwd pi
# Mise à jour de la liste des dépôts
sudo apt-get update
# Mise à jour des paquets
sudo apt-get upgrade
# Creation du dossier contenant les scripts
mkdir /home/pi/scripts
1.1 Brancher le module IR LED
Le tutoriel est disponible ici : https://nuxii.fr/fr/blog/brancher-le-module-infrarouge-leds-n40
2.2 Configurer le module
# Installation du paquet pour la gestion de ire
sudo apt-get install lirc
éditer le fichier suivant :
sudo vi /boot/config.txt
Remplacer la nouvelle ligne ci-dessous :
#dtoverlay=
par celle-ci :
dtoverlay=lirc-rpi,gpio_in_pin=17,gpio_out_pin=7
# Redémarrer pour la prise en compte
sudo reboot
# Convertion vers la nouvelle syntaxe
sudo /usr/share/lirc/lirc-old2new
# Est-ce que les touches sont bien vues ?
sudo systemctl stop lircd
mode2 -d /dev/lirc0
# Appairage des touches
irrecord -f -d /dev/lirc0
#Suivez les instructions (nommez la télécommande nuxii) puis déplacez le fichier dans le dossier de configuration
cp nuxii.lircd.conf /etc/lirc/lircd.conf.d/
ou
=> Fournir le fichier
# Test de l'appairage
sudo irw
# Configuration de l'action des touches avec des commandes personalisées
sudo vi /etc/lirc/irexec.lircrc
begin
prog = irexec
button = KEY_BACK
config = echo "Test" > /tmp/test
end
systemctl enable irexec
systemctl start irexec
ou
creer un fichier de configuration pour un programme natif:
#Vérifiez les programmes compatibles
lirc-config-tool -l
#Creer un template de fichier de configuration
lirc-config-tool -o . vlc
#Modifiez le fichier de configuration
begin
prog = vlc
button = KEY_BACK
config = key-audiodevice-cycle
end
begin
prog = vlc
button = KEY_HOME
config = key-quit
end
begin
prog = vlc
button = KEY_UP
config = key-audiotrack
end
begin
prog = vlc
button = KEY_DOWN
config = key-subtitle-track
end
begin
prog = vlc
button = KEY_LEFT
config = key-previous
end
begin
prog = vlc
button = KEY_RIGHT
config = key-next
end
begin
prog = vlc
button = KEY_OK
config = key-play-pause
end
begin
prog = vlc
button = KEY_STOP
config = key-quit
end
begin
prog = vlc
button = KEY_PLAY
config = key-play-pause
end
begin
prog = vlc
button = KEY_REWIND
config = key-slower
end
begin
prog = vlc
button = KEY_FASTFORWARD
config = key-faster
end
begin
prog = vlc
button = KEY_VOLUMEDOWN
config = key-vol-down
end
begin
prog = vlc
button = KEY_VOLUMEUP
config = key-vol-up
end
#Activer la gestion depuis une télécommande infrarouge dans VLC
Outils -> Préférences -> Afficher les paramètres (Tous) -> Interface de contrôle -> Cocher "Interface de controle par infrarouge"
#Activer le fichier de script
Outils -> Préférences -> Afficher les paramètres (Tous) -> Interface de contrôle -> Infrared -> "/home/pi/vlc.lircrc"
Redémmarez VLC et testez
Notre objectif est d'allumer/eteindre les leds rouge et verte quand le seuil de température du CPU passe les 60 degrés Celcius
/home/pi/scripts/nuxii-led.sh
#!/bin/bash
LED1=27
LED2=22
cd /sys/class/gpio/
if [ -e /sys/class/gpio/export ]
then
echo "$LED1" > /sys/class/gpio/export
echo "$LED2" > /sys/class/gpio/export
fi
echo out > /sys/class/gpio/gpio$LED1/direction
echo 0 > /sys/class/gpio/gpio$LED1/value
echo out > /sys/class/gpio/gpio$LED2/direction
echo 1 > /sys/class/gpio/gpio$LED2/value
while true;
do cpu=$(cat /sys/class/thermal/thermal_zone0/temp)
cpu=$(($cpu+0))
echo $cpu
if [ $cpu -lt 60000 ]; # CPU Temperature over 60 c
then
echo 0 > /sys/class/gpio/gpio$LED1/value
echo 1 > /sys/class/gpio/gpio$LED2/value
else
echo 0 > /sys/class/gpio/gpio$LED2/value
echo 1 > /sys/class/gpio/gpio$LED1/value
fi
sleep 1
done
sudo vi /lib/systemd/system/nuxii-led.service
[Unit]
Description=ShutdownScript
After=multi-user.target
[Service]
Type=idle
ExecStart=/home/pi/scripts/nuxii-led.sh
[Install]
WantedBy=multi-user.target
sudo chmod 644 /lib/systemd/system/nuxii-led.service
sudo systemctl daemon-reload
sudo systemctl enable nuxii-led.service
3.1 Brancher le bouton
Le tutoriel est disponible ici : https://nuxii.fr/fr/blog/brancher-le-bouton-poussoir-n38
3.2 Configurer le bouton
/home/pi/scripts/shutdown.py
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import subprocess
GPIOBUTTON=23
LEDBUTTON=14
def initGlobals():
GPIO.setmode(GPIO.BCM)
GPIO.setup(GPIOBUTTON, GPIO.IN)
GPIO.setup(LEDBUTTON, GPIO.OUT)
def fct():
subprocess.call("shutdown -h now", shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
#########################################
#MAIN - entry point
if __name__ == '__main__':
initGlobals()
GPIO.output(LEDBUTTON, GPIO.HIGH)
GPIO.setup(GPIOBUTTON, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.wait_for_edge(GPIOBUTTON, GPIO.FALLING, bouncetime=300)
fct()
GPIO.remove_event_detect(GPIOBUTTON)
GPIO.cleanup(GPIOBUTTON)
GPIO.cleanup(LEDBUTTON)
#########################################
sudo vi /lib/systemd/system/shutdown.service
[Unit]
Description=ShutdownScript
After=multi-user.target
[Service]
Type=idle
ExecStart=/usr/bin/python /home/pi/scripts/shutdown.py
[Install]
WantedBy=multi-user.target
#Ajout des droits :
sudo chmod 644 /lib/systemd/system/shutdown.service
sudo systemctl daemon-reload
sudo systemctl enable shutdown.service
4.1 Brancher l'écran
Le tutoriel est disponible ici : https://nuxii.fr/fr/blog/souderbrancher-l-afficheur-lcd-n39
4.2 Configurer l'écran
apt-get install lcdproc i2c-tools
wget -O /usr/lib/arm-linux-gnueabihf/lcdproc/ https://github.com/wilberforce/lcdproc/raw/master/hd44780.so
raspi-config
->Interface options
->Activate i2c
## Server section with all kinds of settings for the LCDd server
[server]
DriverPath=/usr/lib/arm-linux-gnueabihf/lcdproc/
++Driver=hd44780
NextScreenKey=Right
PrevScreenKey=Left
ReportToSyslog=yes
ToggleRotateKey=Enter
[menu]
DownKey=Down
EnterKey=Enter
MenuKey=Escape
UpKey=Up
[hd44780]
ConnectionType=i2c
# Port where the LPT is. Usual value are: 0x278, 0x378 and 0x3BC
Port=0x27
# Device of the serial interface [default: /dev/lcd]
Device=/dev/i2c-1
# Bitrate of the serial port (0 for interface default)
Speed=0
# Specifies the size of the LCD.
# In case of multiple combined displays, this should be the total size.
Size=16x2
CharMap=hd44780_default
DelayMult=4
#You may need to change some values depending on what i2c baclpack you use
i2c_line_RS=0x01
i2c_line_RW=0x02
i2c_line_EN=0x04
i2c_line_BL=0x08
i2c_line_D4=0x10
i2c_line_D5=0x20
i2c_line_D6=0x40
i2c_line_D7=0x80
Backlight=yes
BacklightInvert=yes
#Testez avec lcdproc
lcdproc -f
#Modifiez le fichier à votre convenance
/etc/lcdproc.conf
[BigClock]
# Show screen
Active=false
Se référer à l'article ...
5.1 Brancher la LED
Le tutoriel est disponible ici : ...
5.2 Configurer la LED
/home/pi/scripts/nuxii-ledrgb.py
import RPi.GPIO as GPIO
import threading
import time
import random
R = 21
G = 19
B = 23
PINS = [R,G,B]
def initialize_gpio():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(PINS, GPIO.OUT, initial=GPIO.LOW)
def color_test(channel, frequency, speed, step):
p = GPIO.PWM(channel, frequency)
p.start(0)
while True:
for dutyCycle in range(0, 101, step):
p.ChangeDutyCycle(dutyCycle)
time.sleep(speed)
for dutyCycle in range(100, -1, -step):
p.ChangeDutyCycle(dutyCycle)
time.sleep(speed)
def color_test_thread():
threads = []
threads.append(threading.Thread(target=color_test, args=(R, 300, 0.02, 5)))
threads.append(threading.Thread(target=color_test, args=(G, 300, 0.035, 5)))
threads.append(threading.Thread(target=color_test, args=(B, 300, 0.045, 5)))
for t in threads:
t.daemon = True
t.start()
for t in threads:
t.join()
def main():
try:
initialize_gpio()
print("nPress ^C (control-C) to exit the program.n")
color_test_thread()
except KeyboardInterrupt:
pass
finally:
GPIO.cleanup()
if __name__ == '__main__':
main()
/lib/systemd/system/nuxii-ledrgb.service
[Unit]
Description=LED RGB
After=multi-user.target
[Service]
Type=idle
ExecStart= /usr/bin/python /home/pi/scripts/ledrgb.py
[Install]
WantedBy=multi-user.target
#Ajout des droits :
sudo chmod 644 /lib/systemd/system/nuxii-ledrgb.service
sudo systemctl daemon-reload
sudo systemctl enable nuxii-ledrgb.service