Make a Raspberry Pi infrared remote control. The device can programmatically control television sound bar audio volume. The Raspberry Pi uses LIRC (Linux Infrared Remote Control) to send commands to an attached infrared transmitter.
The Python app has three main parts:
- Functions to send commands to the infrared transmitter, which then transmits the commands to the television sound bar
- A Flask web service to accept television command requests (e.g. volume decrease, volume increase)
- A scheduler that automatically sends remote control commands at programmed times (e.g. mute during TV commercials)
Raspberry Pi IR Control Expansion Board. This uses gpio pins 17 out (IR LED), pin 18 in (IR receiver). http://www.raspberrypiwiki.com/index.php/Raspberry_Pi_IR_Control_Expansion_Board
I bought Icstation 38KHz IR Infrared Remote Control Transceiver Shield for Raspberry Pi 2 3 Module B B+ https://www.amazon.com/IR-Remote-Control-Transceiver-Raspberry/dp/B0713SK7RJ/ref=pd_cp_147_1?pd_rd_w=nydwe&pf_rd_p=ef4dc990-a9ca-4945-ae0b-f8d549198ed6&pf_rd_r=NPTQR2NR66SZXGEC1CFF&pd_rd_r=dc222ec9-1d1f-11e9-82b3-7117715d74e2&pd_rd_wg=OnVSD&pd_rd_i=B0713SK7RJ&psc=1&refRID=NPTQR2NR66SZXGEC1CFF
Can attach keyboard and monitor to pi. Alternatively, can connect from another computer on local network via ssh.
ssh -v pi@10.0.0.4
Michael Traver's excellent "Raspberry Pi IR Remote Control" https://github.com/mtraver/rpi-ir-remote has helpful up to date suggestions for configuring current versions of LIRC (0.9.4) and Raspbian (Stretch) and warnings about outdated online info.
sudo apt-get install lirc
The following additional packages will be installed:
libftdi102 liblirc0 python3-yaml
Suggested packages:
lirc-compat-remotes lirc-drv-irman lirc-doc lirc-x setserial ir-keytable
This package is outdated, contains remote definitions which were part of lirc up to 0.9.0.
Add the following content to /boot/config.txt
dtoverlay=lirc-rpi,gpio_in_pin=18,gpio_out_pin=17
In /etc/lirc/lirc_options.conf
- change driver to default
- change device to /dev/lirc0
LIRC 0.9.4 does not use hardware.conf
lirc looks in a configuration directory for files ending in .conf
/etc/lirc/lircd.conf.d
https://sourceforge.net/projects/lirc-remotes/ has config files for many remotes. You can try any of these to see if they work with your device.
I added cxa_cxc_cxn.lircd.conf
pi@raspberrypi:/etc/lirc/lircd.conf.d $ sudo cp ~/beepscore/rpi-ir-remote/config/lirc/cxa_cxc_cxn.lircd.conf .
Use lirc command irsend
irsend list cambridge_cxa ""
000000000000140c KEY_POWER
000000000000140e KEY_POWER_ON
000000000000140f KEY_POWER_OFF
000000000000140d KEY_MUTE
0000000000001432 KEY_MUTE_ON
0000000000001433 KEY_MUTE_OFF
0000000000001410 KEY_VOLUMEUP
0000000000001411 KEY_VOLUMEDOWN
irsend SEND_ONCE cambridge_cxa KEY_VOLUMEDOWN
The front facing camera on iPhone doesn't filter IR. It showed the raspberry pi is lighting the transmit infrared LED. However the remote configuration cambridge_cxa doesn't work with my Polk sound bar receiver.
https://learn.adafruit.com/using-an-ir-remote-with-a-raspberry-pi-media-center/using-other-remotes To disable a configuration file change extension from .conf to e.g. .dist
cd /etc/lirc/lircd.conf.d
sudo mv devinput.lircd.conf devinput.lircd.dist
lirc-remotes has lots of files, but none named polk. Could try existing ones but this could be time consuming. Instead use an existing handheld remote transmitter to "teach" the Raspberry Pi how to act like that remote. The Raspberry Pi IR Control Expansion Board has an infrared receiver. LIRC command irrecord records button press infrared signals. http://www.lirc.org/html/irrecord.html
irrecord -d /dev/lirc0 ~/lircd.conf
Using driver default on device /dev/lirc0
Could not init hardware (lircd running ? --> close it, check permissions)
htop
^C
sudo killall -9 lircd
irrecord --list-namespace
In repo remy_python I added directory config to keep polk.lircd.conf in version control.
cd remy_python/config
irrecord -d /dev/lirc0 ./polk.lircd.conf
irrecord -f -d /dev/lirc0 ~/polk.lircd.conf
Enter valid key names e.g. KEY_VOLUMEDOWN
For LIRC to use configuration file, copied it to
/etc/lirc/lircd.conf.d/polk.lircd.conf
cd remy_python/config
irrecord -f -u ./polk.lircd.conf
Then copy updated file to
/etc/lirc/lircd.conf.d/polk.lircd.conf
irsend list polk ""
0000000000000001 KEY_MUTE
0000000000000002 KEY_POWER
0000000000000003 KEY_VOLUMEUP
0000000000000004 KEY_VOLUMEDOWN
0000000000000005 KEY_UP
0000000000000006 KEY_DOWN
ssh -v pi@10.0.0.4
cd to project directory
cd ~/beepscore/remy_python
If using conda (e.g. via miniconda), activate environment
source activate remy_python
start Flask web server
python3 service.py
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
* Restarting with stat
Now clients on local network can see the remote control service.
http://10.0.0.4:5000/api/v1/tv/ping/
Send a remote control command.
http://10.0.0.4:5000/api/v1/tv/mute/
/api/v1/tv/power/
/api/v1/tv/voice-decrease/
/api/v1/tv/voice-increase/
/api/v1/tv/volume-decrease/
/api/v1/tv/volume-increase/
GET requests can be made via a browser such as Firefox or mobile Safari. POST requests can be made via clients such as terminal curl or POSTMAN or iOS Remy.app
curl --request POST http://10.0.0.4:5000/api/v1/tv/volume-decrease/
pi terminal shows client's ip address and request info
10.0.0.3 - - [23/Jan/2019 23:39:22] "POST /api/v1/tv/volume-decrease/ HTTP/1.1" 200 -
10.0.0.3 - - [23/Jan/2019 23:39:26] "POST /api/v1/tv/volume-increase/ HTTP/1.1" 200 -
On macOS, can install via conda navigator. However I couldn't find conda apscheduler for raspberry pi. So install via pip.
source activate remy_python
pip install apscheduler
To run server and scheduler
source activate remy_python
python service.py
To run scheduler but not server
source activate remy_python
python scheduler.py
Currently unused. Could be used together with closed caption text or speech recognition to detect commercials. Some commercials don't say product/service/company name until late in the commercial.
Can run tests on macOS by temporarily commenting out service.py subprocess.call(irsend). Not sure how to run tests on pi yet.
python -m unittest discover
throws RuntimeError: working outside of request context
http://beepscore.com/website/2019/02/03/raspberry-pi-infrared-remote-control-tv.html
http://beepscore.com/website/2019/02/05/network-enabled-raspberry-pi-tv-remote-control.html
http://beepscore.com/website/2019/04/21/automatically-detecting-television-commercials.html
https://github.com/beepscore/tv_commercial_silencer
Remote control television by sending commands from iOS device to a server. https://github.com/beepscore/Remy
by Michael Traver https://github.com/mtraver/rpi-ir-remote
https://www.raspberrypi.org/forums/viewtopic.php?t=202375
https://andicelabs.com/2017/11/lirc-raspberry-pi/
https://raspberrypi.stackexchange.com/questions/70945/setting-up-a-remote-control-using-lirc
http://www.raspberry-pi-geek.com/Archive/2015/10/Raspberry-Pi-IR-remote
https://www.hackster.io/austin-stanton/creating-a-raspberry-pi-universal-remote-with-lirc-2fd581
http://opensourceuniversalremote.com/
http://alexba.in/blog/2013/06/08/open-source-universal-remote-parts-and-pictures/
https://github.com/project-owner/Peppy.doc/wiki/Pylirc
lirc_node is an npm module that acts as a very thin shim between LIRC and Node. https://github.com/alexbain/lirc_node
http://www.raspberrypiwiki.com/index.php/Raspberry_Pi_IR_Control_Expansion_Board
http://www.raspberrypiwiki.com/index.php/Raspberry_Pi_IR_Control_Expansion_Board
https://www.amazon.com/Raspberry-Controller-Transmitter-Transceiver-Geekworm/dp/B076BDR34K
https://www.amazon.com/WINGONEER-Infrared-Control-Transceiver-Raspberry/dp/B072QWXLK2
https://www.instructables.com/id/Raspberry-Pi-Zero-Universal-Remote/
SparkFun WiFi IR Blaster (ESP8266) https://www.sparkfun.com/products/15031
https://github.com/mdhiggins/ESP8266-HTTP-IR-Blaster
https://www.raspberrypi.org/learning/python-web-server-with-flask/worksheet
https://github.com/beepscore/basic_flask https://www.raspberrypi.org/learning/python-web-server-with-flask/worksheet
http://mattrichardson.com/Raspberry-Pi-Flask/
http://beepscore.com/using-raspberry-pi-to-end-iphone-phone-call/
A simple Python flask web service to read and write Raspberry Pi GPIO. https://github.com/beepscore/pi_gpio_service
https://github.com/CorrosiveKid/raspberrypi-gpio-api
http://randomnerdtutorials.com/raspberry-pi-web-server-using-flask-to-control-gpios/
https://makezine.com/2011/08/16/enough-already-the-arduino-solution-to-overexposed-celebs/