Read about InfraRed communication. In brief, we transfer data through IR light. Continuous On-Off generates binary stream. IR Transmitter and IR Receiver are two modules that enable this communication.
This is part of something large that I was trying to build and I needed a basic IR transceiver system that, after much experimentation, I decided to build with a Raspberry Pi because of high memory requirements of my solution.
First thing,Setup Raspberry with Noobs, setup for remote access with a USB WiFi dongle. Remote login, since UI access is not needed anymore and
# updates
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo rpi-update
sudo apt-get clean
Some of the commands above may be redundant, I didn’t bother to look into them and understand. Good to be on top of tree…
Install LIRCsudo apt-get install lirc
#Add following to /etc/modules
lirc_dev
#Rx - 23, Tx = 18
lirc_rpi gpio_in_pin=23 gpio_out_pin=18
GPIO Pin 22 corresponds to Pin 15 and GPIO Pin 23 corresponds to Pin 16 on RPi. All the configurations use GPIO pin numbers. Below PinOut diagrams from www.raspberrypi.org
Physical Pin Numbers
GPIO Pin Numbers
Continue with changes…
#following changes to /etc/lirc/hardware.conf
LIRCD_ARGS="--uinput"
DRIVER="default"
DEVICE="/dev/lirc0"
MODULES="lirc_rpi"
#uncomment and update /boot/config.txt
dtoverlay=lirc-rpi,gpio_in_pin=23,gpio_out_pin=18
#restart service to test
sudo /etc/init.d/lirc restart
[ ok ] Restarting lirc (via systemctl): lirc.service.
Keyes IR components PinOut$ sudo /etc/init.d/lirc stop
[ ok ] Stopping lirc (via systemctl): lirc.service.
$ mode2 -d /dev/lirc0
Point a remote to Rx module and press a key, on receiving IR signals an onboard LED blinks on the Rx module. You will see similar output as below
space 16777215
pulse 7704288
space 169
pulse 106
space 1903
space 10811
pulse 33
space 287800
pulse 103351
You need to sanitize these codes and then play them through your transmitter. There are tools to help learn and play these codes.
Note: Codes for a lot of remotes has been recorded and contributed by community and can be downloaded from Lirc Remotes. These needs to be copied to /etc/lirc/lircd.conf.
$ irsend SEND_ONCE LG_TV KEY_POWER
$ irsend --help
Usage: irsend [options] DIRECTIVE REMOTE CODE [CODE...]
DIRECTIVE
SEND_ONCE - send CODE [CODE ...] once
SEND_START - start repeating CODE
SEND_STOP - stop repeating CODE
LIST - list configured remote items
SET_TRANSMITTERS - set transmitters NUM [NUM ...]
SIMULATE - simulate IR event
REMOTE
Name of remote whose configuration to use from lircd.conf
CODE
Key code as saved in lircd.conf
e.g: $ irsend SEND_ONCE LG_TV KEY_POWER
irsend might throw errors, you may want to run lircd -n to get details, -d if error says “could not get file information for /dev/lirc”
$ sudo lircd -n -d /dev/lirc0
lircd-0.9.0-pre1[15822]: lircd(default) ready, using /var/run/lirc/lircd
lircd-0.9.0-pre1[15822]: accepted new client on /var/run/lirc/lircd
lircd-0.9.0-pre1[15822]: removed client
lircd-0.9.0-pre1[15822]: accepted new client on /var/run/lirc/lircd
lircd-0.9.0-pre1[15822]: removed client
Finally, to confirm if IR LED is blinking, see it through your phone camera! (most WebCams have IR Filters, phone cameras don’t).
Comments