Monday, June 15, 2015

JAVA DS18B20 sensor with Raspberry Pi

Hello there

This is a quick review of the lesson 18 of the "Sunfounder 37 modules Sensor Kit for Raspberry Pi Model B". This lesson is about 1-wire devices and in particular we will be reading values from the DS18B20 temperature sensor. The documentation of the kit is quite enough to get a basic introduction about what it is the 1-wire communication.

DS1B20 sensor
However in January 2015 the Raspbian operating system was updated and it is required to change some configuration to detect these type of devices. This post from the REUK.co.uk  has full details of the hole process from installation to device detection.

In summary to solve the issue about detecting the device, it is just required to add the line "dtoverlay=w1-gpio" at the end of the file "/boot/config.txt". With this simple modification and after rebooting the Pi. The device should be detected and listed under the command: "ls -l /sys/bus/w1/devices/". A new device link should appear with the name "28-00000xxxxxx".

Just follow the original documentation of the kit or the article from REUK.co.uk to do a quick verification test. If everything is fine we can now run the lesson's exercise "Ex16_Ds18b20.java" with the following command:

    sh runPi.sh "org.mandfer.sunfunpi4j.Ex16_Ds18b20 28-00000xxxxxx"

Just replace "28-00000xxxxxx" with your device file name. This should print the current temperature on the console output like in the video below. 


Reading values from the DS18B20


For full details about how to set up your Raspberry Pi and how to run these exercises please check out my old post Raspberri Pi with Pi4j and Junit testing mockups. Or leave me a comment if you have any issue or question.

This is all for now, 
Thanks for reading and please post a comment if you have any issue or questions. 
Keep on hacking,


Posted by Marc Andreu.

No comments: