Editors Note: Thank you Guest Blogger Jason Chalmers! This is a great tutorial on how to build a simple Astrophotography with the Raspberry Pi using sensor input from the WeatherRack2. He and his daughter got great results.
Introduction
Over the summer of 2020, my eight years old daughters developed a fascination with space. I wondered how I could nurture that fascination. I remembered how much my kids love the time-lapse videos produced by our SkyWeather2 kit so astrophotography popped into my head. What does astrophotography have to do with the new WeatherRack2 from SwitchDoc Labs? Let me explain.
Figure 1: The PiNightSky
Astrophotography Design
The plan that formed in my mind had some pretty simple requirements: use a Raspberry Pi and Raspberry Pi camera module to take still images of the night sky and combine the images into a time-lapse video in the morning. Like all projects, I utilized the Internet to show me what others had done before. In particular, I was most interested in finding some type of cover that would protect the camera from the elements. It didn’t take long before I stumbled upon the acrylic dome used in the project.
After I found the dome, I moved on to designing a 3D-printed part to hold the hardware. The design requirements were simple: a mounting plate to support the camera module, Raspberry Pi, and the acrylic dome. As always, efficient use of space was key.
The last requirement for the design was a container my daughters could decorate. Likely due to the prevalence of indoor and outdoor potted plants in our home, a flowerpot popped into my head. After a short meeting with my daughters, I received approval from management on my proposed design. Parts design and sourcing began.
Figure 2: 3D-printed hardware mounting plate
The size of the flowerpot used was intentional. The printing volume of my 3D printer is 150mm x 150mm x 150mm. As a result, the mounting plate could not have a diameter greater than 150mm so the flowerpot couldn’t be much more than 6.5” in diameter assuming the flowerpot was tapered.
Build
Parts list:
- Flowerpot – https://www.lowes.com/pd/Garden-Treasures-6-in-W-x-5-25-in-H-Green-Smooth-Plastic-Planter/3880783
- Rubber grommet – https://smile.amazon.com/gp/product/B07ZVLT9YS/
- Nylon fasteners – https://smile.amazon.com/Hilitchi-120pcs-Female-Standoff-Assortment/dp/B017QRA5MW/
- Brass fasteners – https://smile.amazon.com/Geekworm-Raspberry-Installation-Standoff-Accessories/dp/B0756CW6Y2
- Acrylic dome – https://smile.amazon.com/gp/product/B07DNVXBWP/
- Outdoor extension cord – https://www.lowes.com/pd/Utilitech-100-ft-16-2-2-Prong-Outdoor-SJTW-Light-Duty-General-Extension-Cord/3190317
- Male straight connector – https://www.lowes.com/pd/Project-Source-15-Amp-Volt-Orange-3-Wire-Grounding-Plug/4068219
- Right-angle USB connector – https://smile.amazon.com/gp/product/B00QR2YJTS/
- Right-angle USB-C cable – https://smile.amazon.com/gp/product/B07P9GJHPX/
- Silicon caulk – https://www.lowes.com/pd/GE-Silicone-2-2-8-oz-Clear-Silicone-Caulk/1043637
- 3D-printed mounting plate – STL File – https://github.com/switchdoclabs/SDL_Pi_Astrophotography
- WeatherRack2 – https://shop.switchdoc.com/products/wireless-weatherrack2
- Raspberry Pi Software Defined Radio – https://shop.switchdoc.com/products/software-defined-radio-sdr-and-antenna
Process:
- The male end of the extension cord was lopped off and the diameter of the cord was measured.
- The appropriately sized grommet was identified based on the diameter of the cord.
- The diameter of the outer wall of the grommet was measured and a hole was drilled into the flowerpot close to the bottom of the flowerpot.
- The grommet was seated into place on the flowerpot.
- The cut end of the extension cord was fished through the grommet from inside the flowerpot until only the female end of the extension cord remained in the flowerpot.
Figure 3: Extension cord and seated rubber grommet
- The right-angle USB adapter was plugged into the extension cord inside the base of the flowerpot.
Figure 4: Extension cord and right angle USB adapter
- The camera module was mounted on top of the mounting plate using nylon fasteners.
Figure 5: Installed camera module
- The Raspberry Pi was mounted below the mounting plate using brass fasteners.
- The ribbon cable was fished through the plate and connected to the camera and Raspberry Pi.
- The right-angle USB-C cable was plugged into the Raspberry Pi and the right-angle USB adapter.
- The mounting plate gently rotated as it was lowered into the flowerpot to allow the USB cable to wrap below the Raspberry Pi.
- Silicon caulk was applied to the mounting plate and acrylic dome to weatherproof the hardware.
Python 3 dependencies:
The flowerpot is controlled by a Python 3 script and relies upon the following modules:
- Eclipse Paho MQTT
- picamera
- pytz
- requests
- Pillow
The modules can be installed with the following command:
sudo pip3 install paho.mqtt picamera pytz requests pillow –upgrade
Astrophotography Software and STL Downloads
The files for this project are located here: https://github.com/switchdoclabs/SDL_Pi_Astrophotography
Ambient light challenges:
The first iteration of the flowerpot used a V1 Raspberry Pi camera module to capture images. The V1 camera module is limited to a maximum exposure of six seconds. In spite of only being open for six seconds, the image sensor is easily overwhelmed by the smallest amount of ambient light and produces a white image. As a result, the script called an external API in order to determine nighttime.
Specifically, the API returned a time for sunset and sunrise that was used to set a flag that controlled image capture. Unfortunately, ambient light is still present well before and after sunrise and sunset. As a result, the time lapse videos produced had lovely all-white intros that faded to black and all-white endings that got progressively brighter as sunrise approached.
In order to try and eliminate the unnecessary frames, the script was updated to utilize the times of first and last light as reported by the API. As before, a fair amount of ambient light is still present in the atmosphere even at first and last light. While the all-white intros and endings were shorter, they were still present.
What to do? The first thought I had was to apply a fudge factor to the first and last light times that would delay capture after last light and end capture before first light. The fudge factor would likely be an effective approach, it just felt too crude. The next thought I had was around artificial intelligence and whether image analysis could tell me if the image captured was usable. While AI would be a very elegant solution, it just felt too elegant.
What else? The answer finally hit when I thought why not add a sunlight sensor to the top of the mounting plate and I couldn’t believe my foolishness. I already have a fully functional sunlight sensor as part of the WeatherRack2 mounted on the low roof of our home!
Figure 6: WeatherRack2 on old satellite dish mount
WeatherRack2 to the rescue:
Immediately after receiving my WeatherRack kit from SwitchDoc Labs, I cloned the supporting GitHub repository and added MQTT support to the Python 3 script that receives telemetry data from the rack’s sensors. Publishing the data to an MQTT broker allows easy post-processing of the telemetry data utilizing Node-RED. As a result, I quickly set to work modifying the Python 3 script for the flowerpot to use the telemetry data from the WeatherRack2!
Current script functionality:
The script reads configuration settings from config.json and begins to establish an MQTT client. Prior to connecting to the MQTT broker, the following callbacks are setup:
- on_connect – handles the connection event to a MQTT broker
- on_disconnect – handles the disconnect event from a MQTT broker
- on_subscribe – handles the subscribe event to a MQTT topic
- on_message – handles the message event from a subscribed topic
Once the connection parameters are set and callbacks are created, the MQTT client opens a connection to the MQTT broker and starts a loop that waits for messages. Upon successful connection to the MQTT broker, the client subscribes to a topic on the broker that receives telemetry data from the WeatherRack2 from a separate process.
Specifically, the script is reading the lux value in the telemetry data. The lux value is used to set the value of a flag that controls the camera. A lux value greater than zero sets the flag to False and image capture is halted. A lux value of zero sets the flag to True and image capture is performed.
Results
Figure 7: Raw Big Dipper Picture
Here are two pictures of the raw and the processed data for the great view of the Big Dipper. Project successful!! The stars are there in the Raw file, but wait until you see the enhanced version!
Figure 8: Enhanced Big Dipper Picture
And a Video:
Conclusion
Figure 9: Final Assembly
Utilizing the sensor data from the WeatherRack2 has eliminated ALMOST all of the all-white images from the time lapse videos produced by the flowerpot. Additionally, the moon, clouds, fog, and rain present challenges to capturing good images of the night sky. As a result, refinement continues. My goal is to establish a GitHub repository for the project in order to maintain up-to-date source code that is publicly available as I progress. SwitchDoc has the software as of this writing at: https://github.com/switchdoclabs/SDL_Pi_Astrophotography
Most recently, the flowerpot went through software and hardware upgrades. The V1 camera module was replaced with a V2 camera module. The new camera has a maximum exposure of ten seconds. The mounting plate was also upgraded. The recess in which the acrylic dome sits was widened by 2mm to allow for a more forgiving fit. Also, the orientation of the Raspberry Pi was rotated 180° to avoid twisting the ribbon cable that connects the camera module to the Raspberry Pi.
The Python 3 script had two additional functions added: adjust_brightness() and adjust_contrast(). Both functions utilize the ImageEnhance object in the Pillow library to increase the brightness and contrast of images captured. Although we’re about 25 miles from the center of the nearest city, that city continues to get closer and closer to us so light pollution definitely impacts the brightness and visibility of stars in the ten-second exposures. The extra post-processing really increases the brightness of stars in the images.
Moving forward, the moon, clouds, fog, and rain are still challenging. The Pillow library includes the ImageStat object and the image stats have so far proven useful in identifying images that should likely be discarded due to clouds, fog, or rain. The moon is a unique challenge because I would prefer not to limit image capture to new moons. I may take a swing at figuring out how to pause image capture while the Moon is in the exposure based on the Moon’s path through the night sky and the position of the flowerpot on Earth.
Finally, the Raspberry Pi HQ camera module is a tantalizing thought because it supports 200s exposures!!!
Where did you get your dome? I have a somewhat similar project, an automated “PicturePost” (http://picturepost.unh.edu) and used a dome I found that was intended for underwater cameras. It lasted about 1 year before the acrylic yellowed so much due to UV that it was no longer useful. I replaced it with a glass salad bowl I found in eBay – that might not work for you because the bottom is flat, not curved.
Acrylic dome – https://smile.amazon.com/gp/product/B07DNVXBWP/
According to the marketing material, it is outdoor-rated.
Jason