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
lirc_dev
lirc_rpi gpio_in_pin=18
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 :
# /etc/lirc/hardware.conf
#
# Arguments which will be used when launching lircd
LIRCD_ARGS="--uinput"
#Don't start lircmd even if there seems to be a good config file
#START_LIRCMD=false
#Don't start irexec, even if a good config file seems to exist.
#START_IREXEC=false
#Try to load appropriate kernel modules
LOAD_MODULES=true
# Run "lircd --driver=help" for a list of supported drivers.
DRIVER="default"
# usually /dev/lirc0 is the correct setting for systems using udev
DEVICE="/dev/lirc0"
MODULES="lirc_rpi"
# Default configuration files for your hardware if any
LIRCD_CONF=""
LIRCMD_CONF=""
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 :
dtoverlay=lirc-rpi,gpio_in_pin=18
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
space 16777215
pulse 9083
space 4459
pulse 615
space 520
pulse 645
space 493
pulse 613
space 525
pulse 610
space 510
pulse 621
space 539
pulse 628
space 486
pulse 637
space 510
pulse 626
space 494
pulse 635
space 1641
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 <lirc@bartelmus.de>
#
# 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:
#
begin remote
name /home/pi/lircd.conf.conf
bits 16
flags SPACE_ENC|CONST_LENGTH
eps 30
aeps 100
header 9042 4488
one 593 1671
zero 593 537
ptrail 603
repeat 9047 2221
pre_data_bits 16
pre_data 0xFD
gap 108029
toggle_bit_mask 0x0
begin codes
KEY_0 0x30CF
KEY_1 0x08F7
KEY_2 0x8877
KEY_3 0x48B7
KEY_4 0x28D7
KEY_5 0xA857
KEY_6 0x6897
KEY_7 0x18E7
KEY_8 0x9867
KEY_9 0x58A7
KEY_UP 0x50AF
KEY_DOWN 0x10EF
KEY_VOLUMEUP 0x807F
KEY_VOLUMEDOWN 0x906F
KEY_FORWARD 0x609F
KEY_BACK 0x20DF
KEY_PAUSE 0xA05F
KEY_PLAY 0xA05F
KEY_CLOSE 0x00FF
end codes
end remote
Howdy are using WordPress for your site platform? I’m new to the blog world but
I’m trying to get started and create my own. Do you
require any coding expertise to make your own blog? Any help would
be greatly appreciated!
Hey hello,
I bought a Theme. I didn’t even think about making my own. There are also lots of free templates.