Daniel Müllner |
Raspberry Pi setup
The following tips are specifically for a Raspberry Pi with Arch Linux. They might save you some time if you are building a controller with the same configuration, but not everything applies in general.
-
To make the SainSmart 1.8 ST7735R TFT LCD Module work, do the following:
Add the line
dtparam=spi=on
to the file /boot/config.txt.
Generate a file /etc/modules-load.d/raspberrypi.conf with the following content:
spi_bcm2835 fbtft_device
Generate a file /etc/modprobe.d/fbtft.conf with the following content:
options fbtft_device name=sainsmart18 rotate=270
- This display is accessible as a framebuffer device. A splash screen or other static content can be easily displayed by copying a bitmap to /dev/fb1.
-
Unfortunately, one cannot easily detect when the Raspberry Pi has completely shut down and it is safe to switch off power. The green LED on the Raspberry blinks ten times at the end of the shutdown sequence, but if one misses this signal, it is unclear whether the computer is still running or not. In order to have a permanent indicator, I connected another green LED to a free GPIO pin (pin 16 in my case) and light the LED at startup. At shutdown, the operating system configures all GPIO ports as input, so that the LED goes out. This gives me a good indication when I can turn off power.
My startup script /etc/rc.local is as follows:
#!/bin/bash cd /root/fancontrol python2 led.py # Light the green LED cat startscreen.bin > /dev/fb1 # Display splash screen exit 0
The led.py script is contained in my GitHub repository with the controller software.
- The Raspberry does not have a real-time clock. At boot, Linux therefore sets the time and date to the beginning of the epoch (January 1, 1970). Even though I have a DCF77 module, it takes 1−2 minutes to receive the signal and set the time. For the period before the first valid DCF77 signal, the package fake-hwclock is very useful. This installs a systemd service which stores the time on shutdown and sets it back to the last value on startup. Although the time is off by the period that the Raspberry was shut off, I at least do not get strange log entries from the year 1970 after a reboot.
-
The fan control scripts are also run as a systemd service. Here is my file /etc/systemd/system/fancontrol.service:
[Unit] Description=Fan control [Service] Type=simple WorkingDirectory=/root/fancontrol ExecStart=/usr/bin/python2 -u control.py Nice=-19 IOSchedulingClass=realtime IOSchedulingPriority=0 TimeoutStopSec=30 [Install] WantedBy=multi-user.target
The controller can then be activated as usual by
systemctl enable fancontrol
respectively
systemctl start fancontrol
Note that terminal output from the Python scripts is saved automatically. The command
journalctl -u fancontrol -b
shows all terminal output from the fancontrol service since last boot (option -b).
The timeout in the systemd service file is quite long (30 seconds) since the controller, as a safety measure, always stops the fan and closes the window when it is being terminated. The window motor runs for up to 10 seconds, hence I generously allow 30 seconds for the process to stop before it is killed forcefully.
-
I also generate graphs for my web server from the logs. The graphs for the current day are updated every 5 minutes. Moreover, shortly after midnight, the final graph for the previous day is generated and uploaded to my web space. This is scheduled with systemd timers. Here is my file /etc/systemd/system/fangraph-now.service:
[Unit] Description=Graph for today's data [Service] Type=idle WorkingDirectory=/root/fancontrol Environment='HOME=/root' ExecStart=/usr/bin/python2 -u statistics.py 0 Nice=19 IOSchedulingClass=idle CPUSchedulingPolicy=idle TimeoutStopSec=10 RuntimeMaxSec=300 [Install] WantedBy=multi-user.target
This is the corresponding file /etc/systemd/system/fangraph-now.timer:
[Unit] Description=Generate realtime graphs [Timer] OnBootSec=3min OnUnitInactiveSec=5min 10sec [Install] WantedBy=timers.target
And this is the file /etc/systemd/system/fangraph-yesterday.service:
[Unit] Description=Graph for yesterday's data [Service] Type=idle WorkingDirectory=/root/fancontrol Environment='HOME=/root' ExecStart=/usr/bin/python2 -u statistics.py 1 Nice=19 IOSchedulingClass=idle CPUSchedulingPolicy=idle TimeoutStopSec=10 RuntimeMaxSec=300 Restart=on-failure [Install] WantedBy=multi-user.target
This is the corresponding file /etc/systemd/system/fangraph-yesterday.timer:
[Unit] Description=Generate daily graphs [Timer] OnCalendar=00:10:30 Persistent=false [Install] WantedBy=timers.target