Astronomical Imaging Intervalometer
Updated - 13th June 2018
I have been imaging noctilucent clouds (NLC) for some time but have always had a problem taking images automatically at set intervals so they can be converted into a movie later. My normal mode of imaging NLC is to set the lens to the lowest f stop and allow the camera auto exposure to vary the exposure time as the sky gets darker. I also wanted to use the mirror lock-up facility on my DSLR camera to allow the vibrations to die down before the shutter is opened. After some problems with my RaspberryPi I decided to build a serial port interface and control the camera from the astronomical programme IRIS. This worked but had problems trying to keep a constant interval - the programme allows you to set a delay between images but this is from the end of the first image to the start of the next. Details of this interface can be seen in my presentation here (pdf). The connection cable is described in the last slide. This is used both with the serial port interface and with my RaspberryPi intervalometer.
Having terminated the cable in a 15 way D sub-miniature connector (as a VGA monitor connection) it was easy to connect a short cable to the PiFace terminating in the 15 way connector. To reduce the likelihood of the interface cable being plugged into the VGA socket on the computer I put the female connector (i.e. the same as on a computer) on the connection lead.
The intervalometer has been designed for use on a Canon 10D to 40D series DSLR cameras. It should work on other cameras but the connections will be different.
The hardware is based on a standard RaspberryPi & PiFace interface fitted in a case from Farnell CPC but this is only for protection, I brought a red one but the light from the red LEDs on the PiFace show through the case - a black case might be more appealing.
There are three wires from the camera, a ground wire, a focus wire and the shutter wire. The focus wire needs to be connected to the ground first - this simulates the 'half press' of the shutter button. Then the shutter wire needs to be connected to the ground as well.
If mirror lockup is used this sequence has to be repeated twice with a gap between to allow the vibrations due to the mirror lifting to die down.
I decided not to use the relays to drive the camera due to the clicking noise. The open-collector outputs on the PiFace are perfectly capable of driving a Canon Camera ( I have not tried others). You need to be careful in connecting the camera - while the output pins are 'Open Collector' and thus passive some of the pins on the PiFace have +5V on them and accidently connecting this to the camera could damage the camera. One thing to be very careful is that the left hand connection on the Output Port ( looking from where the wires are inserted) has +5V on it so don't connect the camera ground to here ! It is not very well labeled on the board - either you have to deduce this from the diagram on page 8 of the documentation. The most convenient 0V (ground) pin is on the left of the three pins marked 'Power Input' again the other pins have +5V on them so ensure you get the correct one. There is also a ground pin on the right hand side of the input block.
The other thing to be aware of is that the board labels the outputs as 0 to 7, when writing to them in Python they appear as outputs 1 to 8 ! NB the python GPIO routines have been modified to correct this so they now refer to the ports as 0 to 7. The focus wire has to be connected to output 2 and the shutter to output 3. If in doubt run the software and check which LEDs light up before connecting the camera.
If you decide to use the relays to operate the camera the two common contacts of the relays need to be connected together and to the ground wire from the camera. The focus wire is then connected to the Normally Open (NO) contact of the first relay and the shutter wire should be connected to the NO contact of the second relay. The software will need modifying so the focus commands are written to Pin 1 and the shutter commands to pin 2. Jumpers JP5 & JP6 must be installed as explained on the data sheet.
The data sheet for the PiFace is located here, this gives code examples as well.
Two of the input switches on the PiFace are used to control operation of the programme. The first switch starts the intervalometer running, the second stops the programme at the end of the sequence. This ensures that the camera is not left with the mirror locked up which is not only confusing when you try to use the camera but more importantly leaves the CCD subject to bright sunlight if the Sun shines into the lens.
Software description & function
As described in the presentation above I initially had problems with the RaspberryPi freezing when it lost the network connection. This was not much help as I intended to use the intervalometer away from a network and also I usually switch my network off at night when the NLC images are being taken. However running a sudo apt-get update followed by sudo apt-get upgrade seems to have solved this problem and the Pi works without a network connection quite happily.
The present software which is written in Python works but is quite crude in that you have to edit the code to change the values of the interval, the focus & shutter times.
The major problem I had in writing the code was that Python is a single threaded language with no provision for interrupts. As a result if the sleep function is used for the various time intervals there is no way to read the halt switch or to flash an LED to show that the programme is still working.
To get round this I have defined a snooze function which as far as the rest of the programme is concerned does the same as the sleep function. However the snooze function in fact sleeps for 0.5 sec and then wakes up and changes the state of the running LED as well as checking the state of the halt switch. The number of times the 0.5 sec sleep is called depends on the parameter (in seconds) passed to the sleep function. As a result of the way this function works only time intervals that are multiples of 0.5 secs will work correctly. Shorter times will be rounded up to the next 0.5 sec interval. The function returns the value of 1 to the main programme if the halt switch has been pressed and 0 otherwise. This is used to increment the variable 'exitatend' which is checked at the end of the main programme loop. If it is greater than 0 the programme halts. The variable 'exitatend' is incremented rather than set to the return value as the snooze function can be called again after the halt button is pressed and released. In this case snooze will return 0 which would overwrite a previous halt request.
LED 8 will flash every second while the programme is running. LED 6 should illuminate when button 2 the halt button is pressed to confirm that the programme will be stopping at the end of the sequence. LED3 & LED4 illuminate when the focus wire and the shutter wires are grounded (active) respectively. After the programme is halted it needs to be restarted to run again - pressing button 1 the start button will have no effect.
A variable PTime is used to allow for the time the programme is actually running rather than sleeping. This has been set to a nominal 0.5 seconds, you need to check the actual timings on your setup if the interval time is critical. You will not get great precision as the operating system is running other things in the background that will effect the time taken.
It should be noted that the way the programme is structured the camera needs to be in 'Mirror Lockup' mode otherwise you will end up with two exposures for each interval. Also while there is a time allowed for the camera to focus if focus is not achieved you will not get an image. This does not matter for astronomical purposes as I normally set the lens for manual focus.
The programme prints the time of and sequence number of each image on the monitor. The times should be correct if the RaspberryPi is connected to the internet when started but since the Pi does not have a Real Time Clock (RTC) chip it loads the time it saves the time it was last switched off and uses this as the starting time until updated from the internet. Thus the time will be wrong if not connected to the internet at startup. However time gives a good way of checking if the PTime variable above is correct. My Pi drifts by about 1 sec every 3 to 4 images so really PTime needs to be 1/4 to 1/3 seconds shorter but since PTime only works in 0.5 second steps the value of 5 seconds is the closest to the correct value.
The Python code currently version V3-004 14 May 2018 is available on the link. The Python script now automatically downloads the images to the Raspberry Pi after the exposures have finished see the changes to my Raspberry Pi to Camera Download page for details. The Python script file needs to be saved into the appropriate directory in your RaspberryPi before running it.
This version logs the exposures to a file on the RaspberryPi named for the current date and time as follows YYYYMMDD-HHMMSS.Log . This enables you to see how many exposures were taken and at what time. This is a text file that can be opened in any editor that understands Linux line endings. This version also corrects the GPIO addressing changes mentioned above
Downloading data from the camera to Windows PC
I have normally downloaded the data from the camera by removing the CF Memory card and plugging it into my PC to save it to the network. I was not really happy with this as the Memory Card connector is only specified for a very limited number of insertions and it is difficult to get to. The camera is too far from my PC for a USB lead to work so I though I would try connecting the camera to the RaspberryPi via a USB cable. After some research I discovered that if I loaded GPhoto2 onto the RasPi as well as samba I am able to access the images stored on the Camera from the RasPi using the RasPi file manager. I then transfer the images to a folder on the RasPi. This is not very fast - around 20 secs per image. When the files are copied on the RasPi I can then access the folder containing the images from my Windows PC as samba makes the folders available on a windows network. It is then easy to copy the images onto my network for viewing.
Attempts to access the camera from my PC via the RasPi have not been successful. I have been unable to find where the USB camera is mounted which is required for access from samba. My suspicion is that the RasPi file manager and or Gphoto2 hijacks the mounting and does not mount it in a place visible to the user which accounts for the odd path to the camera in the file manager. Investigations continue !
New 13th June 2018
Showing Sun Altitude (and Azimuth) in the display & logfile
While running my intervalometer to record NLC I normally run my Excel Spreadsheet that shows the current Altitude and Azimuth of the Sun. I normally use this to decide when the Sun is greater than 12 degrees below the horizon as the chance of seeing NLC fall at this altitude, particularly as my Northern horizon is not that good.
As the programme that operates the intervalometer is written in Python(2.7) I wondered if I could calculate the Sun's altitude using the Raspberry Pi and then show this on the screen so I could see if it was time to end observation.
A bit of research showed that several programmes can be used to calculate the Suns position. I decided to use PyEphem on the basis that it can be used for other astro projects and also I managed to locate a copy that could be compiled and loaded onto a Raspberry Pi.
PyEphem is not available using the normal apt-get or package manager one has to resort to using pip which itself may need to be installed on your Pi as it is not part of the normal distribution. The following are the packages I installed:
install pip if required
sudo apt-get install python-dev
sudo pip install numpy
sudo pip install pyephem --index-url=https://pypi.python.org/simple/
Note: the line above is required as the connection to the source of pyephem requires a https secure connection and pip normally uses http. If you don't use this command line then you will get an error similar to the following:
The new version of my programme can be found on the following link V4-001 13 June 2018. Note for security I have edited my latitude, longitude and altitude in the file. You will need to edit the file with your own observing location and altitude before the programme will run.
I have formatted the Altitude and Azimuth to one decimal place. One thing that still needs to be done is to format the number of seconds in the display & logfile. At present the time is shown to one microsecond, that level of resolution is not needed and the times are not accurate to that level.
© John Murrell 2018
Clicking on the Home logo will return you to the home page