0

I'm new to the Raspberry Pi ecosystem so pardon me if I'm talking nonsense. I want to read the temperature data from the connected DS18B20 sensors using C/C++. I followed this schema to connect them: enter image description here There are a lot of examples how to do it in different languages including C/C++ like:

But most of them seem to use a legacy way of doing things according to linux kernel docs. Official Raspberry Pi documentation says that Programming with GPIO can be done using standard kernel interface via libgpiod. But I have a hard time to find any useful tutorials about how to do that.

So my question is how to read the DS18B20 temperature sensors in a non-legacy (modern) way ? Can someone point me in the right direction ?

2
  • 1
    the page you linked has example code
    – jsotola
    Feb 8, 2021 at 22:15
  • The two pages you linked to has the right way to do it, let the kernel driver take care of it and just read the details from the files in /sys/bus/w1/devices/28-*/
    – onion
    Feb 9, 2021 at 6:49

1 Answer 1

1

I believe the methods presented in those examples are still relevant.

libgpiod is the replacement for the sysfs method of directly talking to the GPIO as a Linux user. I.e. it replaces user functions to read and write individual GPIO and to be told about individual GPIO level changes.

It is not a replacement for all the kernel modules which currently talk to various buses over the GPIO.

E.g. talking on the I2C bus still uses the same kernel driver, talking on the SPI bus still uses the same kernel driver, and talking on the 1-wire bus still uses the same kernel driver.

In your case the DS18B20 uses the 1-wire bus and the deprecation of the sysfs interface to the GPIO is irrelevant.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.