Jump to content
Welcome to Backyard Astronomy Space - please register to gain access to all of our features. Click here for more details. ×
SmallWorldsForum Microscopy and macro photography - a companion forum to BYA ×

Raspberry Pi add on real time clock


TerryMcK

Recommended Posts

The Raspberry PI is a wonderful little computer but does lack a real time clock. Fortunately there are add on boards available that cost only a few quid and can be simply added to the mainboard of the PI.

There are many available and most seem to use the DS3231 chip along with a battery. I bought a set of 4 from a well known online retailer and added them to my various PIs.

 

The advantage now is I can take the telescope and Astroberry loaded PI out in the field and know that the time is correctly set. Previously unless you had a connection to the internet and hence an NTP time source you had to manually set the clock before starting imaging.

 

I think the ZWO ASIAir and similar boxes already have a DS3231 fitted as they are also Raspberry PI based computers. These boards also work in Arduino devices apparently but I don't have one of those so can't comment.

 

image.png.10c710dd1f37895059b7bf14b52d72a7.png

 

To fit a board you locate it over the GPIO pins on the inside corner with the RTC board pointing inwards, as shown below.

 

image.png.9b064a8cd6943c59611377427d0f4c69.png

 

You now need to configure your Raspberry Pi to recognise and use the board.
Turn on the Raspberry Pi and verify that the board is seen by running sudo i2cdetect -y 1 at the command line. You should see ID #68 show up (the I2C address of the DS3231 Real Time Clock chip):
 

image.png.ce0f78da970b95f949d2b9504001448b.png

 

The RTC module must be loaded by the kernel by running:
sudo modprobe rtc-ds1307

 

Now you need to be running as the super user; type in:
sudo bash

 

and then:
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device

Enter exit 
Check the time on the RTC device using:
sudo hwclock -r
If this is the first time the module has been used, it will report back Jan 1 2000, and you'll need to set the time to the current time.
The easiest way is to connect it up to Ethernet or Wifi. It will automatically set the time from the network. You can check the time using the date command

 

Run sudo hwclock -w to write the system time to the RTC board.
You can then verify it with sudo hwclock -r

 

Then to make the PI automatically load the RTC on reboot there are two files you need to modify

In a terminal window run sudo nano /etc/modules and add rtc-ds1307 at the end of the file like so:

image.png.d6a48879f59f845b85b784083a446914.png

 

WriteOut and Exit nano at this point

 

Next 

sudo nano /etc/rc.local
and add the following lines to the file:
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
sudo hwclock -s
date

Just before the exit 0

 

image.png.0e74787f062984fbeb10fec537309f23.png

 

Again WriteOut and Exit the file

 

The next time you reboot the PI will be using the real time clock as its time source and it will be good to take out into the field for imaging duties.
 

 

  • Like 2
Link to comment
Share on other sites

Thanks that's a good find and one problem solved on my list 🙂. I'm planning to use Astroberry with my SLR lens auto-focuser build. As the autofocus wont be from ZWO I cant use the ASIAIR. I have my Pi, home brew Skywatcher focus motor controller and EQMOD interface all ready. Just need to compile the driver for the PI (I have my Windows ASCOM driver to base it on) and "design" the coupling to the lens focuser and make it mechanically sound.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Welcome to Backyard Astronomy Space - please register to gain access to all of our features

    Once registered you will be able to contribute to this site by submitting your own content or replying to existing content. You will also be able to customise your profile, receive reputation points for submitting content, whilst also communicating with other members via your own private personal messaging inbox. 

     

    This message will be removed once you have signed in.

  • Tell a friend

    Love The Backyard Astronomy Space? Tell a friend!
  • Topics

×
×
  • Create New...