Temperature from DS18B20

I didn’t have any problems with this temperature sensor on Raspberry, but on Rock there is problem getting it to work. Mostly the sensor is not visible even after loading the kernel modules.

I have Python3 and connected the sensor, then gone through commands:

apt install python-pip
pip install w1thermsensor

Then I’ve rebooted the board, modprobe’d two modules but nothing seems to be in folder /sys/bus/w1/devices/.

How can I enable 1-Wire interface?


Just tried that and it failed. No device in devices.

I’ve changed first all “serial@”, then only “i2c@”. None helped.

Seems like another issue for the developers.

I didn’t test but if Martin said its working for him, this feature (reading sensor via w1) works. https://forum.armbian.com/topic/8719-rock-pi-4/?do=findComment&comment=73968

But you will need to use Armbian with a modern kernel https://www.armbian.com/rock-pi-4/ which is WIP. I do agree this enabling is not as simple as on other boards (Allwiner for exmple) where w1, uart, … is enabled via menu driven armbian-config utility. When you are done that, you can start thinking about upper level/python.


ROCK Pi 4 supports 1-wire communication for devices such DS18B20, whose data pin connects to GPIO4_D6 pin on ROCK Pi 4 board.

You need to install the latest rockpi4-dtbo packages.

More details:https://wiki.radxa.com/Rockpi4/hardware/devtree_overlays.

1 Like

Thanks! It worked!

The sensor appeared as a bus folder.

However it changes its id (there are even few folders) and I can’t read the temperature.
There is not temperature file anywhere…
Not sure if it is correctly connected, but it is connected as for Rasp Pi.
Should I change the connection pins or add argument to the /boot/hw_intfc.conf file?
intfc:dtoverlay=w1-gpio4-30 is already in the file.

Can you please share how the wires should be connected to the GPIO?

My sensor’s w1_slave file is visible but does hang up the shell when trying to open it with mc viewer (cat also does not work).
Python script returns that the sensor is not ready.

I am getting errors:

Traceback (most recent call last):
  File "./temp2.py", line 5, in <module>
    print("Sensor %s has temperature %.2f" % (sensor.id, sensor.get_temperature()))
  File "/usr/local/lib/python2.7/dist-packages/w1thermsensor/core.py", line 255, in get_temperature
    return factor(self.raw_sensor_value)
  File "/usr/local/lib/python2.7/dist-packages/w1thermsensor/core.py", line 210, in raw_sensor_value
    raise SensorNotReadyError(self)
w1thermsensor.errors.SensorNotReadyError: Sensor 01186bce26ff is not yet ready to read temperature

left to GND #39
middle to GPIO4_D6 #37 (4.7kOhm resistor is connecting middle to right)
right to +3.3V #1


Hareware connection:

DS18B20 --- ROCK Pi 4

Pin DQ  --- Pin37 (4.7kOhm resistor is connecting to Pin VCC)
Pin GND --- Pin39
Pin VCC --- Pin1

According to the DS18B20 datasheet, Pin VCC could be connected to +3.3V or +5.0V.

Every device has its own device id. When /sys/bus/w1/devices/28-00000xxxxxxxx is shown, it means that id devices is detected.

Use cat w1_slave to get the temperature value.

Everything seems to be connected properly.
It does not work. I am getting after a long while:

[0][18:51][root@rock][/sys/bus/w1/devices/28-01186bce26ff] $ cat w1_slave
ff ff ff ff ff ff ff ff ff : crc=c9 NO
00 00 00 00 00 00 00 00 00 t=-62

The device series number, 28-01186bce26ff, is strange. Can you double check it on Raspberry Pi?

What doubt you have about this serial number?

I no longer have Raspberry Pi. When last checked everything was all right.

Are you sure that sensor is not damaged?

Yes, it is all ok, it was moved immediately from Rasp to Rock. Even when I didn’t sold the Rasp yet.

Do you need any logs or anything to guide me further?

I’ve double checked the connections and everything seems to be ok - should be this way, as the sensor is visible in /sys/bus/…

Here is my hardware connect picture.

Yes, if you could, show my the result of sudo dmesg and tree /sys/bus/w1 in https://paste.ubuntu.com/

Here you have: https://paste.ubuntu.com/p/CTHGqZDwWD/

I have connected the sensor like on this page:

So beside sensor there is only resistor.

Hi, I have tested a new DS18B20 sensor(TO-92), which works on ROCK Pi 4 board.

Kernel: 4.4.154-96-rockchip-gb08aaba46e04
rockpi4-dtbo: 4.1

root@linaro-alip:/sys/bus/w1/devices/28-00000bbce8b4# cat w1_slave 
b3 01 4b 46 7f ff 0d 10 9a : crc=9a YES
b3 01 4b 46 7f ff 0d 10 9a t=27187