skappler
Posts: 9
Joined: Fri Jan 18, 2013 11:13 am

DS18B20 Temperature sensor and Java

Thu Feb 07, 2013 6:54 pm

Hey
I'm trying to measure the temperature with a DS18B20 sensor. I found several tutorials and blog entries on how to setup the hardware and read the temperature over the shell, but I have no idea how to do it with Java. I googled for a while but didn't find anything.

I already installed the pi4j library. Is there a way to use the console output/ the way the console way works or do I have to implement the communication with the GPIO all by myself?

I hope you guys could help me!

User avatar
savageautomate
Posts: 225
Joined: Thu Aug 16, 2012 3:20 pm
Location: USA
Contact: Website

Re: DS18B20 Temperature sensor and Java

Sat Feb 09, 2013 6:42 pm

Hi skappler,

The Pi4J library does not provide any console interactivity, its just a programming library to communicate with GPIO, RS232, SPI, and I2C on the hardware.

According to this article (http://webshed.org/wiki/RaspberryPI_DS1820) the DS18B20 sensor requires a 1-wire interface. There is not a dedicated 1 wire interface on the Pi and thus Pi4J does not provide any 1-wire support. The article mentions a bit banging Linux driver that uses a single GPIO pin to communicate with the 1-wire device. This driver would make it possible for Pi4J to support the GPIO/1wire approach, but its not currently implemented.

I added a feature request to the Pi4J project to add support for this in a future build.
https://github.com/Pi4J/pi4j/issues/32

Thanks, Robert
Robert Savage | Follow me @savageautomate
http://www.pi4j.com | http://www.pislices.com
http://www.savagehomeautomation.com

skappler
Posts: 9
Joined: Fri Jan 18, 2013 11:13 am

Re: DS18B20 Temperature sensor and Java

Sun Feb 10, 2013 4:19 pm

So it's not a good idea to do this with Java at the moment :P Except I want to write the driver myself.
Thank you for adding the feature request :)

User avatar
savageautomate
Posts: 225
Joined: Thu Aug 16, 2012 3:20 pm
Location: USA
Contact: Website

Re: DS18B20 Temperature sensor and Java

Sun Feb 10, 2013 7:45 pm

You want to write the Linux driver for the device?
Robert Savage | Follow me @savageautomate
http://www.pi4j.com | http://www.pislices.com
http://www.savagehomeautomation.com

skappler
Posts: 9
Joined: Fri Jan 18, 2013 11:13 am

Re: DS18B20 Temperature sensor and Java

Sun Feb 10, 2013 8:23 pm

I want to write an equivalent in Java. This should be possible, right?

User avatar
savageautomate
Posts: 225
Joined: Thu Aug 16, 2012 3:20 pm
Location: USA
Contact: Website

Re: DS18B20 Temperature sensor and Java

Tue Feb 12, 2013 1:00 am

I'm not sure. I have never attempted to write something like this in Java. I think the timing would concern me, but perhaps some others will comment here with any experience they may have had.
Robert Savage | Follow me @savageautomate
http://www.pi4j.com | http://www.pislices.com
http://www.savagehomeautomation.com

manolis
Posts: 1
Joined: Tue Feb 12, 2013 8:36 am

Re: DS18B20 Temperature sensor and Java

Tue Feb 12, 2013 8:52 am

skappler wrote:I want to write an equivalent in Java. This should be possible, right?
Follow the instructions at http://www.cl.cam.ac.uk/freshers/raspbe ... mperature/ to enable 1-wire and then use a simple FileReader to get the value from the file:
/sys/bus/w1/devices/<device-id>/w1-slave
You have just to replace <device-id> with the correct deviceId

Natch
Posts: 1
Joined: Fri May 03, 2013 2:04 am

Re: DS18B20 Temperature sensor and Java

Fri May 03, 2013 2:20 am

I found several tutorials and blog entries on how to setup the hardware and read the temperature over the shell, but I have no idea how to do it with Java.
Have a look at the 1-Wire API and ReadTemp example at http://www.maximintegrated.com/products ... re_api.cfm

I didn't try it myself so I'm not sure if that's what you are after. Please report back if it works for you as I'm interested in this topic as well.

bullen
Posts: 283
Joined: Sun Apr 28, 2013 2:52 pm

Re: DS18B20 Temperature sensor and Java

Sat May 04, 2013 10:37 am

Why can't you just do:

Runtime.getRuntime().exec("/opt/vc/bin/vcgencmd measure_temp");
https://github.com/tinspin/rupy - A tiny Java async HTTP application server.

Return to “Java”