Temperature ( DS18B20) and Orange Pi Zero


Temperature measurement is possible with many sensors. Here we will use the DS18B20 sensor which is available in a waterproof version to measure for example the temperature of the water in a swimming pool.


Connect as shown in the diagram the DS18B20

DS18B20 and Orange Pi Zero
  • black = ground
  • yellow = data on pin PA14
  • red = 3.3v
  • A 4.7kohm resistor between the 3.3v and the yellow data wire

One Wire bus activation

The DS18B20 provides temperature measurements on a “1-wire” serial bus. You have to configure the armbian system by running ‘armbian-config’, the equivalent of ‘raspiconfig’ on Raspberry.

$ armbian-config

Go to the “system” section and select “Hardware” then activate w1-gpio.

You must add the corresponding “overlay” in /boot/armbianEnv.txt:

The pin used is also specified. Here PA14 on an Orange pi-Zero. The 1wire bus requires a + pull-up resistor. We can add uses that of the orange-pi which is much higher than the 4.7kOhm.

To manage the dialogues on the 1-wire bus, it is essential to have control over the execution time of the processor. To do this, you need to be able to temporarily “freeze” the OS’s ability to preempt by adding modules to the Linux kernel.

We define these modules in the configuration file

We can also add them by command

modprobe w1-therm
modprobe w1-gpio


After a reboot of the system, you can check the presence of the probe by:

ls /sys/bus/w1/devices

The answer should look like the one below with a code 28 in mind which corresponds to a temperature sensor.

Check that the modules loaded in memory are correctly taken into account


w1_therm et w1_gpio should be listed.

We can check that the gpio pin is correctly taken into account by

cat /sys/kernel/debug/gpio
gpio-14 ( |onewire@0           ) out hi
gpio-17 ( |orangepi:red:status ) out lo


The measurements are in folder 28 … located:


Read the w1-slave file, it contains 2 lines. There is the result in hexadecimal and the CRC check to validate the result.

98 01 55 05 7f a5 81 66 64 : crc=64 YES
98 01 55 05 7f a5 81 66 64 t=25500

At the end of the second line the temperature t = …. to be divided by 1000 gives the temperature of ° Celsius.

The measurements are performed periodically by the linux kernel. The w1_master_timeout file gives 10s base. This value adapts depending on the number of sensors on the line and the quality of the responses. A script written for example in python will read the w1-slave file and display the measurements or send them to a web client. A file named temperature in the same folder gives the last known value.

F1ATB André

Ham Radio - Home automation - Photovoltaic

You may also like...

2 Responses

  1. Tom Eastem says:

    Hi André,
    I have re-created basic blink (LED blink) script on OrangePi Oneplus using your script.
    Do you know how to read temperature/humidity from DHT11 /22 on Oneplus?
    Thanks, Tom

    • F1ATB André says:

      DHT22 uses a proprietary standard to transmit the data in serial. It takes around 4ms to transmit the 40 bits of the results (16 bits for humidity, 16 bits for temperature, 8 bits for a check sum). A 0 bit corresponds to a 0 level during 50us then a 1 during 27us. A 1 bit corresponds to a 0 level during 50us then a 1 during 70us. To decode this 40 bits frame, you need to sample the GPIO pin at around 20us. If you use a library as pyA20 written in C, it works as it is described on this site for the Orange Pi Zero. For the Orange PI One Plus, the OPI.GPIO library in Python uses the sysfs file system to access the GPIO. You can sample an input at 120us. I wrote some lines of code using also sysfs and was able to sample at 100us. I didn’t find on the web a library equivalent to pyA20 written in C more rapid to access the inputs. It has to be written…
      An alternative is to use other sensors using I2C bus or 1 wire bus which are implemented by the Operating system.