Introduction: Wireless All Sky Camera
An all sky camera is a device designed to take pictures of the entire sky over a certain amount of time, usually to monitor meteor showers or other astronomical phenomena.
I built mine to monitor the northern lights. I live in the Yukon and we sometimes get beautiful aurora displays during the night. However, I also have a day time job and I need my 8 hours of sleep. I created this camera to record a movie of the entire night. That way, I can replay the movie in the morning and never miss any aurora night.
Step 1: Requirements and Materials
My requirements for this camera are the following:
- needs to photograph most of the sky
- needs high sensitivity to low light
- should be weather proof
- no wires should run to the house
- needs to be autonomous
- needs to create a movie from pictures and upload it to the internet
- needs to start at dusk and stop at dawn
After thinking about it for a while, I decided that the device should include its own computer and send the pictures using wifi. As for the camera, I decided to use an astronomy camera that would be small enough and was powered over USB.
Here's the list of materials:
- ASI224MC camera from ZWO (ASI120MC or MM works too and is cheaper)
- wide angle lens Arecont 1.55 (It gives a wider field of view than the lens that comes with the camera)
- Raspberry Pi 2 (or 3)
- 64 GB micro SD card
- Wifi module (no need if Raspberry Pi 3)
- Short right angle USB cable
- 4" ABS pipe with end caps
- Acrylic dome
I thought about adding a dew heater but after a few month of testing, I never got any frost on the acrylic dome. This is possibly due to the heat produced by the raspberry pi itself.
Step 2: Wiring
In this instructable, I will assume that you already have raspbian installed on the SD card.
The wiring is relatively easy. Plug the USB cable to the camera on one side and the raspberry pi on the other. Plug the wireless dongle into one of the 3 remaining USB ports of the pi. Insert the micro SD card in its slot and plug the raspberry pi to its 5V adapter.
In order to keep things tidy, you can fix your camera and computer onto a plywood board like I did on the picture.
Step 3: Build the Enclosure
The enclosure is made of a 4" ABS pipe, a flat end cap and a threaded end cap with its lid.
The flat cap goes on top and is drilled to the diameter of the camera. The threaded cap goes at the bottom and a hole (for the extension cord) is drilled in the centre of the lid.
The acrylic dome can be fixed onto the top end using weather proof silicone. I used an acrylic ring but it makes things more complex than they need to be.
You can now fix the enclosure onto your deck, your roof or any other location with a good view of the sky.
Step 4: Software
Update: If you need to change the way the capture works, you might have to make changes to the C++ source and compile it on your Raspberry PI. To do this, follow PeterD192's detailed instructions in the comments.
Update 2 (Nov 11th 2016): I have set up a GitHub page with an install script to make things easier for everyone: https://github.com/thomasjacquin/allsky If you use it, you shouldn't have to use any of the following instructions.
In order to capture images with the camera, we need to run a program in the terminal. ZWO provides an SDK in order for developers to communicate with the camera. Using this SDK, I modified one of their C++ example and compiled it for the raspberry pi. Here's a list of dependencies that need to be installed in order to get the program running.
- OpenCV to capture the image of the sky (You can get a compiled version here)
- Sunwait to calculate the civil twilight of your location. There is a compiled version in the archive. Make sure you copy it to your path:
sudo cp ~/allsky/sunwait /usr/local/bin
- Required dependencies:
sudo apt-get update && sudo apt-get install libusb-dev libav-tools gawk lftp entr imagemagik
To make things easy, I have attached an archive. Extract it at /home/pi/allsky.
From the lib folder, you will need to run this in order to use the camera without being root:
sudo install asi.rules /lib/udev/rules.d
You will also need to add libASICamera2.so to your library:
sudo cp ~/allsky/lib/armv7/libASICamera2* /usr/local/lib
Another thing you will need to do in order to automate everything is to run the main program on startup of the pi. You can open ~/.config/lxsession/LXDE-pi/autostart and add this line:
@xterm -hold -e ~/allsky/allsky.sh
Remember to set your wifi connection in order for the pi to upload videos.
allsky.sh contains all the parameters you might want to play with: GPS coordinate, white balance, exposure and gain.
Step 5: Collect Images
Now that the raspberry pi is ready, you can plug your all sky camera. The startup script should call allsky.sh which in turn calls the binary file named "capture". It will determine if it's day time or night time. In case it's night time, the capture will start and take a picture every 5 seconds (or whatever value you set in allsky.sh). At the end of the night, the capture will stop and avconv will stitch them together and upload a video to your website using FTP.
Step 6: Watch Your Time Lapse Videos
The video produced by avconv should weigh between 30 and 50 mb depending on the length of the night (here in the Yukon, we can get from 18 hours to 0 hours of night time) and should be viewable on any web browser.
In the event that you find something interesting in the video, you can access the individual images on the raspberry pi. They will be in a folder named after yesterday's date.
Here's a page showing my own videos with almost all night archived starting January 18th 2016. Some have beautiful northern light, others have clouds, snow or rain.
First Prize in the
Space Contest 2016
14 People Made This Project!
We have a be nice policy.
Please be positive and constructive.
Having a problem with image capture. Starting a couple days ago, the camera is not updating the image. It seems to be going through the motions of taking a picture, saving file, uploading image to my ftp site. But each image is just a repeat of the last, except the date/time stamp is added (overwriting the last, which becomes a jumble after a while).
I have tried rebooting, checking settings etc but no effect. The only thing I had been messing with at the time (that I can recall!) was the gain setting.
Appreciate any ideas short of power cycling - camera is currently a 2 hour drive away in a dark sky park :=).
I ran into this once before with my 290MM camera - I think I ended up formatting the Pi3 and installing everything from scratch.
Attached is an example (first image and 4th image after rebooting, plus close-up of data/time stamp).
Thanks Thomas. Card is 128GB and is more than half empty. I had similar thoughts about possible resource issues. And I wonder if the camera's relatively larger images (178MC - 6.4MB) is causing issues somehow. Exposures are 20s with essentially no gap in between (default 10ms). Maybe next I'll try adding a gap in between (perhaps a few seconds) to see if it makes a difference.
If you thought it was helpful, I could provide you with remote access (via VNC) to the camera/Pi.
avahi-daemon is a service that let you connect to the Pi without knowing the IP. It uses the host name of the computer. For example in our case you can access the RPi using http://allsky.local
It gets installed when you install the GUI. In order to uninstall the GUI, you can just prevent lighttpd from starting at boot time:
sudo systemctl disable lighttpd
sudo systemctl disable avahi-daemon
and in config.sh, set this variable like so:
You'll have to reboot to make sure everything is disabled.
Now regarding the stacked images, do you have room left on the SD card? Also, what's your exposure setting? I'll investigate a bit more on my side in the mean time.
Yes, used the # sign to comment out (and no evidence that allsky.sh is running on reboot).
I checked for entr, capture and lftp processes but none evident before running allsky.sh manually.
One example last night: after rebooting and starting manually (and making sure per above that no entr/capture/lftp was running beforehand), and then disconnecting VNC session.. Worked fine for about 15 minutes, then starts "stacking" the date/time.
Here is example video from last night (example starts at 11:50pm):
Also I am wondering:
1) What exactly is the avahi-daemon: running [allsky.local] ?
avahi 346 0.0 0.2 6532 2764 ? Ss 18:54 0:10 avahi-daemon: running [allsky.local]
2) How can I turn off or uninstall the gui interface?
Did you comment that line using the # sign?
Also, when you start allsky.sh manually and Ctrl + C to stop, I would advise that you run these before starting the process again:
I have seen entr being duplicated in the past and that would cause issues as it would call saveImage multiple times.
Tried your suggestions (commented out the allsky line in autostart, rebooted Pi, started allsky manually in terminal window) but it did not go that well. After a couple attempts at starting allsky manually (stop and restart script), it seemed to be working but after about 1/2hour it started doing the "stacking" (of date/time) again. Tried rebooting a couple of times but no change.
Each time I reboot, it will take a fresh picture for first capture but every subsequent capture just results in a duplicate of the first, but with the new date/time overwritten. I don't think it is "stacking" the whole picture because there is no sign of star trailing.
Also I notice a couple of times the Pi seemed to reboot itself (ie. lost VNC connectivity and when reconnected, any open programs/windows including the allsky script were closed).
I'll keep playing with it. Might try re-installing the Allsky code next. Open to any further suggestions you might have.
In your situation, what I would do is the following:
- Remove the allsky line from /home/pi/.config/lxsession/LXDE-pi/autostart (That will prevent the autostart)
- Reboot the RPi or if rebooting is not an option, you can kill any processes with the names allsky.sh, ./capture, entr, lftp.
- Connect to the RPi using VNC, open a terminal, cd to the allsky directory and run ./allsky.sh
- Leave the terminal open. Now you can disconnect and reconnect to the Pi using VNC without triggering a new process every time.
I believe that should work in your case.
Thanks Thomas. Now that you mention it, I seem to recall that being mentioned before.
I only have one instance of allsky.sh in /home/pi/.config/lxsession/LXDE-pi/autostart
However, I do access using Real VNC/VNC Connect, so I guess that is the source of my problem. Funny that it was working for weeks before now and I had been connecting via VNC multiple times - I wonder what triggers it?
SSH is not currently an option as the Pi/Camera is behind a NAT (that I don't control).
I see these as current running services (ps - aux | grep allsky):
avahi 346 0.0 0.2 6532 2764 ? Ss 18:54 0:10 avahi-daemon: running [allsky.local]
pi 836 0.0 0.8 13944 8288 ? S 18:54 0:01 xterm -hold -e /home/pi/allsky/allsky.sh
pi 874 0.0 0.2 4628 2584 pts/0 Ss+ 18:54 0:00 /bin/bash /home/pi/allsky/allsky.sh
I think 874 is the allsky script and 836 is the XWindow it is running in? If I delete these two processes, they just start back up automatically (maybe because I am connected via VNC Server at the time?).
Is there any option for me to kill/remove the extra allsky process that is causing the stacking issue (via VNC Viewer connection)? Or am I hosed until I get local access to the Pi?
I don't use the Allsky GUI (to save on resources). Normally use the Pi XWindow menu to do Shutdown/Reboots.
Thanks again for all your help. I'm still having a blast with this project!
Hey Dave, do you use any kind of remote desktop software to connect to the RPi? In the current version (v0.5), The allsky.sh script is called automatically on startup. It will also be called when you create a new session using Remote desktop, VNC, etc.
That's how people usually end up with the same issue of images being stacked. Version 0.6 will remove this behaviour.
It won't create multiple instances if you connect using SSH.
Also, note that if you're using the GUI, you can power cycle using the reboot button on the "System" page.
Also, make sure you have only 1 instance of allsky.sh in /home/pi/.config/lxsession/LXDE-pi/autostart
Thomas, What is supposed to happen when it erases old image files or if the SD card runs out of memory? I think the latter happened to me. I had a 64 Gb SD card, but when I went to access the images the other night the Rpi was complaining about out of memory space and while I can log into the Rpi I cannot access the image files to try and erase some and make more space. I believe I had it set up for a 1 month supply of images, before it would start erasing the old files. When I did log in it seemed all my image file directories were empty, even the current ones.
When a linux computer runs out of memory, it behaves in a weird way. For example, it will fail to list your files or directories. It will also fail to auto-complete when using the TAB key.
What I would suggest is to manually run something like
'rm -rf /home/pi/allsy/images/20180517/'
It should clear 1 day worth of data and give you enough space to behave properly. You may have to reboot as well.
thanks that helped, let me see what I can salvage
back up and running
I have seen discussion elsewhere regarding ASI (and other CMOS) camera gain and offset. I don't see anywhere in the all-sky camera code to set the 'offset'. Does this mean that an "appropriate default" is being used automatically (perhaps being set by the API)? Or is offset always defaulting to 0?
As I understand it, there are ideal (or at least recommended) offset values for given gain values.
I looked at the SDK documentation and it appears that the offset is the same as the Brightness setting:
ASI_BRIGHTNESS,//pixel value offset (a bias, not a scale factor)
The default value is 50 but you can set it to a different value (between 0 and 100 I presume) using the GUI. It is a manual setting for now but may include it alongside auto exposure in v0.6
Hi, Thomas. Great share of info.
I am using asi120mc, downloaded allsky.git. followed all through your instruction.Key in Lat Long number. Key in ftp server login . choosen GUI
rebooted. screen showing allsky.sh running. detected asi120. saving 5s exp image every 10ms. press Ctrl C to to stop. and cd '..allsky/' [connecting....]
i go to my ftp server. i didnt se any images uploaded. i go to var/www/html/images or img , also no new image file being uploaded or created
i am lost. please kindly help . thank you
Hi Louis, the images are saved in the following directory: /home/pi/allsky/images/
If the image wasn't uploaded to your server, it's probably an FTP configuration issue. Have you connected to this server before? If not, try to ssh to it in order to add it to the known hosts:
Run ./allsky.sh again and wait for the ftp debug information to show up in the terminal. It will tell you if the transfer worked or failed.
Setting up a second (colour) unit based on 178MC. Everything seems to be working fine except the timelapse creation is not working (creates 0 length mp4 file). If I run avconv command manually, I get this error:
frame= 42 fps=1.8 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed=
frame= 43 fps=1.8 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed=
frame= 44 fps=1.7 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= x264 [error]: malloc of size 20515824 failed
Video encoding failed
[libx264 @ 0xceda40] final ratefactor: 30.79
This is the manual command I am using:
pi@allsky:~/allsky $ avconv -y -f image2 -r 25 -i images/20180410/%04d.jpg -vcodec libx264 -b:v 2000k -pix_fmt yuv420p images/20180410/allskytest-20180410.mp4
individual images did get numbered sequentially and there are no 0-size files. They are all jpg's.
I'm still trying to figure out how the instructables comments threads are organised. I think my answer is still here but kind of hidden. I had to expand an arrow to see it.
Anyway, yes you can resize the images using the Image Magick's 'mogrify' command. Instead of creating a whole new set of scaled down images, it overwrites them. Here's the doc:
You could probably call the command at line 17 on timelapse.sh
Hmmm, Thomas's answer from yesterday seems to have disappeared? Anyway, you were right on the money Thomas. Images are the full 3096x2080 (~1.8M files). And the memory does drop from around 700MB to about 30MB before error (usually gets to about 40+ frames). Interestingly, when I watch the memory use on my 290MM based unit (smaller sensor/file sizes), the free memory also drops from 600-700MB down to 20-30MB (and stays in the range) , but it does not error out.
I found these references:
So I tried increasing the CONF_SWAPSIZE from 100 to 1000 (swap space on SD Card) and it worked. However, the timelapse creation takes much longer to complete (3-4 hours). Not a problem for me as my Pi has nothing else to do during daylight hours!
However, downsizing the images before timelapse processing might be a more elegant solution (as you suggested). Any suggestions on how to downsize images on-the-fly before being fed into avconv? Perhaps an imagemagik command?