CONFIGURATION: Module Infrarouge/Led et Télécommande + Bouton (Recalbox)

Publié le : 09/02/2018 22:43:16
Catégories : Tuto, Manuel

INTRODUCTION

OS/Distribution

Recalbox

Raspberry Pi 3 Model B

SOMMAIRE

  • 1-Infrarouge-télécommande: recevoir et décoder les signaux infrarouge de la télécommande Nuxii. Naviguer dans les menus, de contrôler retroarch (LOAD/SAVE,QUIT,RESET....), ou votre environnement linux simplement depuis votre télécommande
  • 2- LEDS: allume une led verte lorsqu'un jeux est lancé et une led rouge quand vous êtes dans le menu
  • 3-Bouton:Eteindre le Raspberry Pi
  • 4-LCD:Afficher la consommation CPU/Memoire, la température, l'heure...
  • 5-LED RGB: Tuning Led RGB

Utilisation

Ce tuto aborde les étapes nécessaires à la mise en fonctionnement des modules intégrables au boitier Nuxii SG et XG avec Recalbox, une distribution Retrogaming pour Raspberry Pi 3 !

Prérequis

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 :

 recalbox à ce jour 17.11

AVERTISSEMENT

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 17.11. AUCUN SUPPORT TECHNIQUE NE SERA APPORTE SUR LES PROBLEMES LIES FUTURES MISES A JOUR

ETAPES

Etape 0 - Preparation de l'OS

Installez Recalbox, connectez-vous en ssh puis lancez les commandes et modifiez les fichiers comme indiqué.

mount -o remount,rw /boot
>mount -o remount,rw /

/boot/config.txt

#dtoverlay=lirc-rpi
++dtoverlay=lirc-rpi,gpio_in_pin=17,gpio_out_pin=0,gpio_in_pull=up

/recalbox/share/system/configs/retroarch/retroarchcustom.cfg
# Enable stdin/network command interface.
++network_cmd_enable = true
++stdin_cmd_enable = true

>mv /boot/overlays/lirc-rpi.dtbo /boot/overlays/lirc-rpi.dtb

#CREATION DES REPERTOIRES

>mkdir ~/json

#CREATION DES FICHIERS SCRIPTS

>tcouch/etc/init.d/S98NuxiiComponents

>touch /recalbox/scripts/nuxii-led.sh

#AJOUT DES DROITS D'EXECUTION


>chmod +x /etc/init.d/S98NuxiiComponents
>chmod +x /recalbox/scripts/nuxii-led.sh

#INSTALLATION DE LA LIBRAIRIE KEYBOARD SUR PYTHON

>wget https://github.com/boppreh/keyboard/archive/master.zip
>unzip master.zip
>mv keyboard-master/keyboard/ /usr/lib/python2.7/

Etape 1 - Infrarouge/Telecommande

BUTTONS CONFIGURATION

/recalbox/share_init/system/.config/lirc/.lircrc

""



begin
prog = irexec
button = KEY_BACK
config = python -m keyboard /recalbox/share/system/json/back.json
repeat = 3
end
begin
prog = irexec
button = KEY_HOME
config = python -m keyboard /recalbox/share/system/json/start.json
repeat = 3
end
begin
prog = irexec
button = KEY_HOME
config = retroarch --command SAVE_STATE
repeat = 3
end
begin
prog = irexec
button = KEY_UP
config = python -m keyboard /recalbox/share/system/json/up.json
repeat = 3
end
begin
prog = irexec
button = KEY_DOWN
config = python -m keyboard /recalbox/share/system/json/down.json
repeat = 3
end
begin
prog = irexec
button = KEY_LEFT
config = python -m keyboard /recalbox/share/system/json/left.json
repeat = 3
end
begin
prog = irexec
button = KEY_RIGHT
config = python -m keyboard /recalbox/share/system/json/right.json
repeat = 3
end
begin
prog = irexec
button = KEY_OK
config = python -m keyboard /recalbox/share/system/json/ok.json
repeat = 3
end
begin
prog = irexec
button = KEY_STOP
config = python -m keyboard /recalbox/share/system/json/select.json
repeat = 3
end
begin
prog = irexec
button = KEY_STOP
config = retroarch --command QUIT
config = killall mupen64plus
repeat = 3
end
begin
prog = irexec
button = KEY_STOP
config = shutdown now
ignore_first_events = 70
end
begin
prog = irexec
button = KEY_PLAY
config = python -m keyboard /recalbox/share/system/json/ok.json
repeat = 3
end
begin
prog = irexec
button = KEY_PLAY
config = retroarch --command PAUSE_TOGGLE
repeat = 3
end
begin
prog = irexec
button = KEY_REWIND
config = python -m keyboard /recalbox/share/system/json/left.json
repeat = 3
end
begin
prog = irexec
button = KEY_FASTFORWARD
config = python -m keyboard /recalbox/share/system/json/right.json
repeat = 3
end
begin
prog = irexec
button = KEY_VOLUMEDOWN
config = amixer set PCM -- $[$(amixer get PCM|grep -o [0-9]*%|sed 's/%//')-1]%
repeat = 3
end
begin
prog = irexec
button = KEY_VOLUMEUP
config = amixer set PCM -- $[$(amixer get PCM|grep -o [0-9]*%|sed 's/%//')+1]%
repeat = 3
end
 

