dimanche 24 octobre 2021

Raspberry Pi to remote control a NAD C325 bee using Lirc

Install lirc :

pi@moode:~ $ sudo apt update

pi@moode:~ $ sudo apt install lirc

Find setting for NAD:

pi@moode:~ $ irdb-get find nad
morgan's_daytona/Tornado.lircd.conf
nad/451.lircd.conf
nad/AVR2.lircd.conf
nad/AVR2.lircd.conf
nad/CDP-5425.lircd.conf
nad/RC512.lircd.conf
nad/SR6.lircd.conf
nad/SR712.lircd.conf


Ok, i choose SR6 (NAD_SR712 seems working also):

pi@moode:~ $ irdb-get download nad/SR6.lircd.conf 

Downloaded https://sourceforge.net/p/lirc-remotes/code/ci/master/tree/remotes/nad/SR6.lircd.conf as SR6.lircd.conf

and copy to etc folder:

pi@moode:~ $ sudo cp SR6.lircd.conf /etc/lirc/lircd.conf.d/

( or downloard lirc remote setting for NAD (325 use SR5 but SR6 seems working..) :

wget http://lirc.sourceforge.net/remotes/nad/SR6

)

Setup GPIO

GPIO 22 is used to transmit remote code by a simple NPN transistor and an IR LED:


Q1 ie.: 2N2222, R1 could be 4K7 and R2 100
IR LED can be salvaged from an old remote control.

Edit /boot/config.txt and add GPIO output line at the end :

pi@moode:~ $ sudo nano /boot/config.txt

dtoverlay=gpio-ir-tx,gpio_pin=22

Setup LIRC

Edit /etc/lirc/lirc_options.conf as follows by changing these two lines:
 
pi@moode:~ $ sudo nano /etc/lirc/lirc_options.conf
 
###driver = devinput
driver = default

Remove suffix .dist from /etc/lirc/lircd.conf.dist
pi@moode:~ $ sudo cp /etc/lirc/lircd.conf.dist /etc/lirc/lircd.conf

Reboot

pi@moode:~ $ sudo reboot

Test by sending code to NAD

First you check your hardware using your smartphone camera, IR codes are visible.

Send 100 times the code KEY_POWER:

pi@moode:~ $ irsend SEND_ONCE NAD_SR6 KEY_POWER -#100
 
You should see the IR LED flashing for 1 or 2 seconde

Turn on the amplifier after booting with a service !

pi@moode:~ $ sudo nano /etc/systemd/system/amplifierOn.service
 
[Unit] 
Description=Set up amplifier 
After=lircd.service 
[Service] 
Type=oneshot 
RemainAfterExit=true 
ExecStart=/usr/bin/irsend SEND_ONCE NAD_SR6 KEY_POWER -#3
ExecStop=/usr/bin/irsend SEND_ONCE NAD_SR6 KEY_SLEEP -#3
[Install] 
WantedBy=multi-user.target

Make this file executable:

pi@moode:~ $ sudo chown root:root /etc/systemd/system/amplifierOn.service
pi@moode:~ $ sudo chmod 666 /etc/systemd/system/amplifierOn.service



Save and test the service:
pi@moode:~ $ sudo systemctl start /etc/systemd/system/amplifierOn.service

Enable the service:

pi@moode:~ $ sudo systemctl enable /etc/systemd/system/amplifierOn.service

If you got an error like : 

Failed to start etc-systemd-system-amplifierOn.service.mount: Unit etc-systemd-system-amplifierOn.service.mount not found.

Just reboot and check service status:

pi@moode:~ $ sudo systemctl status amplifierOn.service 

That should return something like:

● amplifierOn.service - Set up amplifier
   Loaded: loaded (/etc/systemd/system/amplifierOn.service; enabled; vendor preset: enabled)
   Active: active (exited) since Wed 2022-01-26 08:47:39 CET; 6min ago
 Main PID: 482 (code=exited, status=0/SUCCESS)
    Tasks: 0 (limit: 2063)
   CGroup: /system.slice/amplifierOn.service

Jan 26 08:47:39 moode systemd[1]: Starting Set up amplifier...
Jan 26 08:47:39 moode irsend[482]: lirc_command_run: Sending: SEND_ONCE NAD_SR6 KEY_POWER 3
Jan 26 08:47:39 moode irsend[482]: lirc_command_run, state: 0, input: "BEGIN"
Jan 26 08:47:39 moode irsend[482]: lirc_command_run, state: 1, input: "SEND_ONCE NAD_SR6 KEY_POWER 3"
Jan 26 08:47:39 moode irsend[482]: lirc_command_run, state: 2, input: "SUCCESS"
Jan 26 08:47:39 moode irsend[482]: lirc_command_run, state: 3, input: "END"
Jan 26 08:47:39 moode irsend[482]: lirc_command_run: data:END, status:0
Jan 26 08:47:39 moode systemd[1]: Started Set up amplifier. 


Which indicates that everything is working normally... if not... good luck !

1 commentaire: