It is already a while that I have the feeling that the responsiveness of the raspberry controlled car is not really satisfying. Always I have the feeling it responds a fraction later. Last week I was changing the tv channel using the remote control. I noticed buttons like forward, backward, up arrow, back arrow, …. I was immediately thinking that this could be the solution to my problem. Why not control my Raspberry controlled car with a simple remote control instead of a JavaFX application. To be able to do that I need an infrared receiver and of course the software to glue everything together. So I started looking on the internet for information. Rapidly I found information about lirc (Linux Infrared Remote Control). This is a Linux package that makes it possible to send and decode infrared signals.
As infra red receiver for example you can use a TSOP2136. You can find the datasheet on TSOP2136 Make sure you do the wiring correct. There are only 3 wires. A data wire, supply voltage wire and a ground wire. Depending on the sensor the order can be different so watch out.
Connect the sensor data pin to the GPIO 18 pin (or another but make sure this is also mentioned in the configs), connect the sensor ground pin to the ground pin and the sensor supply voltage pin to the 3.3V pin.
To get lirc installed use the following command
sudo apt-get install lirc
Some configurations need to be done.
Add the following to /etc/modules
Important notice is that GIO pin 18 (BroadCom GPIO pin number-> not PI4J/WiringPi GPIO pin number) will serve as data input from the infrared sensor.
Create or modify the following file (/etc/lirc/hardware.conf) with the contents here under :
# Arguments which will be used when launching lircd
#Don't start lircmd even if there seems to be a good config file
#Don't start irexec, even if a good config file seems to exist.
#Try to load appropriate kernel modules
# Run "lircd --driver=help" for a list of supported drivers.
# usually /dev/lirc0 is the correct setting for systems using udev
# Default configuration files for your hardware if any
Restart Lirc to be sure the changes a described above are taken.
sudo /etc/init.d/lirc stop
sudo /etc/init.d/lirc start
Add the following line to /boot/config.txt :
When done reboot your raspberry pi and than launch the following commands :
sudo /etc/init.d/lirc stop
mode2 -d /dev/lirc0
Now take your remote control and push any button. You should see something similar like this :
pi@raspberrypi ~ $ sudo /etc/init.d/lirc stop
[ ok ] Stopping remote control daemon(s): LIRC:.
pi@raspberrypi ~ $ mode2 -d /dev/lirc0
When you want to work with the remote control you will have to create or generate an lirc configuration file because you will need to configure what signal corresponds with what button (action) on the remote control. To do this you can launch the following command :
irrecord -d /dev/lirc0 ~/lircd.conf
lircd.conf is the configuration file that will be generated. Follow all steps when using irrecord. In my case I got the following content in my config file.
# Please make this file available to others
# by sending it to <email@example.com>
# this config file was automatically generated
# using lirc-0.9.0-pre1(default) on Tue Feb 2 19:09:14 2016
# contributed by
# brand: /home/pi/lircd.conf.conf
# model no. of remote control:
# devices being controlled by this remote:
header 9042 4488
one 593 1671
zero 593 537
repeat 9047 2221