-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1-Wire direct support #429
Comments
The move from Pi4J V1 to V2 specifically included the removal of device-specific implementations to reduce maintenance and minimize testing. That's why @taartspi created a lot of example implementations for specific devices in https://github.com/Pi4J/pi4j-example-devices. Can we have a similar approach for 1wire with only generic methods in Pi4J and device code in an example project? |
BTW thanks for the detailed info and research @dariuszzbyrad :-) |
I agree with @FDelporte thanks for the research! |
I also agree these individual devices should be added to the example project and not the pi4j project |
Thanks for answer! The next step is to make experiments with additional 1-Wire devices (I’ve ordered DS2438, DS2408, DS28E05, DS2431, DS9092 from 'my friends') to identify common communication patterns. I mean about reading from or writing to specific virtual files (single or multiple bytes) and other operations. Once the experimentation is complete, I'll propose an API for 1-Wire support. |
I’m back with a proposal for an API to support 1-Wire devices. Currently, it’s just the API itself, but implementation in the LinuxFS plugin and a mock version still need to be added. Changes: Available API: Example Usage: |
Following our discussion about adding direct support for 1-Wire in Pi4J, I made some research.
Devices Connected:
For experiments, I've connected two DS18B20 temperature sensors and one DS2413 GPIO device.
1. Using sysfs for DS18B20:
The DS18B20 works via sysfs, and you can read temperature data as follows:
or from the w1_slave file:
darek@raspberrypi:/sys/bus/w1/devices/28-06219443087e $ cat w1_slave 57 01 4b 46 7f ff 0c 10 38 : crc=38 YES 57 01 4b 46 7f ff 0c 10 38 t=21437
2. Using sysfs for DS2413:
The DS2413 GPIO device works similarly, but it uses a different mechanism for interacting with the output state. You can check its state as follows:
darek@raspberrypi:/sys/bus/w1/devices/3a-0000005eaee8 $ cat state | xxd -b 00000000: 01111000 x
And change state:
It requires
sudo
:As I described, each type of 1-Wire device would still require a separate implementation. This is because the w1-gpio driver does not provide a unified interface for all device types. This means we need to implement a class for each device we want to support. Additionally, since it is part of sysfs, it should be included in our LinuxFS provider. Lastly, the statement 'Doesn’t need sudo' on this page will no longer be valid.
3. Using OWFS (External Library):
While theoretically, the owfs library can be used for interacting with 1-Wire devices and controlling the GPIO pins (such as with JNI), it is not recommended due to well-known issues with races and other bugs:
"Despite the project name, the owfs package itself is NOT recommended for any real use, it has well known issues with races etc."
4. Using ioctl:
The w1-gpio driver in Linux does not support ioctl commands for direct interaction with 1-Wire devices. Instead, it uses sysfs for device interaction. ioctl is more commonly used with devices that expose a character device interface in /dev/, but 1-Wire devices are managed through sysfs entries, not ioctl.
Conclusion:
Question
@FDelporte, @eitch, @taartspi: Do we agree to introduce limited support for 1-Wire devices as part of the LinuxFS provider, starting with the DS18B20 and progressively adding support for other devices like the DS2413?
The text was updated successfully, but these errors were encountered: