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:
cp /boot/dtb/sun7i-a20-bananapi.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:
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
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
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!
If you can switch to newest image because you simply added tons of applications, and tweaked tons of configs, what you can do is still download newest image, plug into a SDCard reader over one of the USB, then move the old /boot into /boot-OLD and copy the one from the new image from /mnt/boot into /boot. Probably, you will also need to install newest u-boot by doing :
dd if=/usr/lib/linux-u-boot-dev-orangepipc_5.27_armhf/u-boot-sunxi-with-spl.bin of=/dev/mmcblk0 bs=1024 seek=8
The, reboot and see newest kernel, but still able to use you old applications
There is also overlays provide in recent Mainline builds for A20, such /boot/dtb/overlay/sun7i-a20-w1-gpio.dtbo.
To enable it, simple edit /boot/armbianEnv.txt and add this :
And then reboot.
(Note : to use such overlays, your need a recent image, not upgrades from old image)
Here is how to shrink an existing image.
In "gparted", do "edit/resize" of the partition, but leave a certain percentage of free space, then "Apply".
Replace the "endsect" by the actual number shown by fdisk.
sudo modprobe loop
sudo losetup -f
sudo losetup /dev/loop0 myimage.img
sudo partprobe /dev/loop0
sudo gparted /dev/loop0
sudo losetup -d /dev/loop0
fdisk -l myimage.img
truncate --size=$[(endsect+1)*512] myimage.img