Configure Raspberry Pi and Sense HAT for logging

Smart buildings are a really hot item right now, but how smart is your home? And how much do you know about what is going on in your home, when you are not there? What is a useful data-set to create? What data can you create? Luckily I got my hands on some Raspberry Pis with a Sense HAT Kit. Now I could try to answer these questions myself! I really wanted to figure out how the Raspberry Sense Hat kit worked. To my big surprise, it was rather easy to create a nice script that writes the Raspberry Pi SenseHat sensor data to a log file. This enabled me to analyze my data later-on by importing the log file into a spreadsheet program like Libre Office (or something similar). The spreadsheet enabled me to create nice graphs. As I’m always curious I tried this in a friendly environment at home, and in the harsh environment of my wife’s atelier where the environmental conditions are constantly changing caused by the warmth of the winter and heat produced by the glass kilns.

In this “how to” I’ll take you through the steps I took.

Install Raspian Buster Lite on your disk, by using dd or a program like Etcher. I’ll show you what I did using Ubuntu Linux.

Connect the disk to your computer find your disk by entering the following in the terminal:
$ sudo fdisk -l

Based on the size of the disk I found mine at /dev/sdb so to use “DD” I used the following commands:
$ umount /dev/sdb
$ dd if=./2019-09-26-raspbian-buster.img of= /dev/sdb

Wait with some nice music while the image is written to the disk (or get a cup of tea, or do something else as it might take a while).

Take the disk out of your computer and put it into your Raspberry.

Connect your Raspberry Pi to your monitor and hookup a keyboard.
Boot your Pi and and logon (username/password:pi/raspberry)

Configure your Raspberry Pi with a program called raspi-config.

$ sudo raspi-config

  • Hostname (choose a nice name)
  • Memory split (set it to 1 MB)
  • SSH (enable)
  • Time zone (choose your nearest town (of interest ;-))
  • Expand filesystem size

When finished reboot and check whether your Pi boots without errors.

Now you can hook it up to the network and connect to the Pi using SSH by entering the following command in a terminal session on your Ubuntu machine:
ssh pi@(your raspberry IP-address)

Next check your partition size and whether the complete disk she is being used:
$ sudo fdisk -l

Please take your time to update your Raspbian to the latest fixes and updates:
sudo apt-get clean && sudo apt-get -y autoremove && sudo apt-get -y update && sudo apt-get -y dist-upgrade –fix-missing && sudo sync

$ sudo reboot now

Personally, I’m a big fan of ZRAM to reduce wear and tear of your disk. It’s not mandatory so if you are not into it, you may skip these steps!

You can install ZRAM by entering the following command in your terminal:
sudo wget -O /usr/bin/

Configuring ZRAM Script
After it is downloaded, we need to set user executable permissions on it:
$ sudo chmod +x /usr/bin/

We now need to edit the rc.local file:
$ sudo nano /etc/rc.local

Add this before the “exit 0” line:
/usr/bin/ &

Close and save /etc/rc.local by pressing: Control + X, Y, Enter.

Reboot your Raspberry Pi to enable ZRAM:
$ sudo reboot now

Logon again using SSH (see the description above).

Time to install the necessary Sense Hat libraries:
sudo apt-get install sense-hat

After (or during) the installation of the Sense Hat libraries you can upload the LoggerScript from your Ubuntu to your raspberry. Open another terminal session on your computer and use “CD” to go to the folder containing the “”:
$ cd Downloads
$ scp ./ pi@(your raspberry ip-address):/home/pi/

In the session where you are connected to your raspberry with SSH you might want to make the script executable by entering:
$ sudo chmod +x ./

Now schedule it to your needs, in my example I’ll use every 15 minutes, using crontab:
$ crontab -e

A small advise to choose “NANO” as a text editor!

Add the following at the end of the file:
*/15 * * * * python /home/pi/

Suggestions for improving this article are welcome, please let me know and drop me a line .