""

NUXII REMOTE CONFIGURATION


wget --output-document /recalbox/share_init/system/.config/lirc/lircd.conf.d/nuxii-remote-lircd.conf http://nuxii.fr/img/cms/configs/nuxii-remote-lircd.conf


SIMULATION DU CLAVIER POUR LES EVENEMENTS

~/json/escape.json

""
{"event_type": "down", "name": "escape", "scan_code": 1}
{"event_type": "up", "name": "escape", "scan_code": 1}

""

#SPACE
~/json/select.json
""

echo '{"event_type": "down", "name": "select", "scan_code": 57}
{"event_type": "up", "name": "select", "scan_code": 57}
""

#ENTER

~/json/enter.json
""

{"event_type": "down", "name": "start", "scan_code": 28}
{"event_type": "up", "name": "start", "scan_code": 28}

""

~/json/up.json
""

{"event_type": "down", "name": "up", "scan_code": 103}
{"event_type": "up", "name": "up", "scan_code": 103}

""

~/json/down.json
""

{"event_type": "down", "name": "down", "scan_code": 108}
{"event_type": "up", "name": "down", "scan_code": 108}

""

~/json/left.json

""

{"event_type": "down", "name": "left", "scan_code": 105}
{"event_type": "up", "name": "left", "scan_code": 105}

""

~/json/right.json
""

{"event_type": "down", "name": "right", "scan_code": 106}
{"event_type": "up", "name": "right", "scan_code": 106}
""

#A KEYBOARD

~/json/back.json

""
{"event_type": "down", "name": "back", "scan_code": 31}
{"event_type": "up", "name": "back", "scan_code": 31}
""


#S KEYBOARD

~/json/ok.json

""
{"event_type": "down", "name": "ok", "scan_code": 30}
{"event_type": "up", "name": "ok", "scan_code": 30}
""

Etape 2 - LEDS

/recalbox/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 retroarch=$(ps -ef | grep retroarch | grep -v "grep" | wc -l)
  if [ $retroarch -eq 0 ]; # If retroarch is not playing
   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


""



#LANCER LE SCRIPT AU BOOT

/etc/init.d/S98NuxiiComponents

""


#!/bin/bash

NAME="nuxii-led.sh"

_start() {
        echo -e "Starting $NAME ...n"
        (sh /recalbox/scripts/nuxii-led.sh)&
}

_stop() {
        echo -e "Stopping $NAME ...n"
        kill $(ps | grep [n]uxii | awk '{ print $1 }')
}

_restart() {

if [ "$(ps | grep -c [n]uxii)" -eq "0" ];
then
        _start
        echo -e "$NAME is now runningn"
else
        _stop
        sleep 2
        _start
fi

}

case "$1" in
 start)
        _start
 ;; stop)
        _stop
 ;; restart)
                _restart

 ;; *)
        echo "Unknown argument "'$1'" "
        exit 1
esac

""

Etape 3 - Bouton

recalbox.conf

#https://github.com/recalbox/recalbox-os/wiki/Add-a-start-stop-button-to-your-recalbox-(EN)

-- #system.power.switch=PIN356ONOFFRESET    # https://github.com/recalbox/recalbox-os/wiki/Add-a-start-stop-button-to-your-recalbox-(EN)

++ system.power.switch=PIN356ONOFFRESET    # https://github.com/recalbox/recalbox-os/wiki/Add-a-start-stop-button-to-your-recalbox-(EN)

##############

REBOOT

>shutdown -r now

Etape 4 - Ecran LCD

Non supporté

Etape 5 - LED RGB

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()

##########EXTRAS############

Advanced troubleshooting tips:

-Vérifiez le câblage

-Verifier le recepteur IR

>lsmod | grep lirc

>irw

>killall lircd

>mode2 -d /dev/lirc0 -m

> ps | grep irexec

> python -m keyboard ~/json/left.json

-Vérifier le module LED

>/etc/init.d/S98NuxiiComponents restart

>sh /recalbox/scripts/nuxii-led.sh

Vérifier le bouton

> ps | grep ".py"

Source: https://github.com/recalbox/recalbox-os/wiki/Infra-red-remote-control-on-the-Recalbox-%28EN%29

Nuxii.frTeam:)

Partager ce contenu