Home » Java » Archive by category "Pi4J" (Page 2)

IR Receiver versus DC motor

Some more about my issue. I tried an alternative calling irw direcly in my java code

p = Runtime.getRuntime().exec("irw");

And the result was exactly the same. Once the motor starts turning, the IR receiver seems hanging. When the motor stops, the IR receiver works again. Some reading and searching on the internet learned me that a possible cause could be electric noise because of the running DC motor. I tried to put a capacitor around the DC motor but without result. In other words I am stuck for the moment and thus still looking for a solution. If any of you would have any suggestions, they would be very welcome. I have no electronic background what probably explains my lack of knowledge on that.
In the meanwhile I also posted my issue on a Raspberry Pi forum. See Forum post

I will keep you posted as soon as I get around this issue.


Continue reading »

Look for JLIRC Alternative

My first experiments with JLirc were promising but at some point I started getting issues. The idea was simple. Compile the code and put in in the classpath. That was working well but in the context of my Rasbperry Controlled Car I got weird issues. The JLirc library has a native implementation to read the infrared signals. The library has a nativeRead method to read data from the socket : /dev/lircd.
Without batteries attached to the car this is working well without any issues but with batteries inside, it hangs after the first button I click on the remote control. Weird, very weird. I have spend a lot of time trying to figure out what is the issue but I cannot find it. As I said, without batteries in the battery holder, it works, with batteries, it hangs. I can’t see nor understand the link with why it would hang.
In my search I have noticed that the JLirc library dates from 2001. And that is a little surprising. I don’t say the issue could be related to that but I prefer to have code that is more recent. I have learned out of experience at work that sometimes code running under an older JVM does not work fluently anymore under more recent versions.
I will have a look if I can read the socket via another way. When I have time I will also try to further figure out what is wrong.

Continue reading »


After having lirc working on the Raspberry Pi, I wanted a Java program that can talk with lirc and make it possible to intercept infrared signals from a remote control via java code.  That is were JLirc comes in.  JLirc is a java api for using lirc.  More information about can be found on JLirc

The installation instructions can be found on an install file which you can find in the sources zip.  You have to download the sources to your raspberry pi and extract the zip.  Than you need to do a build (Makefile).  Important note is that you have to use the option  -march=armv7-a instead of what was original in the Makefile.  It will not build if you don’t change it.Once built you have to first launch the lirc deamon :

sudo service lirc start

and than launch the test application which is in the sources :

java -cp . org.lirc.test.Irw

As a result when you hit a button on the remote control you should see something similar like this :

pi@raspberrypi ~/lirctest/build $ java -cp . org.lirc.test.Irw
0000000000fda857 00 KEY_5 /home/pi/lircd.conf.conf

Pretty simple isn’t it.

Continue reading »

LIRC on Raspberry Pi

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_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

#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
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
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
end codes

end remote

Continue reading »