DS18B20 temperature sensor with Banana Pi M1 (Armbian 5.25 4.9.7)

A guide how to connect and read the temperature from DS18b20 temperature sensor to Banana Pi.

Prepare:

  1. Banana Pi M1 installed with Armbian 5.25 v4.9.7.
  2. uname -a # Linux bananapi 4.9.7-sunxi #1 SMP Thu Feb 2 01:52:06 CET 2017 armv7l GNU/Linux.
  3. Check in directory /boot/ if it has dir /dtb/ or not, if yes then continue, if not then use other way.

Hardware:

Connect the DS18b20 with the Banana Pi as following:

If you have 1 sensor, just connect one, if you have more, the same applied.

Setup

(all the command here is running under root account, if you logged in with other account, please use sudo or similar way to run these commands)

Go to your home folder and make a new dir named “dtb”:

cd ~
mkdir dtb
cd dtb

Copy the .dtb file from /boot/dtb to ~/dtb folder:

cp /boot/dtb/sun7i-a20-bananapi.dtb . # Remember the last dot.

Backup the original .dtb file then decompile the .dtb file:

mv sun7i-a20-bananapi.dtb sun7i-a20-bananapi.dtb.orig
dtc -I dtb -O dts sun7i-a20-bananapi.dtb > sun7i-a20-bananapi.dts

Edit the sun7i-a20-bananapi.dts file:

nano sun7i-a20-bananapi.dts

Find this line: [email protected], and add pio: before it like this:

pio: [email protected] {

Then go to end of file, before the last }; add this:

[email protected] {
 compatible = "w1-gpio";
 gpios = <&pio 7 20 0>; /* PH20 */
 status = "okay";
};
# Note: PH20 is pin 16.

Hint 1: Why <&pio 7 20 0>; is PH20? The answer is the first number comes from H character (A-0 B-1 C-2 D-3 E-4 F-5 G-6 H-7 and so on…). 20 is from the number after PH.

Hint 2: Why do PH20 is physically pin 16 on the board? Please refer to this image:

Save the file with Ctrl+X -> Y -> Enter.
Compile .dts file back to .dtb, then copy .dtb back to /boot/dtb folder:

dtc -I dts -O dtb sun7i-a20-bananapi.dts > sun7i-a20-bananapi.dtb
cp sun7i-a20-bananapi.dtb /boot/dtb/sun7i-a20-bananapi.dtb
sync
shutdown -r now

After reboot, the Banana Pi should detect the DS18B20 sensor. Check and get the result:

ls /sys/bus/w1/devices
# Result
# ls /sys/bus/w1/devices
# 28-xxxxxxxxxxxx w1_bus_master1
# 28-xxxxxxxxxxxx is the ID of the sensor.
cat /sys/bus/w1/devices/28-xxxxxxxxxxxx/w1_slave
# Result:
# 70 01 4b x6 7f xx 0c 10 40 : crc=40 YES
# 70 01 4b x6 7f xx 0c 10 40 t=23000

Which means the DS18B20 temperature sensor read 23.000°C.

ooOoo

Disclaimer: The information in this page is collected and learned from my experience. If any info is wrong, please kindly let me know in the comment.

3 thoughts on “DS18B20 temperature sensor with Banana Pi M1 (Armbian 5.25 4.9.7)”

  1. That sounds pretty easy, however I really don`t know how You get this working in reality. I tried many things throughout the DeviceTrees and I don`t get the DS1820 working on the bananapi M1 with armbian. Compiling the sun7i-a20-bananpi.dts I get the warning:
    Warning (unit_address_vs_reg): Node /[email protected] has a unit name, but no reg property

    In sys/bus/w1/devices I only see the entries: 00-400000000000 00-800000000000 00-c00000000000 w1_bus_master1

    Not any results.

  2. Anyhow Your article helped.

    I also decompiled “sun7i-a20-w1-gpio.dtbo” in “/boot/dtb/overlay/” and modified Pin to “PH20”.
    Also didnt work after comipiling an restart the system.

    Then I changed the w1-Pin in both decompiled files to “PI3”. I compiled both files and restarted the system.

    I don’t know why but its running.

    I used PI3 before in wiring-pi environment.

    My kernel is:
    uname -a
    Linux bananapi 4.14.4-sunxi #1 SMP Thu Dec 7 07:12:38 CET 2017 armv7l GNU/Linux

    Hardware is Bananapi M1

    Thanks

    1. Yeah so glad that you managed to get it working. I haven’t tried it with 4.14.4 as yours, so maybe something has changed by the time. However, are you connecting the DS18b20 to Pin 16 when you first try it with “PH20”? Also may I ask you what did you put in here:

      gpios = < &pio 7 20 0>; /* */

      with the “PI3”?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.