Jump to content

nkahl

Members
  • Posts

    12
  • Joined

  • Last visited

Reputation Activity

  1. Like
    nkahl got a reaction from Echo in Enable 1-wire in kernel 4.9 on BananaPi   
    Hello all,
     
    of the occasion now comes a tutorial for how to set up a DS18B20 temperature sensor on a Banana Pi:
    Connect the sensor and a 4k7 pull-up resistor as shown in the attached circuit diagram. Make sure the Banana Pi is switched off to avoid any damage. Boot the BPi and log in as "root". Create a new directory in the root's home and copy the Banana Pi device tree (DTB) to it: mkdir dtb cp /boot/dtb/sun7i-a20-bananapi.dtb . cd dtb/ Change to the new directory with the cd command.
    Decompile the DTB:
    dtc -I dtb -O dts sun7i-a20-bananapi.dtb > sun7i-a20-bananapi.dts  
    Open the DTS file (which contains plaintext and is thereof human-readable), for example, with nano.
    Insert the following code block at the end of the file before the last line (containing };) - see attached screenshot if necessary:
    onewire@0 { compatible = "w1-gpio"; gpios = <&pio 7 20 0>; /* PH20 */ status = "okay"; };  
    Search for "pinctrl@01c20800" in the file and go to it.
    Put a "pio: " before "pinctrl@01c20800" (see screenshot).
    Save your changes and exit the DTS file.
    Run the following commands:
    mv sun7i-a20-bananapi.dtb sun7i-a20-bananapi.dtb.orig 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 This will move the original DTB file to "sun7i-a20-bananapi.dtb.orig" (in case you need it in the future), compile the DTS file to a new DTB and copy this into /boot. Then your Banana Pi is restarted.
    Afterwards, the temperature sensor will show up in /sys/bus/w1/devices with a random ID.
    The temperature can be read out via:
    cat /sys/bus/w1/devices/[DS18B20 ID]/w1_slave Replace [DS18B20 ID] with the ID you see in the directory, it is usually beginning with "28-". The command's output will contain something like
    t=20312 which is the temperature in Celsius (°C), here, it is ~ 20,3 °C.
    This tutorial assumes that the sensor is connected to the PH20 pin, if you use another, you will need to edit the code snippets above.
     
    Kudos to zador.blood.stained for all the help!
     
    Further readings:
    https://linux-sunxi.org/1-Wire https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/temperature/ http://www.linuxx.eu/2014/09/banana-pi-temperature-sensor-ds18b20.html Best regards,
    Norbert Kahl



×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines