Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Add 1-wire support using GPIO pin #32

Closed
savageautomate opened this issue Feb 9, 2013 · 16 comments
Closed

Add 1-wire support using GPIO pin #32

savageautomate opened this issue Feb 9, 2013 · 16 comments

Comments

@savageautomate
Copy link
Member

Feature request to add support in Pi4J for the GPIO bit-banging 1-wire Linux kernel driver:

pi@raspberrypi:$ sudo modprobe wire
pi@raspberrypi:
$ sudo modprobe w1-gpio
pi@raspberrypi:~$ sudo modprobe w1-therm

See this article for details: http://webshed.org/wiki/RaspberryPI_DS1820

schup added a commit to schup/pi4j that referenced this issue May 26, 2015
@marcandreuf
Copy link

I implemented an example in JAVA using the modprobe driver and reading from the file. Just like the article. At least I could read temperature values in a Raspberry pi :-)

https://github.com/marcandreuf/sunfounder-sensors-raspi-4j/blob/master/src/main/java/org/mandfer/sunfunpi4j/Ex16_Ds18b20.java

I hope it helps.

@ademcaliskan
Copy link

I would suggest an static function for listing all available wired devices as an Array or List.

Adem

@DataWorm
Copy link

Schups code looks fine, but it is a few months old. Until now there has been no reaction on his merge request... Is there a chance, that it will get merged soon or got this issue postponed for a specific reason?

@natdan
Copy link
Contributor

natdan commented Sep 12, 2015

I've only got active now (someone was of impression that he's following this project while he wasn't). I'll go through the code over weekend and do the necessary. Sorry for the delay...

@savageautomate
Copy link
Member Author

BTW, it will get merged into the 'develop' branch which means that it will be available in the 1.1-SNAPSHOT builds.

@DataWorm
Copy link

Seems to take some more weekends? ;-)
Could we help in some way? Is there something that needs to be improved (apart from some javadoc comments) before it could be merged?

@natdan
Copy link
Contributor

natdan commented Sep 22, 2015

All help appreciated. Do you know how to lay laminate? Or at least remove existing tiles from kitchen floor? I think I got confused by Robert's message thinking he has already done it. Will start looking into it tonight. Sorry about it.

@DataWorm
Copy link

I think I could learn it on-the-fly. But free support for such tasks is limited to Berlin! ;-)

@natdan
Copy link
Contributor

natdan commented Sep 22, 2015

OK. I've skimmed through Schups's code and I am not 100% sure what to do. Code itself is fine and I'll pull b76d065 and f16c54c - it will, at least buy us some time. Only thing is that it, probably, will be just WIP or initial (working) starting point for One Wire interface.
My only problem is that it doesn't (at this moment) capture 'idea' of 1-wire interface and in this format I cannot see it being implemented with simple bit banging through GPIO. TmpDS18B20 class, for instance, must be tied to a file (direct, one of, implementations of 1-wire protocol through kernel driver). I would be more interested seeing something closer to the low level driver which, then can be implemented through /sys file system (as here) or bit banging or ... whatever is there. Implementation for test it third one I can envisage here. Still good place to start all with! Thanks Schups :)
BTW 9f59171 doesn't go under 1-wire protocol. Maybe it should be pulled after reviewed by Robert...

@schup
Copy link
Contributor

schup commented Sep 23, 2015

I agree - native implemenation of the 1-wire protocol would be nice.
Unfortunately I don't know the interals of the 1-wire protocol.

I've sumitted the merge request to get some feedback on the implementation and if the general approach would be good enough for now.
It is WIP :-)
The code is not really documented and well tested. Since the DS18B20 sensor is the only 1-wire device I have ever used there may be some specifics that wouldn't work well with other devices.

9f59171 - I merged the development branch back in to make sure it isn't breaking anything.
I would suggest to not merge the feature branch until has stabilized a bit more :-)

Cheers,
Peter

@natdan
Copy link
Contributor

natdan commented Sep 23, 2015

I've made implementation of one wire protocol some 20 years ago for 8031 (8051) µControllers and there are some resources on the internet (oh, what a understatement), so I don't mind looking more into it when time allows... And I hope it is going to be soon as I would like to use RPi + 2x1820 (or newer equivalent) soon as replacement for my hot water/heating controller.
Anyway - you've tested your code with real device and it works - that's really good start! :)
Will merge it as soon as return from the business trip.

@DataWorm
Copy link

Of course a bit-banging implementation might be nice but kernel support on the other side might be more efficient?!
The DHT11 or DHT22 sensors for example (which would be my next feature requests) uses a single dataline but with another manchester-like protocol. I saw multiple implementations for it without kernel support. The python implementations have a lot of read fails due to the timing. C implementations perform much better but still can have read fails. W1 might have the same issue?! Therefore a kernel support would be a better working solution, wouldn't it?!

@natdan
Copy link
Contributor

natdan commented Sep 24, 2015

There's nothing wrong relying on kernel support and I see implementation of one wire protocol that users that particular kernel module as a primary implementation. But API (java interfaces) shouldn't really be kernel module specific (i.e. talking about exposed files) but to expose higher (lower?!) level functions one wire protocol itself defines. They will nicely translate to kernel module implementation, but at the same time allow other implementations and ability to move to other platforms(), too.
DHT11/22 protocol API should be specification agnostic, too. Maybe we can start with C implementation (and JNI bridge to it) and see if anyone comes up with a kernel module, too. That would allow us to move from one implementation (which might not be ideal) to better one later without breaking compatibility of systems using it.
(
) Server API defined pi4j works perfectly on Lejos and Haiku - not as a fully fledged pi4j port but more like cut down hacked version... Still code that works on pi4j (and uses Server API) works perfectly without any changes on those platforms because API is implementation agnostic...

@natdan
Copy link
Contributor

natdan commented Sep 26, 2015

Done. Again, apologies for not have done it sooner. Your code is now in develop branch. See pull request comments for failing tests..

schup added a commit to schup/pi4j that referenced this issue Sep 26, 2015
savageautomate added a commit that referenced this issue Sep 26, 2015
#32 fix unit test errors in TmpDS18B20Test
@savageautomate
Copy link
Member Author

Unit test code merged. This W1 impl is now available in the latest 1.1-SNAPSHOT build. Thanks!

@giampiero7
Copy link

Hi @savageautomate,
I'd just like to point out that WiringPi includes the driver for the MaxDetect series 1-wire sensors:

https://github.com/WiringPi/WiringPi/blob/master/devLib/maxdetect.c

It might be nice including it in Pi4J too :)
I'll let you decide if it is worth having it as an enhancement...

Cheers,
Giampiero

mheath pushed a commit to mheath/pi4j that referenced this issue Feb 16, 2021
FIX: Issue Pi4J#15; Prevent the PiGPIO library from internally handling s…
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants