Astronomical clock with raspberry-pi

Raspberry pi as astronomical clock.

Whats you need:
– Raspberry Pi Zero W.
– Power supply 5 Volt with at least 2 Ampere out.
– Pc debian like as Ubuntu for work around.
– At least 4 Gb Sd memory.
Raspian Lite
– An always active Internet connection to the raspberry for Automatic time.

Start with pc linux terminal, write Raspian.img into Sd with:
sudo dd if=raspian.img of=/dev/sdb
Change path and name of raspian.img as your path and real usb device.

Now last operation with SD on Pc linux for configure Wireless Lan. Edit in the sd card sudo nano /etc/network/interfaces as below:

auto lo
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-ssid your-SSID
wpa-psk your-password

Save and put sd into Raspberry, discover IP and if nothing wrong you can be abled to connect to it with SSH client.
In recent version of Raspian SSH Service is disabled at boot, enable it creating an empty file named ssh into /boot/.
Connect at Raspi from pc in SSH with ssh pi@(raspi_IP) password raspberry.

Install Sunwait

Donwnload Sunwait here.
Decompress archive with:  tar -xvzf sunwait-20041208.tar.gz
Compile Sunwait with:  make
Now copy sunwait in the system folder /usr/local/bin/sunwait , to do it use:
sudo cp sunwait /usr/local/bin/
Sunwait calculate sunrise and sunset with geographical coordinates here an example for Italy:
sunwait -p 45.4153N 11.1174E
Result:
Using location: 45.415300N, 11.117400E
Date: 14 Jan 2018
Local time: 12:09
Day length: 9:10 hours
With civil twilight 10:12 hours
With nautical twilight 11:26 hours
With astronomical twilight 12:37 hours
Length of twilight: civil 0:31 hours
nautical 1:07 hours
astronomical 1:43 hours
Current specified time zone: CET (1 from UTC)
Sun transits meridian 1224 CET
Sun rises 0751 CET, sets 1658 CET
Civil twilight starts 0718 CET, ends 1731 CET
Nautical twilight starts 0641 CET, ends 1808 CET
Astronomical twilight starts 0606 CET, ends 1843 CET

Disk check at boot

To enable disk check at boot edit:
sudo nano /etc/default/rcS
Enable:
FSCKFIX=yes

Setting Cron
Edit cron event manager with:  sudo crontab -e
Insert this lines:
0 04 * * * /usr/local/bin/sunwait sun up 45.4153N 11.1174E ; python /home/pi/killlight.py
0 16 * * * /usr/local/bin/sunwait sun down 45.4153N 11.1174E ; python /home/pi/startlight.py
0 9 * * * /sbin/shutdown -r now

Pratically at 16pm sunwait is launched for wait sunset and at 04am sunwait is launched for wait sunrise. And at 9:00am raspberry reboot it.

Python code
When sunwait is launched by cron it write staus of light into a exchange file named IO.txt.
Copy startlight.py and killlight.py Script into raspberry home/pi/.
Finally main script astronomic.py it position is always /home/pi/ and for startup it at boot edit rc.local:
sudo nano /etc/rc.local
Insert first of exit 0
su pi -c 'python /home/pi/astronomic.py'

Schematic

 

Leave a Reply

Your email address will not be published. Required fields are marked *