Introduction: RasPiAstroKam (aka PiKam): Overview

This is my first Instructable, so no need to be too kind.

If you haven't heard, the US is going to have a rather impressive eclipse on Aug 21, 2017. Because my house is only going to see some of it, myself and a friend have decided to go view it. And we have telescopes with solar filters and all sorts of good nerdness in our heads. I also have a desk littered with pieces of gear, so that's where this project started.

The objective was to come up with a way to use a Raspberry Pi (was a Zero to start with) to take astronomy pics, aka astrophotography. We have scopes, but didn't really want to try building our own, like the Pi Telescope. The Raspberry Pi Astro Cam has some outdated code (although this was a big inspiration for me, thank you!). I also wanted to make sure this would work with almost any scope, so having it work with an existing eyepiece or as an eyepiece was a requirement. At this time (2017-06-14), I've built it as an eyepiece replacement.

Originally, my intent was to use the Raspberry Pi Zero or Zero W in this project and have them directly on the scope with all other components to one side to keep the weight on the scope down. But, as I started putting things together, I made a change for a couple of reasons.

First, the weight and pull of the HDMI cable for video was notable. If I used my auto-tracking scope, it was a load. and the longer the cord, the heavier it could get. As I was making a PiZ+camera case, this meant it pulled on the mount, the case, and the eyepiece. I was concerned that this was a significant challenge. This would only get worse with the micro USB cabling (one to the PiZ and possibly one from the PiZ to a screen).

Secondly, I couldn't get a long enough Pi Zero Camera Cable to make using the Zero a solid option away from the scope. The Raspberry Pi B does have options for longer camera ribbon cables (2m!) and those are VERY light. Moving the Pi away from the scope also removes the micro USB cables and cuts the weight. This also can give me MUCH more flexibility around the final product. Win win win.

I also wanted this to be as "stand-alone" as I could once completed. That means less hardware whenever I can manage it in the field. So, I tried to remove the needs for keyboard and mouse to run this. In my case, that meant I opted to use the HDMI 5" Display with Touch (similar to this)but mine is the older 2260 model without the mini driver. This also means a cable from the Pi to the screen for HDMI and another for the "touch screen" mouse.

The use of a touch screen meant that I could use the Pixel desktop and make a GUI for my Python code to operate the camera. That felt remarkably practical over trying to run things via a terminal or using external keyboard/mouse/screen for everything in the field.

Step 1: Parts List

Here's what I used:

