Wednesday, 17 September 2014

Banana Pi: Temperature Sensor (DS18B20) - Tutorial


Requirements

    --> Banana Pi running Raspbian for Banana Pi
    --> Breadboard
    --> Jumper Wires
    --> DS18b20
    --> 4.7K Ohm resistor
    --> Breakout cobbler

       

      Hardware Setup

      Refer to the graphic for the correct wiring. Make sure the Banana Pi is switched off to prevent any possible damage.

      Banana Pi Temperature Sensor - DS18B20

      Software Setup

      Double check the wiring and boot the device. In order to be able to access the temperature data, we need to make some minor adjustments to the script.bin file, which is a binary configuration file used by Allwinner SOC.
      sudo apt-get install git
      git clone https://github.com/linux-sunxi/sunxi-tools
      cd sunxi-tools
      make
      
      #location of the script.bin file
      cd /boot/bananapi/
      
      #get the fex file
      sudo /home/bananapi/sunxi-tools/bin2fex script.bin bananapi.fex
      
      #edit the fex file
      sudo nano bananapi.fex
      
      #add the following at the end, save (CTRL + O) and close
      [w1_para]
      gpio = 4
      
      #.fex back to .bin
      sudo /home/bananapi/sunxi-tools/fex2bin bananapi.fex script.bin
      
      sudo reboot

      Reading raw data from the sensor

      After successfully rebooting your device, you will notice that /sys/bus/w1/devices is no longer empty.
      bananapi@lemaker ~ $ cd /sys/bus/w1/devices
      bananapi@lemaker /sys/bus/w1/devices $ ls
      28-000006203041  w1_bus_master1
      bananapi@lemaker /sys/bus/w1/devices $ cd 28-000006203041
      bananapi@lemaker /sys/bus/w1/devices/28-000006203041 $ ls
      driver  id  name  power  subsystem  uevent  w1_slave
      bananapi@lemaker /sys/bus/w1/devices/28-000006203041 $ cat w1_slave
      5e 01 4b 46 7f ff 02 10 8d : crc=8d YES
      5e 01 4b 46 7f ff 02 10 8d t=21875
      t=21875 is the number we are looking for. E.g.: 21.9 degree Celsius (°C) in my case.

      Banana Pi Temperature Sensor (DS18B20)
      my setup

      14 comments:

      1. This comment has been removed by the author.

        ReplyDelete
      2. Hi, nice tutorial! What distribution were you running?

        ReplyDelete
      3. Thnx you saved my life. I just got one sensor working with my banana pi after 24h of tring everything.

        ReplyDelete
      4. Hi, i have a bananapro with lubuntu. i made the software update above. The make instruction is ok but there is no root/bananapi directory and no script.bin. What is the reason.?

        ReplyDelete
      5. Same problem like Josef. Banana Pi running Bananian: /boot/ is empty

        ReplyDelete
        Replies
        1. try raspbian

          http://www.lemaker.org/resources/9-38/image_files.html

          Delete
        2. /boot is not empty, but /boot is not mounted. Try to enter:
          mount /dev/mmcblk0p1 /boot

          Delete
      6. sunxi-tools does not install jessie 15.08
        install fail

        ReplyDelete
      7. This comment has been removed by the author.

        ReplyDelete
      8. Hi
        I have problem with compilation.

        root@openmediavault:/sunxi-tools# make
        bash: make: command not found

        Any ideas how to make it?

        ReplyDelete
        Replies
        1. you need install:
          #apt-get install build-essential

          Delete
      9. Hi Mike, thanks for the tutorial!

        I found "script.bin" in "/boot" directly, there was no "/boot/bananapi". (running Raspbian GNU/Linux 7 (wheezy)) I copied the modified version of script.bin to both positions for good measure. (tried only overwriting the old file, without succes)
        After following the instructions, I only found "w1_bus_master1" in "/sys/bus/w1/devices".
        The temperature sensor worked without problem when I had it connected to an Arduino.
        I don't see any error message or other clue.
        Do you have an idea what more I could try?

        Thanks in advance!
        Roel

        ReplyDelete

      How to download a portion of Youtube Video with youtube-dl

      First make you have both youtube-dl and ffmpeg installed: sudo apt install youtube-dl ffmpeg Then download a portion of your desired...