Pi Sliced Day Photos is a .NET Core (C#) program designed to be run on a Raspberry Pi that can take photographs at Sunrise, Sunset, a number intervals in-between and at custom times specified either by clock time or minutes +/- from sunrise/sunset. This program was written specifically to support scheduling that I did not find easily available in other programs.
The Pi Sliced Day Photos Timelapse Helper Windows Desktop GUI and command line program create Timelapse Videos from the photographs created with the Pi Sliced Day Photos by using FFmpeg. These programs understand the naming conventions of the Pi Sliced Day Photos program and make sorting and filtering based on different cameras and schedules easy. These programs also have some interesting options like combining photos from different cameras into a single video.
Pi Sliced Day Photos Downloads
Pi Sliced Day Photos Timelapse Helper - Windows Desktop Gui - Downloads
Pi Sliced Day Photos Timelapse Helper - Commandline - Downloads
Pi Sliced Day Photos
The inspiration for this program is living 6,000' below and 5 miles west of a mountain peak. This program allows us to input sunrise and sunset times that match when the sun comes over the ridge to the east and when it sets over the various mountains on the western skyline. With sunrise/sunset times so influenced by topography 'halfway thru the available sunlight for the day' becomes a much more interesting scheduling option than a photo taken at a certain clock time or sun angle.
The sunrise/sunset times for the program must be provided as a CSV file - this requires some extra work but leaves you free to use any times you want. A great way to use this is by generating sunrise/sunset times based on the topography around the camera site (see the notes below) - in many cases the sunrise time on an imagined horizon is not photographically useful or interesting, the sunrise time when the sun emerges from behind a mountain peak is much more interesting!
The image below was created with the Pointless Waymarks Utilitarian Image Combiner by combining the output of this program from 3 Raspberry Pi 3 A+ computers with Wide Angle Camera Module 3 cameras - the cameras face, approximately, west, north and east
Program Requirements
- A Raspberry Pi where .NET Core can run and an attached camera that responds to libcamera-still. This program has only been confirmed to run on a Raspberry Pi 3 A+ and B+ with a Camera Module 3 Wide - but I believe any 2+ version Pis, official Pi camera modules and current version of the Raspberry Pi OS will work.
- A settings file named PiSlicedDaySettings.json - an example is included in the code and there are notes below.
- A CSV file named SunriseAndSunset.csv with the calendar day, sunrise time (local) and sunset time (local) - an example file is included with the code.
Sunrise and Sunset are always photographed - you can also specify:
- How many photographs you want between Sunrise and Sunset (during the day - 0 is valid)
- How many photographs you want between Sunset and Sunrise (during the night - 0 is valid)
- Times relative to sunrise and sunset - for example Sunrise-10 for a photograph 10 minutes before Sunrise or Sunset+10 for a photograph 10 minutes after Sunset.
- Clock Times
SunriseAndSunset.csv
This program uses a file of Sunrise/Sunset times to allow you to input any sunrise/sunset times that you want - a strong use case for this is generating topography compensated Sunrise/Sunset times for your location. For example, today at my house we didn't see the sun come over the mountains to the east until 40+ minutes after the sunrise time calculated for the 'true' (imagined) horizon...
The SunriseAndSunset.csv file should be formatted like the sample file included with the program:
DAY, SUNRISE, SUNSET
2023-01-01,08:15:00-0700,17:23:00-0700
2023-01-02,08:15:00-0700,17:24:00-0700
If you are interested in generating Topography compensated Sunrise/Sunset times for your location try:
- gvellut/tppss: Compute sunrise / sunset times taking into account local topography - this is a great free way to generate the times - it does take some setup, but like me you might find preparing the data for the program is an interesting project!
- Find Your Location and Compute Sunlight Conditions - a paid service that will do this for you.
- Various photography apps can calculate/show you this information but I'm not sure if any of them export yearly (or multi-year) data...
Settings File
DaySlices - Takes an integer and determines the number of photos taken between sunrise and sunset.
NightSlices - Takes an integer and determines the number of photos taken between sunset and sunrise.
PhotoStorageDirectory - The path to where the photos are written.
SunriseSunsetCsvFile - The name (including extension) of the csv file of Sunrise and Sunset times.
PhotoSeriesName - Postfix for the photo name - this defaults to the machine name if not present.
LogFullExceptionsToImages - The assumption is that this program will run largely unattended and that most of the time the only thing you will see is the photographs. The program will try to alert you of errors by writing exception information to an image file in the PhotoStorageDirectory. This setting determines whether the program writes all of the exception information or only an abbreviated message. This option exists because writing full exception information may leak information about your setup!
LibCameraParameters - Day/Night/Sunset/Sunrise - command line parameters for libcamera-still.
CustomTimes - Custom times can be specified either as clock times (3:45 pm) or as minutes before/after sunset (sunset +10). Each custom time also gets LibCamera parameters.
"CustomTimes": [
{
"Time": "Sunset+10",
"LibCameraParameters": "--autofocus-mode manual --lens-position 0 --awb auto --metering average --denoise cdn_hq"
},
{
"Time": "Sunrise-10",
"LibCameraParameters": "--autofocus-mode manual --lens-position 0 --awb auto --metering average --denoise cdn_hq"
}
]
Setup Notes
Suggested setup on the Pi - this is here for convenience and was last updated July 2024. As OS and Pi details change some/most/all of this might become irrelevant, or even harmful, and this by no means covers all the details needed to run a Pi securely and appropriately. The setup below is pretty basic, but use at your own risk!
- I haven't had any issues with older packages in my own installs, but certainly if the Pi is going to be dedicated to PiSlicedDayPhotos I would suggest running 'sudo apt-get update' and 'sudo apt-get upgrade' before installing the program.
- In your home directory - make a directory for the program and the photos:
mkdir PiSlicedDayPhotos
mkdir SlicedPhotos
- Copy the published output of this solution into the PiSlicedDayPhotos folder - then change the permissions for the program to be executable:
chmod +x PiSlicedDayPhotos/PiSlicedDayPhotos
- You will probably want to change the settings for the program:
nano PiSlicedDayPhotos/PiSlicedDaySettings.json
- Run the program as a service: Edit the pisliceddayphotos.service replacing [Your Directory Here], copy it to /etc/systemd/system/, start and follow the service to check for any errors:
nano PiSlicedDayPhotos/pisliceddayphotos.service
sudo cp PiSlicedDayPhotos/pisliceddayphotos.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable pisliceddayphotos --now
journalctl -u pisliceddayphotos -f
I like to disable the LEDs to make sure that the glass covering the lens opening won't pick up any light from the LEDS - How To Easily Disable Status LEDs On RaspberryTips
sudo nano /boot/firmware/config.txt
Add the following lines to the end of the file:
#Disable Power LED (Red)
dtparam=pwr_led_activelow=off
#Disable Activity LED (Green)
dtparam=act_led_trigger=none
dtparam=act_led_activelow=off
#Disable LAN LEDs
dtparam=eth_led0=14
dtparam=eth_led1=14
My preference is for Automatic/Unattended Upgrades - do this long enough and something unexpected will break, but I would rather stay up to date and have something break sooner rather than later. Secure your Raspberry Pi by enabling automatic software updates – Sean Carney and UnattendedUpgrades - Debian Wiki
sudo apt-get update
sudo apt-get install unattended-upgrades
sudo dpkg-reconfigure --priority=low unattended-upgrades
If you've worked in years gone by with the Pi Camera and C# you might know the very useful techyian/MMALSharp: C# wrapper to Broadcom's MMAL with an API to the Raspberry Pi camera - unfortunately without choosing an older version of Raspberry Pi OS that library no longer works. The Pi has moved on to libcamera. I didn't find a C# wrapper for libcamera and since I didn't need to do anything other than write stills to the Pi's storage calling libcamera-still 'command line style' seemed to be the best option.
I didn't find a single great place for libcamera-still documentation - frustrating until I figured out that (beyond 'getting started' content) running 'libcamera-still --help' was really the best single source of information.
July 2024 Update
I have been running 3 Raspberry Pi 3 A+ computers with the Wide Angle Camera Module 3 cameras for over 6 months now - the PiSlicedDayPhotos program and Pis have run without issues or attention needed! However, a few things have come up:
- Dirty UV lens filters: With these in an exposed outdoor location I anticipated the outside of the filters getting dirty - but I didn't realize how dirty the inside would get. In my initial setup I hot glued UV filters to the enclosures to weatherproof the camera opening - this worked well overall but there is no easy way to clean the inside of the filter or the lens of the Camera Module. I have now updated my enclosures with an inexpensive 58-55mm Step-Down Ring hot glued to the enclosure for the UV filter to screw into. This is an improvement, but I do wonder whether after 6-12 months of sitting outside unattended whether the UV filter will still be easily removable.
- File Names: My Pis have run long enough for the sun at sunset to make a full trip south to north. When I went to process some of the photos I realized that there were some good details - the date and time was available directly in the file name and I had used the PhotoNamePostfix setting to identify the different cameras in the file names. But because the sunset/sunrise times are constantly changing it was more difficult than it should have been to filter the files for sunset/sunrise/slice... The Program has been updated so that file names now include some schedule information that should make this easier.
- It is my fault for not being more careful but I cracked a microsd trying to get it out of the longest lived Pi - I'm not sure if it was the temperature and outside conditions but all of the microsds were more difficult to remove than I am used to. I don't see a sea of postings about this online so maybe just carelessness and bad luck, but I'm not sure how many Pis sit outside in the Arizona summer?
Backstory
For a number of years my wife and I used a previous (now-archived) project - cmiles/PiDropLapse - and a Raspberry Pi 4 Model B to take periodic photographs and sensor readings to monitor an area inside our house.
Since moving to a more rural property I have wanted to do a similar project but outside and solar powered - Raspberry Pi shortages, never quite finding an in-stock dedicated Pi solar setup that I loved and other house projects delayed that idea...
Recently we installed a 24V/100aH solar system near our parking area. The main purpose of this system is to power the rodent deterrent lights for our trucks - but luckily it has more than enough power to also power several Pis for photo purposes!
My Setup with Notes
Most of the gear below was purchased mid-2023, but I have added a few mid-2024 updates. I hope to keep my current setup running for a very long time so I won't be constantly updating this list with the latest and greatest gear - but I will try to update with improvements, notes, failures and successes.
- Raspberry Pi 3 Model A+, 5V 2.5A Switching Power Supply with 20AWG MicroUSB Cable, 32 GB MicroSD Card and a case from Adafruit: This is about $60 USD plus shipping - I like the $25 USD price of the 3 A+, the full sized HDMI port and the slim profile.
- Raspberry Pi Camera Module 3 - 12MP 120 Degree Wide Angle Lens: I love photography - you can see some of my work over on Pointless Waymarks - so I considered a number of choices for this project but in the end the cost/convenience/size/performance of going with a $35 official camera module won out.
- Wooden Enclosure: Hopefully weatherproof (enough)! Built with spare/scrap wood, bug screen sitting in a closet and the paint for our deck. The main feature is that I recycled existing materials for this... As you can see in the photo above the carpentry is very (very!) basic so no details are included. Mounting the camera and weatherproofing the exit hole for the camera/lens took a few tries:
- I tried using plexiglass for the entire front panel of the enclosure - but at least with the plexiglass I had the images were never sharp. I was using plexiglass left over from another (not camera oriented) project and I didn't want to dive into figuring out 'best optical quality plexiglass' (and didn't want glass for durability reasons) so I moved on.
- I moved from the plexiglass front panel to a wooden one. I drilled a hole large enough for the lens and mounted the camera tightly to the front panel - which didn't work, mounting the front of the camera package tightly against something can end up impacting focus...
- In the end for focus and to make sure the wide angle camera has a clear view I made a larger hole for the lens and used spacers to ensure the front of the camera isn't against anything. This approach made it important to find something to cover the hole for weatherproofing.
- I tried a plexiglass dome off of Amazon to cover the exit hole for the camera - this was great for part of the photograph but distorted the edges. It's possible that the distortion would go away if I mounted the camera farther into the dome or found a the right dome, but I wasn't interested in either of those options.
- The solution that finally worked for me was hot gluing a $5 Sensei 58-55mm Step-Down Ring to the enclosure and screwing in an $8 Tiffen 55mm UV Protector Filter - it is easy to find smaller diameter filters but after some experiments I liked this size because it was very easy to position it so that the edge of the filter didn't end up in the photographs.
- With the mostly recycled enclosure the cost of the system is around $105 (mid-2023) - potentially a bit more with tax and shipping.
- Solar: As mentioned above powering the system with solar was a goal for this project - but it turns out that the solar system powering my setup isn't dedicated primarily to running the Pis... So only tangentially related, but for the sake of fully documenting the project the main components of the solar system are listed below. This system is massive overkill if you just want to run a few Pis, like most real-world systems I had many constraints and goals that are not in line with 'build the world's best small solar system'. Nothing below is a recommendation, I don't have enough experience to do that, but fwiw I am happy with the setup (wiring, fuses and some other small parts and details omitted - btw if you are building a system like this for the first time be sure to look up wiring and fuse/breaker cost - it was much more than I guessed...).
- 6x Newpowa 100W 12V Mono Compact Solar Panels - we started with fewer panels but with the overwhelming majority of the load on this system at night 600W of panels has made it more likely that on short, stormy, winter days we can charge the battery bank to capacity during daylight hours.
- 2x Ampere Time 12V 100Ah Lithium Batteries - purchased used, wired in Serial for 24V.
- Victron Energy SmartSolar MPPT 100/20 - if you are buying a solar charge controller for the first time pay attention to the Nominal PV Power rating at a particular voltage - at 12V this device supports 290W, at 24V it supports 580W. We moved to 24V about 9 months in so we could connect more panels.
- Victron Phoenix 24V/1200W Inverter with Victron VE.Direct Bluetooth Smart Dongle - we started with a 12V/800W inverter which was ok but wouldn't run some of our power tools, when we moved the system to 24V we upgraded to a 1200W inverter which so far has run everything we have expected it to. Of the Victron devices we have this is the only one where the system communication isn't great - the Bluetooth connection is very very useful but I don't think you can run the Bluetooth Smart Dongle and a USB connection to the Victron Remote Monitoring System at the same time which is slightly frustrating...
- Victron SmartShunt
- Raspberry Pi 3 Model A+ running the Victron Energy Venus OS to provide communication between the system and the Victron Remote Monitoring System. See Panbo's Raspberry Pi Victron Venus OS Install post and as of 9/18/2023 see Raspberry Pi 3A+: VRM Portal ID Missing for critical information on getting Venus OS working correctly on the 3 A+. I used 3 VE.Direct to USB interface cables to connect the SmartSolar, SmartShunt and Inverter to the Pi (currently the Bluetooth interfaces are not used to connect devices to the Victron Venus OS/Cerbo GX units! The Bluetooth is worthwhile though because it creates a pretty great app experience, at least on Android...).
Other Projects
Fundamentally this project is just taking photographs with the Raspberry Pi which is not hard to do and you can find other great free projects and code to take stills, timelapses and more! One of my favorites is GitHub - thomasjacquin's allsky: A Raspberry Pi operated Wireless Allsky Camera - I hope to build on of these in the future... Also see Roll Your Own All-Sky, Raspberry Pi Camera - IEEE Spectrum and the Hacker News discussion.
Tools and Libraries
This program would not be possible without the amazing resources available for creating Free software! Used in this project:
Tools:
- Visual Studio IDE, .NET Core (Linux, macOS, and Windows)
- ReSharper: The Visual Studio Extension for .NET Developers by JetBrains
- GitHub Copilot · Your AI pair programmer · GitHub
- AutoHotkey
- Compact-Log-Format-Viewer: A cross platform tool to read & query JSON aka CLEF log files created by Serilog
- Fork - a fast and friendly git client for Mac and Windows
- LINQPad - The .NET Programmer's Playground
- Notepad++
Core Technologies:
Libraries:
- GitInfo | Git and SemVer Info from MSBuild, C# and VB. MIT License.
- serilog/serilog: Simple .NET logging with fully-structured events. Easy full featured logging. Apache-2.0 License.
- RehanSaeed/Serilog.Exceptions: Log exception details and custom properties that are not output in Exception.ToString(). MIT License.
- serilog/serilog-formatting-compact: Compact JSON event format for Serilog. Apache-2.0 License.
- serilog/serilog-sinks-console: Write log events to System.Console as text or JSON, with ANSI theme support. Apache-2.0 License.
- toptensoftware/RichTextKit: Rich text rendering for SkiaSharp. Apache-2.0 License.
- mono/SkiaSharp: SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.. MIT License.
- NUnit.org. NUnit License
- thomasgalliker/ObjectDumper: ObjectDumper is a utility which aims to serialize C# objects to string for debugging and logging purposes.. Apache-2.0 License.
- Codeuctivity/SkiaSharp.Compare: Adds compare features on top of SkiaSharp. Apache-2.0 License.