This is part of a series on the Hawkeye Pi Camera – a Kodak Brownie Hawkeye inspired Raspberry Pi camera with a budget thermal printer.
The Hawkeye Pi Camera uses a Raspberry Pi, a Raspberry Pi v1.3 camera, and a bunch of software. This series will divide the software into the Hawkeye Pi program – written in Python3 – and all of the customized system services.
The Hawkeye Pi Camera’s Raspberry PI uses the latest Raspbian OS image. This provides most of the basic services. There are several services which are upgraded or customized. They include:
- Wireless networking
- Read-only OS
- USB storage access
- Python language
- Python packages
- New systemd service
The Hawkeye Pi Camera provides a web user interface for reviewing, reprinting, and deleting photos as well as basic administration and configuration. This requires network connectivity. The system automatically connects to the user’s local wireless network. However, for the web user interface to be usable away from a know wireless network, it also needs to be able to become its own wireless hotspot.
The logic goes like this: if there is a known wireless network then connect to it. If the connection fails then attempt to become its own access point. If that fails then things are SOL. If there is are no known wireless networks available then attempt to become its own access point.
In addition to this logic, this custom network solution also checks its status periodically to see if the environment has changed and this it should swap between connecting to a wireless network and being an access point.
All of this magic is courtesy of Roboberry’s blog post and his follow up blog post. These two posts output both the logic and the swapping. The only tweak needed for the Hawkeye Pi Camera was to specify the
wlan0 connection needs to use DHCP- to automatically get its access – when connecting to a known wireless network.
Roboberry’s solution required installing
hostapd for setting up an access point and
dnsmasq for handling wireless device connections to the access point.
Raspbian is a flavor of the Linux operating system. Like Windows or MacOS, Linux expects it will be started and shutdown in an orderly manner. However, the Hawkeye Pi Camera has no display or keyboard and is turned on and off with nothing more than a power button. This is the equal to unplugging a Windows or MacOS computer while it is running.
Making the SD card read-only prevents the Raspbian OS from becoming corrupted if it happened to be trying to update data on the SD card when the power was switched off.
There are two approaches to making Raspbian read-only.
The first is to find and tweak every process which wants to update the root file system and make the necessary changes to prevent it, then mount the SD card root file system as read-only. In the past this has been a manageable task. However, as Raspbian has evolved and newer sub-systems have been added, the task of finding every affected process and finding suitable tweaks has become unmanageable.
The second option is to establish an overlay to the root file system. The overlay is an in-memory file system. Any attempt to read from the file system will first look in the overlay and then in the underlying root file system. Any attempt to write to the file system will only write to the overlay. The overlay starts fresh every time the system starts so all previous changes are lost.
Both solutions require a method to make the file system read-write so changes can be made and maintained. The first option has the advantage of toggling from read-only to read-write and back at any time. The second solution is establish during the boot process so it requires the system be rebooted each time its needed to toggle from read-only to read-write or back.
The Hawkeye Pi Camera uses the second method. The read-only configuration of the Raspberry Pi’s SD card came from Pascal Suter’s blog post which he wrote to solve a corruption issue. The Hawykeye Pi Camera improved on Pascal’s solution with the creation of configuration files for the two modes and commands to swap configurations and trigger the reboot. Thus, toggling is as simple as using the commands
rpirw (and waiting for the system to reboot).
USB Storage Access
With the root file system having read-only access, the Hawkeye Pi Camera adds USB memory storage for the pictures and the configuration. The USB device needs to be accessible automatically, after the system boots and any time it is plugged in. The answer came from several sources and then one used was from Ddumont’s blog post.
It’s rather simple. The standard system service handing the file system will auto-mount the USB if it is correctly configured.
Raspbian includes Python (version 2.7.x). Near the completion of the Hawkeye Pi Camera, the code was ported to Python3 to improve the multi-threading performance. This required Python3 to be installed along with the development headers and tools.
The Hawkeye Pi Camera program uses a number of extra Python packages. These include:
python3-picamera for the Raspberry Pi camera,
python3-pil for the image data manipulation,
python3-serial to communicate with the thermal printer, and
python3-rpi.gpio to get input from the arcade switches and control the LEDs.
There are several ways to start a program when the Raspberry Pi boots. A good practice is to use create a system service. The Raspberry Pi Spy blog provides a simple example.
That pretty much covers the system changes. While it’s a bit boring, it is all useful information, not only for the Hawkeye Pi Camera project but also for lots of other raspberry Pi projects.