Backing up images with the Raspberry Pi

System Integration

In order for this to work automatically, there must be a clean connection between the HAT server and the system. Thanks to systemd, this can be done with just a few lines. Listing 9 shows the service definition that you can create in the /etc/systemd/system/hat-server.service file. Line 9 starts the server program with ExecStart. The following line triggers the Boot-Start event. As a result, the red LED flashes during start up.

Listing 9


01 [Unit]
02 Description=Start HAT-server
03 DefaultDependencies=no
07 [Service]
08 Type=simple
09 ExecStart=/usr/local/sbin/
10 ExecStartPost=/usr/local/sbin/ BS
12 [Install]

A second service switches off the light at the end of the boot process. The accompanying service definition is found in /etc/systemd/system/endofboot.service (Listing 10). The service triggers the Boot End event on line 8 in ExecStart. Since the services system stops in reverse order to the start, we use also use the service for the Stop-Start event. The ExecStop command on line 9 does precisely this.

Listing 10


01 [Unit]
02 Description=Change status of HAT-LEDs
05 [Service]
06 Type=oneshot
07 RemainAfterExit=true
08 ExecStart=/usr/local/sbin/ BE
09 ExecStop=/usr/local/sbin/ HS
11 [Install]

Both services require one time activation with the commands from Listing 11. After restarting, the system automatically loads the services. The LEDs should light up as planned. Alternatively the user can switch the LEDs manually as desired from the command line with the script The function uses the copy script from listing 5, especially lines 5 and 9. These trigger the events Action-Start und Action-End. They also cause the yellow light to blink during the copy process.

Listing 11

Enabling hat-server.service, endofboot.service

$ sudo systemctl enable hat-server.service
$ sudo systemctl enable endofboot.service

And with that, your image tank has acquired its basic functions. As previously mentioned, the process works a little more easily with the Display-O-Tron. This particular extension is also made by Pimoroni and, like Pibrella, has a dedicated Python library for conveniently controlling the attachment. This Display-O-Tron offers many more functions.


Your image tank is now ready to go. Three LEDs and a button are all that is needed to interact with the device. Even so, we have not optimized everything that we could. The copy script only copies modified data, i.e. new images from the SD card to the hard drive. If you use multiple cameras which co-incidentally assign the same name to images, these will overwrite previously saved ones. The same problem can arise when image numbering for your own camera is reset.

A wireless connection to the Raspberry Pi would also be helpful, as images could be saved from smartphones and tablets. A nice web interface would also let you do things like view your vacation pictures. Extensions like these do not pose any real challenges for the Raspberry Pi. The second part of the article will appear in the next issue and lay out the necessary steps.

Buy this article as PDF

Express-Checkout as PDF

Pages: 6

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Pibrella board for Raspberry Pi

    Pibrella eliminates the need for a separate breadboard, jumper wires, and basic electronic components. This makes it a perfect board for prototyping and building both simple and advanced Raspberry Pi-based projects.