недеља, 2. јул 2017.

Home weather net

There is a followup of this post.
When I purchased Raspberry Pi starter kit couple of years ago, I got the DS18B20 sensor with it. It is a simple device, three pins only, uses one-wire protocol to send the measured temperature to the host computer. There are plenty of tutorials how to use it with the Raspberry Pi. 

I have connected that one sensor to the PI and was able to read the temperature.

Then I have purchased more DS18B20 sensors and placed one outside, in the shadow.


Then I have purchased DHT11 combined sensor for both temperature and humidity.

DHT11 sensor has a nice support for Python in this library.

Now I have four sensors, two for the inside temperature, one for the outside temperature, and one for the inside humidity. The next step was to make some web site for temperature reading. I have created a small web server which gathers data from all four sensors and displays it in two ways: gauges and charts:
This is nice, but I wanted an instant readout of the temperature, without a need for grabbing the nearest mobile phone, tablet, or computer and navigating to the web server. Then I remembered that I have two old Samsung Android phones: Samsung Galaxy Ace and Samsung Galaxy S+. Both have old Andorid OS, v2.3.6. Both have so small amount of RAM, that they are useless now (especially the Galaxy Ace). So, I have uninstalled everything and installed my own custom application, so those phones now have a new purpose:



Whenever I look at them, they display the time, date, and the temperature inside and outside. The data is displayed each second, moved to the right by one pixel, and then at the end of the line, moved by one pixel below, so the pixels are not burned.

Android phone runs without battery

Now I had two questions: will the display live, since I have turned off the screen saver, and what about the battery - can I run the mobile phone without a battery?

Well, the first question can be answered only by the experiment, and both phones now work for approximately half a year, and they still work.

The second question is more interesting: if I remove the battery, the phone will not work. Android is designed to work with the battery, and it needs software patches at very low level to turn off the protection which requires the battery to be present.

Now, there are plenty of tutorials how to make your Android phone work without a battery. Those tutorials work for older devices like these I have. It all comes to one thing: pretend that you do have a battery. How to do that? Here is what I have done.

First of all, the procedure differes for various phones. Even my two phones have different procedure. For the Galaxy Ace, it was the simple one. There are three pins inside the phone to which battery contacts connect when you insert the battery.

You can connect 5V (from the charger) to the plus pin, ground to the minus pin, and, for the Galaxy Ace, I simply shorted the 'B' pin to the minus pin. The battery voltage is 3.7V, but the phone works with 5V, too.


The picture above is the Galaxy Ace. No voltage regulators, and no resistors.

With the Galaxy S+, it was a different story. First of all, 5V and ground from the charger can be connected to the plus and minus pins, but the phone does not work reliably. I needed to step down the voltage. I have purchased a buck step down regulator, and lowered the voltage to 3.9V. Then I have tried various resistors between minus pin and 'B' pin, to find out that 10K Ohm resistor works nice. So, my final configuration includes voltage regulator to step down the voltage, and 10K resistor between 'B' and minus pins:


The picture above is the voltage regulator and the Galaxy S+. The resistor cannot be seen here, since it is placed inside the phone.

субота, 1. јул 2017.

Odroid XU4 boot from hard disk

I have Odroid XU4 computer. It is a nice piece of machine. It has 8 cores, Gigabit Ethernet, USB3.0. It can boot from uSD card, or eMMC module. However, I have experienced frequent uSD card crashes, so severe, that the Odroid wouldn't boot afterwards. It would happen when Odroid does some intensive write to the file system. It would simply mess up the file system beyond repair.

That is why I have decided to find instructions how to boot this device from a hard disk.

First of all, you cannot make your Odroid XU4 completely boot from the hard disk. It will start the boot process from the uSD card, and then it will mount the root file system on the hard disk, instead on the uSD card.

There is a nice post on the official Odroid forum. It says that you need to write the image on your uSD card and then boot the Odroid. When it boots successfully, you can then connect the external USB hard disk. Then you need to format that external hard disk to ext4 file system:

mkfs.ext4 /dev/sda1

Now you need to copy the content of the uSD root partition to the external hard disk:

mkdir /tmp/sda1
mount /dev/sda1 /tmp/sda1
rsync -avx / /tmp/sda1
umount /dev/sda1

After that, type blkid to see UUIDs of all disks connected to your Odroid. The output would be like this:

/dev/sda1: UUID="86135-2ba3-45cf-bda0-317b" TYPE="ext4" PARTUUID="ab57-01"
/dev/mmcblk0: PTUUID="3ceda53" PTTYPE="dos"
/dev/mmcblk0p1: SEC_TYPE="msdos" LABEL="boot" UUID="5A5A-6868" TYPE="vfat" PARTUUID="3cd53-01"
/dev/mmcblk0p2: LABEL="rootfs" UUID="e139-fe3-99859" TYPE="ext4" PARTUUID="3cd53-02"

Hard disk is /dev/sda1. You need to remember its UUID, since you need to put it in two places: /media/boot/boot.ini file, and /etc/fstab file (before unmounting the temporary mount, it was: /tmp/sda1/etc/fstab).

Make copies of both files, then edit the /media/boot/boot.ini file first. Find the line in which the root file system is mounted:

setenv bootrootfs “console=tty1
console=ttySAC2,115200n8 root=UUID=e139-fe3-99859 rootwait ro”

Substitute the original UUID with the UUID of the hard disk. This way, the Odroid will continue boot from the hard disk instead from the uSD card:

setenv bootrootfs “console=tty1
console=ttySAC2,115200n8 root=UUID=86135-2ba3-45cf-bda0-317b rootwait ro”

Next, open the /etc/fstab file (before unmounting the temporary mount, it was: /tmp/sda1/etc/fstab). Change the original UUID to the UUID of the hard disk:

UUID=86135-2ba3-45cf-bda0-317b / ext4 errors=remount-ro,noatime 0 1
LABEL=boot /media/boot vfat defaults 0 1

With this change, you will have the external hard disk permanently mounted.

I have written couple of instructions about setting up Raspberry Pi here.