Tips, moans, whines and anything I want to store that may help me or other people.
Sunday, 28 March 2021
Some more Pi
Been a while since I've done anything on here, let's face it 2020 was a washout and the first bit of 2021 has gone that way too. It does mean that things at home have come higher up the list of things to do and one of those things was to add a camera to a Raspberry Pi, point it at the sky and take pictures. The main idea was to get some shots of the stars moving but the clouds looked interesting too.
The first attempt was a quick lash up stuck in a plastic bag to give it some water proofing and put on the floor in the garden out of site of the street light at the back. This was a Raspberry Pi 2 and the version 1 camera which can go down to about a 6 second exposure, nothing lower than that so the stars didn't really stand out that well and there is a lot light pollution too.
Here's my first test, not great but it seems to show a bit of promise if we can get a clear night and even more so if we could try somewhere with a darker sky.
The other plan or project was a camera at the from of the house which apart from doing some timelapse would also take a picture every day at dawn, noon and sunset for a year from the 21st of March. For no other reason than it can be done. The noon bit was fairly straight forward, the sunrise and sunset were going to be harder. Until I came across something called "Heliocron". You can use this app to run a task at various times of the day and it calculates sunrise and sunset for you. Many thanks to the author for this.
Let's get started with my SkyCam as I call it, to run properly the Raspberry Pi needs a connection to a network so it can get the correct time. I have a plan B for a travel version but I'll come back to that.
I'm going to build this with a Raspberry Pi 3, a version 2 camera which gives 8Mp and shutter speeds down to 10 seconds. I need a waterproof case so I can stick it outside and a power and ethernet lead out of it. There will be some code which I've borrowed and modified from various searches, I can't remember where I got them but if it's yours then it's much appreciated.
This may not be the best way of doing it but it seems to work.
The finished article looks like this, I've managed to find an old Tripod bush so I can mount it outside and adjust the position.
Using the above mentioned Heliocron, it changes the exposure settings as it gets darker and lighter to keep some detail. I'm not clever enough to get it to take a measurement and do it automatically.
The script that will be taking the pictures is called:
mtshutter
There's going to be a couple of versions of it called mtday, mtdusk, mtearly and mtnight.
I stick the mt in front as it makes them easier to find.
I'm storing them in the /bin folder, I can't see any reason as to why not but if I'm wrong I'm sure somebody will tell me.
They all look fairly similar except for the picture taking settings, starting with mtshutter:
The pictures once taken are stored on a small file server mounted at /mnt/webcam in their own folder called skycam1, there may be another one in the future. You can of course change the location to wherever you want.
Make these executable with chmod +x /bin/mtshutter and so on. All these do is take one picture, which isn't much use for a timelapse camera.
Next we make a script to continually take pictures
This is mttakepic
#!/bin/bash
for (( ; ; ))
do
sh /bin/mtshutter
done
All it does is continually call the mtshutter script
We can get this running as a service on startup by creating another file:
nano /etc/systemd/system/takepics.service
Paste this into it
[Unit]
Description=Take Pictures
After=network.target
[Service]
ExecStart=/bin/mttakepic
WorkingDirectory=/mnt/webcam
StandardOutput=inherit
StandardError=inherit
Restart=always
User=root
[Install]
WantedBy=multi-user.target
And activate it with systemctl enable takepics.service
All that will happen now is the service will start, take some pictures, it will get dark and you won't see anything till it gets light again, this is where the other files come in to play.
At the moment we are running the daytime script, as it gets darker we need to shift to the dusk option.
nano /bin/duskmode
#!/bin/bash
echo "Dusk Mode" > ~/mode.log
service takepics stop
sleep 1
cp /bin/mtdusk /bin/mtshutter
service takepics restart
sleep 1
Then
nano /bin/nightmode
#!/bin/bash
echo "Night Mode " > ~/mode.log
service takepics stop
sleep 1
cp /bin/mtnight /bin/mtshutter
service takepics restart
sleep 1
nano /bin/earlymode
#!/bin/bash
echo "Early Mode" > ~/mode.log
service takepics stop
sleep 1
cp /bin/mtearly /bin/mtshutter
service takepics restart
sleep 1
nano /bin/daymode
#!/bin/bash
echo "Day Mode" > ~/mode.log
service takepics stop
sleep 1
cp /bin/mtday /bin/mtshutter
service takepics restart
sleep 1
You will need to get Heliocron now which can be found here.
I've made it executable and again put it in the /bin folder.
These are coordinates for Swansea, you will need to get yours for it to work properly.
At certain time of the day, the mtshutter will be overwritten and hopefully, we'll get a proper series of pictures which can then be compiled into a timelapse movie.
I've used mencoder to do it, you can install it with sudo apt install mencoder, I've got another script called mttimelapse which consists of the following.
No comments:
Post a Comment