Hardware

  • 1 x Raspberry Pi Model B (available pretty much everywhere)
  • 1x 16GB (or more!) microSD card (San Disk Class10 for speed. 32GB model from Amazon) - Depending on how much storage you need, go big. For my pics, I took 500 pics and it came in around 1.8GB of space just for those.
  • The case from the microSD card (this was really useful as a camera mount!)
  • 1 x 5" HDMI Backpack Touchscreen Display (800x480) or equivalent. I got mine from MicroCenter, but if I rebuilt this, I would go with the 7" screen or higher resolution
  • 1 x Raspberry Pi Camera Board 2 (Camera v2 8megapixel from Adafruit).
  • 1 x 2 meter Raspberry Pi Camera2 cable (Amazon).
  • 1+ x high-capacity USB battery pack (Adafruit) - I have 2 of these for travel and they are beasts. Just one powered the entire system for 5 hours+ on a single charge (tbh, I haven't run the system continuously long enough to drain it yet)
  • 2 x USB-A to microUSB male/male cables (these are all over my house and likely yours as well, but try to get flexible ones)
  • 1 x Male to Male Coiled HDMI Cable (Amazon)
  • 1 x "storage cup" 1.5" diameter. I bought a pack at Hobby Lobby and pulled the size nearest to what I needed and adapted it to fit in my telescope's eye piece. Keep the cap, by the way, because it's a great protector for the camera.
  • $10 - 1 x ArtBin 10" Quick View Deep Carrying Case (Hobby Lobby) - You can change this for a bigger screen or as needed
  • 4 x #4-40 machine screws (4cm+) with nuts and washers (I used Everbilt ones from Home Depot) for mounting the display. I left them longer than needed so I can place a plexiglass sheet over the screen to protect it from cables and stuff when the case is closed)
  • 4x 1/2"x1.2" wooden spools for standoffs (they were the right size, shape, and came pre-drilled with the holes for mounting from Hobby Lobby)
  • 220 and 400 grit sandpaper (as needed to get your eyepiece size correct because I had to reduce mine from 1 3/16" to fit as a 1 1/4" eyepiece)
  • Various screwdrivers, needle-nose pliers, coins, fire, razor blades, sandpaper, masking tape, flat black spray paint, a bolt/nut/washer combination, some rather small screws and nuts, and a cordless drill.
  • Optional: 1 x "touch screen" stylus - This is a just stylus with a rubberized tip for using on touch screens. My fingers are pretty large for working on the 5" screen at 800x480 resolution. This thing helped. Here's one from Amazon.
  • Optional: 1 x Raspberry Pi Case (Adafruit) to protect it and mount it in my case.
  • Optional: 1 x CanaKit Mini Wireless Keyboard with Touchpad (Amazon). This was really handy for doing any quick changes to things, or just working with the desktop easier. It's an handy option, but wasn't required for the operation of the system, just useful if you wanted to make changes to things like the code.
  • Optional: 1 x microUSB Push On Off Power Switch Cable (Amazon). This was handy to make sure I've cut the power to the system a bit easier than fumbling to get the switch on the battery pack.
  • Optional: 1 telescope solar filter (this was for the 2017 eclipse). I was going to build one from this and use foam core boards for the mounting, but a friend lent me a "real" filter that I used instead. I did use the foam core and filter to make filters for binoculars instead, so the idea did work out rather well.

Software

  • Raspbian with PIXEL: This is a no-brainer for easy to install/use. I worked from the "RASPBIAN JESSIE WITH PIXEL" version and modified from there. I'm more likely to make a significantly smaller version going forward, but this is what I have today. Two notes on this:
    • ALWAYS update the packages in your RasPi projects!!! I ran 'sudo apt-get update -y' immediately after I started my Pi and connected it to the network, and so should you! Yes, it can take a long time to finish, but it's very important!
    • PLEASE, CHANGE THE DEFAULT PASSWORD! Anyone can hack your devices if you don't!
  • Python3 - it's already in Jessie+Pixel
  • PiCamera 1.13 - it's already in Jessie+Pixel, if you run the update
  • PyCharm Community Edition - This is NOT REQUIRED TO RUN on the Pi, but is great if you're working with Python code and testing. I used this on my desktop and moved the code to the Raspberry Pi to debug it. I use a lot of ssh, vi, ftp, etc. during the debug process.
  • Python Libs (not included OOTB)
    • PIP3 - easiest way to install new Python modules. Make sure it's installed in Raspbian with 'sudo apt-get install python3-pip'
    • AppJar: This is what I used to build the UI in the project. 'pip3 install appjar'

Step 2: Step 1: Camera Mounting Case

CAUTION: This project involves fire and sharp objects. ALWAYS be extremely careful, use safety equipment appropriate to your task, like protective eyewear and leather gloves.

This one is all credit to DrGarySullivan. I made a few changes, but he was the inspiration across the board for this project.

Remember that microSD card case? Start with that.

Note that plastic mounts for the microSD card itself will get in our way. We'll remove them in a moment.

First, we need a hole for the camera aperture. I used a big screwdriver (compare it with the camera body on the board to see if it's big enough around) that I heated and put one in the case where I needed it. Then clean up the melted debris around the hole inside and outside the case.

Now, the plastic mounts. If you've tried to size the camera board, you already know those mounts are in the way. Time to remove them. To remove mine, I mounted a razor blade in a pair of pliers and held them them with a rubber band. This is NOT enough grip to leverage against the razor blade. It's just enough to hold it so I didn't drop the blade on myself or anything else. The HEAT in the following step is more important than the blade!! If you are using your strength to get the plastic out, REHEAT! Think "hot knife through butter" not "let's cut down trees with a pair of pliers". And BE CAREFUL.

Using the pliers as a handle, heat the razor blade over an open flame. It won't take too much to get it hot. Use the heated blade to start cutting out the plastic. Remember, heat should do this work. Once you've scraped away most of that mount, the Pi CameraV2 should fit closely (not pinched or crushed) with the case closed and snapped.

To create a slot for the ribbon cable, I replaced the razor blade with a copper penny. It took more heat, but made a very nice slot in the back of the case for the cable. My picture shows the case painted and assembled. Do NOT paint the case yet. Set it aside (without the camera board in it) for now.

Step 3: Step 2: the Eyepiece Fitting

I tried to follow the Pi Astro Cam approach using the pipe piece, but I couldn't find one with the precise diameter that I was comfortable using in my scope. Instead, I used the storage cup.

Here's how:

  • Drill a hole in the bottom of the cup - This must be bigger than the camera aperture hole in the camera case. I used a larger drill bit with my cordless drill and then expanded it with a grinding tip. Note that your initial hole may not be as centered as you like. As you grind gently, you can get the hole much more centered. The grinding is more about heat than force.
  • Mount the cup on a bolt - I needed to reduce the diameter of my cup to fit the scope, so I mounted the cup on a bolt with the bolt shaft going out the BOTTOM of the cup. Use washers here to distribute the pressure of the mounting.
  • Mount the cup in your cordless drill - Several years ago, I had to sand down a LOT of polycarbonate tubing to make some light sabers. Trust me, mounting this in the drill is a great idea.
  • Wearing leather gloves, hole a piece of the 220 grit sandpaper loosely around the cup and run the drill slowly. This may take some practice, but as you learn to deal with the rotation of the drill (and it's direction) you can sand down the cup REALLY accurately. Do NOT go too fast or the cup plastic will heat up and likely curve inward into the cup, particularly at the lip of the opening (which you MUST remove completely). Some curling in is fine, but you'll have to sand it out as you go. The bolt will likely be much tighter as you go, so expect to use some pliers or a wrench to release the cup.
  • Before you dismount the cup from the bolt, test the cup fitting in your telescope. ALWAYS thoroughly clean the cup and bolt with water and then dry BEFORE you test to keep dust out of the body of your scope.
  • Once the cup is starting to fit in the scope, switch to 400 grit sandpaper to keep going down. This will make the piece easier to insert and remove and still do the job of sanding down the size to our needs. All together, I used one sheet of 220 grit and 1/3 of a sheet of 400 grit. YMMV.

After the sanding down, you need to paint the cup BEFORE you start attaching to the camera mounting. Painting the outside will change the size and stickiness of the eyepiece. Using masking tape, carefully cover the outside of the cup barrel completely. If you get find paint on it after you've removed the masking tape, you'll have to use 400 grit sandpaper to remove it. Some notes:

  1. Use FLAT black spray paint. I just wore some nitrile/latex gloves to hold the cup in my hand while I painted the inside.
  2. Use TWO coats and let it dry completely between coats.You're trying to make sure nothing reflects off the walls of the cup into the camera. Two coats should prevent the light from leaking into the plastic and creating more problems. I checked my piece in bright sunlight before I decided it was painted enough. If you see light through the paint ANYWHERE, apply more paint.
  3. Pain the INSIDE of the camera holder as well. You're going to adhere the cup to the outside, so don't introduce paint there as a problem. I simply put masking tape on OUTSIDE side of the side with the camera lens hole and spayed the inside all over. Try to keep paint of the of case's latch too. Use TWO coats here too. You want to keep stray photons at bay.

After everything is DRY, I used plain old SuperGlue to attach the cup to the holder. I manually aligned the hole in the cup around the hole in the holder to keep everything centered. Once EVERYTHING is dry and solid, you're almost ready for the camera.

Step 4: Prep & Mount the PiCamera

Before you mount the camera, you need to remove the lens. The telescope will replace the lens. Removing this lens was a bit delicate because the "grip" is very small. I used small needle-nosed pliers to carefully remove mine. The lens simply unscrews ("...lefty loosey") and can be set aside.

Be cautious that you don't over-torgue the camera body or zap the camera with some static discharge. Use an anti-static bag to hold it, whenever possible. Over time, I've had 3 PiCamera's and one has gone bad (not from this project), but Raspbian reports it like the camera is disabled on the system.

After you've removed the lens, you can attach the 2 meter cable to the camera board (unlock the ribbon cable lock, slip in the cable with the contacts facing the BOARD) and relock it. Personally, it was easier to feed the cable through the slot in the holder BEFORE attaching the cable.

Slip the camera into the holder and try to keep it square to the holder. This will keep your images squared as well. Once it is well-situated, close and lock the holder. The camera board should NOT have too much pressure on it as this can distort the images and even break it. Go for "snug" not "compressed".

Step 5: Some Assembly Required

Okay, more than some, but it's really pretty basic. I didn't capture as many pics (well, I did, but that phone suffered a fatal accident and I lost them before I backed them up) of the exact process, but here's some that should help.

First, I started playing with the positions of things in the case. Based on the layout of the cables and size of connectors, I opted to mount the display in the bottom left of the case (leaving the right side open for the HDMI and power/control connections).

To size everything, I set the screen in the box and marked the holes with a Sharpie pen. I removed the screen from the box. I wanted to do the most "difficult" hole first because I could move the others much easier. In my case, it was one of the two on the front of the box (bottom of the screen) where there's a rounded embellishment in the art case.

Taking the small screwdriver that BARELY (if you're not sure, go SMALLER than bigger with the whatever you use here) did NOT fit in the mounting hole, I used an open flame from my stove to head the screwdriver and pushed it through the plastic. A few reheats and re-pushes on the same hole gave me a very clean opening. I used a fingernail to flick the melted excess away.

I put the screen back in the case and used a second screwdriver to simulate the "bolt" and line up the screen in the box. Reheating my first screwdriver, I then punched the second hole in the opposite corner, cleaned it up a bit, put in another small "holder" screwdriver, and moved on to the third and fourth holes.

Using small bolts (machine threaded) with small washers, I mounted the standoffs upward into the box. Mine were: bolt, washer, case, wooden spool, washer, nut (I didn't want to need to torque the display), display, washer, nut. Repeat this 3 more times and the screen is mounted.

I used a similar process to mount the Raspberry Pi in its small case to the inside right lid of the art case. The orientation let me connect the cables to the LEFT and BOTTOM of the Pi so they are compatible with the display and battery. I did not use the OOTB "bolts" for the Pi case and instead replaced the provided nylon ones with some small metal screws and nuts. Mine were a bit longer and allowed me to mount the case to the inside lid of the art supply box.

Lastly, I mounted the switch inside the top lid of the art case by punching two bigger holes and holding the switch with wire tires. When all done, I can get everything, including the wireless keyboard, inside the case and close it without putting pressure on the display connectors, the screen or anything. In the labeled pic, I have the cam at the top of the case, but that's not how I package it when I close it all up.

Step 6: Software Setup

Now that you have the hardware stuff done, you need to enable it all.

At a high level, this means:

  • Download and install Raspbian:
    • This is not covered here, but it's VERY easy.
    • CHANGE THE DEFAULT PASSWORD!!! Don't let someone else take over your system.
    • Attach the Raspberry to your wireless network.
    • Update all the packages. This can be time consuming, but do it often. In order, the following commands will get the current list of packages, upgrade and install them without making you enter too many YES prompts, clean up the list of packages, and then remove stuff that's not being used.
      • sudo apt-get update
      • sudo apt-get upgrade -y
      • sudo apt-get autoclean -y
      • sudo apt-get autoremove -y
  • Set Raspbian to recognize the PiCamera is attached (on the Raspbian desktop, it's under Preferences > Raspberry Pi Configuration.
  • Install Python3 and AppJar
    • sudo apt-get install python3
    • sudo apt-get install python3-pip3
    • pip3 install appjar
  • Copy the piKam code to the Raspberry Pi
    • Lots of possible ways to do this:
      • SSH
        • SSH terminal to raspberrypi
        • cd ~/Desktop
        • vi piKam
        • i (insert)
        • paste code into terminal
        • hit Escape key
        • shift-ZZ (save and exit)
      • Type it in manually
      • FTP transfer
      • Shut down the Pi, remove the microUSB card, mount in another computer and copy the file to the drive...
      • You get the idea, I hope.
  • Make the script executable
    • chmod +x ~/Desktop/piKam

  • Run the code (this MUST be done on the Pi itself, not in the SSH terminal because the UI will run on the Pi and the PiCamera "previews" run directly on the hardware. That also means that previews will NOT work with VNC or other remote desktop viewing tools.
    • In Raspian desktop, double-click the file and Execute / Execute in terminal to run it.

Next up is the code itself.

I tried to make the console pretty simple. There are a LOT of options available with the PiCamera library, and I'm not a photographer, so my usage is rather basic. The "preview" feature of the PiCamera was interesting. I finally started to move it to its own thread so I might "cancel" out of it, but I didn't complete it.

When it takes pictures, the preview will open to capture some light levels for a second before it starts taking pics. Once you click to take a picture(s), the UI will be non-responsive until it completes. I didn't yet move the picture taking to a separate thread. I may update this in the future.

Step 7: PiKam UI

This was intended to be used from the touchscreen, so I wanted as few options and buttons as possible. I really wanted to just be able to capture eclipse pictures, not create a full photo suite for Raspberry.

Currently:

  1. The code will always attempt to

  2. Cancel - Closes the UI

  3. Preview - Previews cannot be interrupted; however, the preview option will now run in a separate thread so the UI is still "responsive". This is not for the preview in the picture taking mode which still "blocks" the UI thread. So, if you click 5 minute preview (600 seconds) and then click the Cancel button behind the preview, the app will close, but the preview will still run for 5 minutes.

  4. Stop Preview does not work...yet.
  5. Capture 1 - this takes a single pic. By default, the code will preview for 4 seconds (awb_sleep) to try to get the light levels and "automatic white balance" set before it takes the picture. Preview is run for each pic you take.
  6. Capture 12 at 5s - "Capture 12 pictures with approximately 5 seconds between each". Runs for 1 minute and cannot be interrupted (yet), but uses a single "preview" session for the 12 images. This was what I used during the eclipse.
  7. Capture 6 at 20s - "Capture 6 pictures with approximately 20 seconds between each". Runs for 2 minutes and cannot be interrupted (yet), but uses a single "preview" session for the 6 images. If my auto-tracking on the telescope hadn't been recently damaged, this was my target for the early and middle stages of the eclipse. I wanted more pics as we neared totality.

And the code is attached.

Attachments

Step 8: Results

It turned out really well for my purposes. We drove to be in totality and had a great viewing, truly IDEAL.

I loaded a series of 12 pics taken with the 5 second interval to give you an idea of how fast the sun and moon transit the view through the scope. All told, that's one minute in a stationary scope.

Step 9: Lessons Learned

What did I learn or what would I do differently next time:

  1. I still don't like writing UI code. I suspect that at this point in my live I never will, but the Python AppJar really is very easy with which to get started.
  2. I should have spent more time getting the threading done for the previews and camera pics. I didn't begin this until far too late, but what I have is at least operable.
  3. The display was a far too dim for full sunlight. We contrived some shades to cover it so I could run the scope, but this is something of which to be aware. At night, the display is easily bright enough for running.
  4. Battery was more than enough for my needs. No issues with just the one battery for this project at all.
  5. I'm DEFINITELY fixing this motorized base or replacing/upgrading my scope. Please, don't warn my wife. An auto-tracking mount, even a basic one, would have REALLY been great for this kind of event. Having the options to set exposure intervals would give really consistent images for such an event.
  6. Use a 7 inch display. Everyone LOVED being able to see the screen.
  7. If you have an HDMI display handy (like a monitor or TV), use that and bring the wireless keyboard to run everything. That's one reason I got the coiled longer HDMI cable (flexible in the carrying case, but able to attach to a bigger screen monitor).
  8. Spend more time understanding the photographic capabilities of the picamera module. This will help me look into splitting the feeds and doing other fun stuff with the code in the future.

Two other topics I'm considering:

  • Reusing an existing eyepiece barrel for the camera mount for the inside thread for filters. I have a number of filters, and being to apply them to the PiKam would be useful, particularly for education, I think.
  • Doing a completely different camera mounting OVER an eyepiece (basically the camera replaces our eyes). I toyed with this a bit, but will likely revisit it in the future. Big advantage here is that you don't have to refocus for the camera versus for a human.

This was really a lot of fun, so I hope you enjoyed my first instructable.

Thanks!

First Time Author Contest

Participated in the
First Time Author Contest