Introduction: Touchscreen Display and Battery for the PiKon Telescope / Raspberry Pi

About: I work as an I.T. Support Technician for my 9 to 5 but my true passion is designing, engineering and making, or just generally fiddling with things.

In 2014, Mark Wrigley of Alternative Photonics along with Andy King, a Physics and Astronomy research associate at the University of Sheffield, created the PiKon 3d printed telescope. Based on Newton's reflecting telescope design it uses a Raspberry Pi and the PiCamera module, with the camera mounted directly in front of the mirror.

I've always had a curiosity for astronomy, but was never keen enough to invest any money in purchasing the necessary equipment. But when the PiKon project featured in the news it was something that really captured my imagination. A year later in 2015, the PiKon turned to crowdfunding, giving everyone the opportunity to get their hands on one. Be it fully assembled or in a kit form that you can 3d print and assemble yourself, I wasted no time in reserving my perk and was eager to start my build.

My kit arrived in early 2016 and I promptly printed my parts and assembled it. To operate the telescope you use the Raspberry Pi, all of your interactions with the telescope are via the Pi command line interface. This requires you to have access to a TV/monitor and a keyboard, as well as a power source for the Pi and the monitor. This is not a problem if you are operating your PiKon indoors through a window or even if you are out in your back garden, but what if you want to take your PiKon on a field trip to a remote location?

To solve this problem I set about designing and making a small, lightweight and compact all-in-one unit that not only provides power to the Pi, but also includes a display, input controls and a user friendly interface. The result is the TED-VDU, it incorporates the following features:

  • 3d Printed enclosure
  • 2.8" Resistive touchscreen TFT display
  • 5200mAh four cell lithium-ion rechargeable battery (provides over 5 hours runtime per charge)
  • A single cable to link the VDU to the PiKon (15-way HD15 cable)
  • Optional 4x programmable (GPIO) buttons
  • Optional LED lights
  • Based on the Cam.py point-and-shoot digital camera user interface

While I designed this for the purpose of adding simple functionality and a friendly UI to my PiKon telescope, the TED-VDU can be used for any Raspberry Pi project that would benefit from an external touchscreen display and battery power pack.

If you don't require a battery for your VDU I have produced a 'Lite' version of this Instructable, it provides the same touchscreen display and user interface but without the battery and the buttons. It's an ideal alternative for anyone who wants the VDU but has their own power source / battery pack for the Raspberry Pi.

Mark Wrigley has published an Instructable for the PiKon Telescope, you can find it here

Step 1: The PiKon Telescope

This instructable assumes that you either already have a working PiKon telescope, or you will be assembling your PiKon by following the instructions provided with the kit. If you don't have a kit yet they are still available to order via the Indiegogo crowdfunding site (link below). Some of the kits include a Raspberry Pi and the camera module, but you can purchase the Pi and the camera separately if you prefer. To build and test your TED-VDU you only need a Raspberry Pi with the Pi Camera module.

For the PiKon to integrate nicely with the TED-VDU, you will need to 3d print a modified version of the PiKon Pi mount. This is to incorporate the HD15 cable connector, the STL file is included with this instructable and is the only part required that differs from the original PiKon kit. I have also included the STL file for a modified version of the PiKon focus knob, I re-designed it to include some grips.

Step 2: Parts, Components and Tools

I have included two STL files for the enclosure, one with and one without the programmable (GPIO) buttons. They are not used in this project as everything is operated via the touchscreen, but they could come in handy if you are using the VDU for a different project. I also used some LED illuminated buttons, these can come in handy when using the PiKon telescope at night as they make a good flash light.

To build the VDU you will need the following tools and equipment:

  • Soldering Iron
  • Wire cutters
  • Wire strippers
  • Pliers (small)
  • Phillips-head screwdriver
  • Multi-meter
  • Hot-melt glue gun
  • Super-glue
  • Round file

You will need the following parts and components:

If you are adding the optional switches to the VDU, you will also need the following:

Step 3: Mount the PiTFT in the Enclosure

Before we can use the 3d printed enclosure you will need to remove and clean-up any support material left over from the printing process. This is typically located around the D-Sub connector cut-out and the square DC jack cut-out. There is also a small cut-out in one of the corners, be sure to remove the support material from this as well or the PiTFT's PCB won't fit properly.

To mount the PiTFT in the enclosure we will be using three of the M2 nuts, take care and follow the guidance below:

  1. Place the M2 nut into the hex cut out, being careful to align the rotation of the nut with the hex shape.
  2. Apply sufficient pressure to push the nut into place, the hex shape is designed to be a snug fit to help hold the nut firmly.
  3. If you need to remove the nut for any reason, you can screw in a M2 screw a couple of millimetres and use it to pull out the nut.
  4. Once you are happy that the nuts are properly seated you will need to use a couple of drops of superglue on each nut to secure it in place. Apply the glue around the outside edges of the nut, taking care not to spill any glue into the thread as you don't want to risk blocking it.

With the M2 nuts glued in place it's now time to test fit the PiTFT screen. The screen should fit snugly, and finish near enough flush to the front face of the enclosure. You may need to remove the protective film from the screen during this process as it can get in the way, but be sure to re-attach it to the screen afterwards to prevent scratching the surface.

If for any reason the screen won't quite fit in all the way properly, you can use the back edge of a fine flat-blade screw driver to remove a thin layer of plastic material from around the side frame of the enclosure.

Once you are happy with the fit of the PiTFT screen, it is secured in place using the M2 screws. The ideal screw length is 4mm though these are not easy to find, anything longer than this will require washers to be used to pack out the screw head, reducing the length that drives through the nut. In my case I used 6mm M2 screws with 4x washers on each screw.

If you are not adding the optional buttons, you can skip the next step and go ahead with securing the screws as above, however if you are adding the optional buttons, you need to follow the next step before securing the screen with the screws.

Step 4: Adding the Four Programmable Buttons (Optional)

If you are not adding the optional buttons you can skip this step and proceed to step 5.

The optional buttons consist of four programmable push buttons that are wired to GPIO pins 18, 22, 23 and 27/21 (GPIO pin 21 was revised to pin 27 on later Pi board revisions). These pins are brought out on the PiTFT PCB itself so we will be utilising these when soldering our wires on.

Prep the wires as per the guidelines below:

  1. Cut 4x pairs of equal length pieces of wire (approx. 5-6 inches long). I'd suggest using a wire colour other than red or black to avoid any confusion with the +5v and ground wiring later.
  2. Strip and prep the cable ends by twisting the strands and tinning them with a little solder.
  3. I added heat-shrink sleeve to the four pairs of wires but this is optional, you can just twist the pairs together.
  4. Push the wires through the holes on the back of the PiTFT and solder on the front face of the screen. Take care not to touch any part of the screen with the tip or shoulder of the iron! Polarity is not important at this stage so wire the pairs any way round.
  5. Once the soldering is complete, visually inspect the solder joints and check you are happy with them.
  6. Secure the PiTFT in place with the M2 screws, remembering to pack them out with washers if the screws are more than 4mm in length.

With the PiTFT secured in place and the wires prepped, you are now ready to start with the switches. You may need to use a round file to make the holes large enough, so test fit the switches and file the enclosure holes as necessary.

Once you are happy with the fit of the switches, remove them all again. I suggest you do as much of the soldering as possible away from the 3d printed enclosure as the heat from the iron can easily deform the plastic if held too close for too long. Take note of how the switches fit to the enclosure panel, for example my illuminating switches push-fit from the front in, whereas the other two are fitted from the back out, so with this in mind I fed the three pairs of wires for the illuminating switches out through the holes.

With those three pairs now out of the way solder the momentary function SP-NO push button switch to pin #23 on the PiTFT (indicated by the yellow cable in the image). This switch is separated from the other three in the layout of the enclosure as I intended on it being used as a special function button (i.e. switching the TFT backlight off/on or to act as a shutdown button).

The three remaining illuminating switches can now be soldered to the wires linking to pins 18, 22 and 27/21 of the PiTFT. Note that if like me you are also using illuminating switches, you will need to solder the power cables to these switches too. Prep 3x pairs of cables in the same way as you did previously, I'd suggest using red and black wires for this task, taking extra care to identify the cathode and anode of the LED's. This information is usually found in the datasheet for your chosen switch if it is not indicated on the switch itself. In the case of my switches, the LED's cathode is indicated by a notch in the body.

The LED's are switched on and off via a SPST on/off function push button switch. My switch lights have a forward voltage of 3.3v, a current of 20mA and there is a 5.0v input coming from the power rail, so I need to use 100Ω resistors in my circuit. If you're not sure how to calculate the correct resistor values for your LED's, here is a handy online calculation wizard. I have included a wiring diagram for the switch circuits to help you get everything hooked up and working properly. Once everything is wired, install the switches in the enclosure. Note that the power rail indicated in the diagram is covered in the next step.

Step 5: The Power Circuit

The power circuit consists of the following items:

  • Ansmann 7.4v Lithium-Ion Rechargeable Battery 5200mAh
  • Toggle Switch SPDT (on/on function panel mount)
  • 2.5mm Straight surface mount DC power socket
  • Recom Switching Regulator (32v Input, 5v Output, 1A)
  • 22μF 10v dc Aluminium Electrolytic Capacitor
  • 220μF 6.3 V dc Aluminium Polymer Capacitor
  • Schottky Diode, 40v 1A
  • Single sided veroboard / stripboard

It is wired as per the wiring diagram provided, as always when using stripboard be sure to break the tracks wherever appropriate and inspect for possible shorts before applying power to the circuit. Refer to the voltage regulators datasheet to determine which pins are +Vin, ground and +Vout. When using polarised capacitors check the polarity before soldering in place.

As space inside the enclosure is limited the circuit has been divided across three pieces of stripboard, each cut to the exact size required. This allows more flexible placement within the enclosure itself, ensuring that everything will fit. If you are assembling your VDU without the optional buttons then you should have a lot more space to get everything in comfortably. Try to keep the wires linking the different boards as short as possible, a couple of inches should be sufficient.

Once the circuits have been assembled as above, everything is powered by soldering the +5v and Ground wires to the power rail.

Finally the toggle switch can be fitted to the enclosure. Panel mount switches typically have a nut that screws to the thread on the body. The DC jack I used is a surface mount one, so I hot-melt glued this into place.

The toggle switch is the master power switch, it will switch between On and Off/Recharge. When in the off position you can attach the battery charger to recharge the battery, the charge status is indicated on the charger itself.

Note that the VDU cannot be powered directly from the mains power supply, the charger is isolated to protect the main circuit.

Step 6: Breaking Out the Pi GPIO Headers to the HD-15 Connectors

This step is probably the most tedious of all the steps, breaking out the GPIO header pins and wiring them to the HD-15 connector. If you are using the optional GPIO buttons, all 15 pins on the HD-15 connector are wired, if you are not using the buttons then HD-15 pins 5, 6, 7 and 8 can be ignored.

You will be breaking out two flat ribbon header cables into HD-15 connectors, one for the VDU/PiTFT side, the other for the RaspberryPi/PiKon side, the VDU and the PiKon are then linked together via a HD15 cable.

To wire the VDU / PiTFT GPIO header to the HD-15 connector, follow these guidelines:

  1. Take the 26p to 26p GPIO header ribbon cable and cut the IDC connector from one end.
  2. Divide the individual cores, taking care not to damage the insulation.
  3. Cut the redundant cable cores.
    • Only pins 2, 4, 6, 9, 12, 13, 15, 16, 18, 19, 21, 22, 23, 24 and 26 are required.
  4. Trim the remaining cables to the desired length (with the IDC connector inserted into the PiTFT the cables need to comfortably reach the D-SUB HD-15 connector cut-out on the enclosure).
  5. Strip approximately 3mm of the cable insulation and twist the cable strands, then lightly tin with solder
  6. Solder each cable to the HD-15 connector pins in turn, as per the wiring diagrams provided (take care not to short any pins and try not to have any excess wire exposed from the insulation).
  7. All pins are wired directly from the GPIO header to the HD-15 connector with the exception of +5v and ground (pins 2, 4, 6 and 9 on the GPIO, pins 1, 2, 3 and 4 on the HD-15), these are wired to the power rail instead.
  8. Once all the pins have been soldered, visually inspect for any potential problems then test for shorts with a multi-meter. Make sure the GPIO header is not connected to the PiTFT as this may produce false-positives.

To wire the Raspberry Pi / PiKon GPIO header to the HD-15 connector, follow these guidelines:

The same steps as above apply, with the exception of a few minor differences.

  1. If you are using an A+ or B+ model Pi with a 40 pin header you will either need to source a 26p to 40p cable, or simply take a 40p cable and cut away the redundant 14 cores.
  2. Before soldering the ribbon cable to the HD-15 connector you need to make sure you feed the cable through the slot in the Pi Mount top cover.
  3. Trim the ribbon cable to the appropriate length, try to avoid having unnecessary excess.
  4. There is no need to divide the individual cable cores beyond a couple of inches as you want the ribbon cable to remain mostly intact, any divided cable should remain within the enclosure.
  5. Cut the redundant cable cores up to the point where the cables have been divided.
  6. Strip approximately 3mm of the cable insulation and twist the cable strands, then lightly tin with solder
  7. Solder each cable to the HD-15 connector pins in turn, as per the wiring diagrams provided (take care not to short any pins and try not to have any excess wire exposed from the insulation).
  8. All pins are wired directly from the GPIO header to the HD-15 connector (see the note below about powering the Pi via the GPIO header pins)
  9. Once all pins have been soldered, visually inspect for any potential problems then test for shorts with a multi-meter. Make sure the GPIO header is not connected to the Pi as this may produce false-positives.

It is worth noting that this circuit powers the Raspberry Pi directly via the 5v power rail on the GPIO header, the recommended method of powering the Pi is via the micro-usb port. Powering it via the 5v rail bypasses the built-in circuit protection, but I have designed it this way to ensure that no additional cabling or connectors are required. If you would prefer to power the Pi via the usb port you can wire a micro-usb cable to pins 1-4 of the HD-15 connector, ignoring pins 2, 4, 6 and 9 on the GPIO header cable. Simply drill a hole in the side of the PiKon Pi Mount and plug the usb connector into the usb port on the Pi.

To secure the HD-15 D-Sub connectors to the enclosures, M2 screws with washers and nuts are used. Hot-melt glue is applied around the connector pins to act as a strain relief.

Step 7: Testing, Finishing Touches and Summary

Before you complete the assembly and secure the cover and back panel, you want to double check all of your connections and wiring, I'd suggest you do the following:

  1. Visually inspect the circuits, double check that they match the wiring diagrams.
  2. Use a multi-meter to check for any unexpected shorts.
  3. Power-on the VDU unit with the PiTFT header cable detached, using the multi-meter check that the power rail is outputting the correct voltage (5v).
  4. If you opted to install the illuminating LED buttons, test them.
  5. Switch off the VDU unit, then connect the PiTFT header cable. Switch the power on again, the PiTFT should come on with a plain white image on the display.
  6. Switch off the VDU unit, then connect the Pi/PiKon via the HD-15 cable.
    • See the note below regarding HD-15 cables before proceeding
  7. Switch the power on again, the Raspberry Pi should come on. You will need a HDMI cable connected to see the display as the PiTFT will not work correctly until the Raspbian kernel has been updated.

If all the above passes without a hitch, you are ready to apply some finishing touches, then secure the cover and back panel to the VDU and the PiMount enclosures.

To make sure the battery pack is safe and secure I used single sided self-adhesive PVC foam tape. You may need to build it up with more than one layer in some areas, this will help keep the battery safe and secure and also prevents any rattling when the VDU is moved around. Once you are satisfied with the fit of the battery and all the cables and components, you can secure the back panel. There are mounting holes included in the enclosure design, you can either use M1.2 self-tapping screws or simply secure it with hot-melt glue. The top cover of the PiMount is also glued on.

Important note regarding HD-15 / VGA / SVGA cables: HD-15 cables are commonly used for VGA monitors and often with these cables not all the pins are wired, many of them are wired to ground. As the PiKon VDU utilises a minimum of 11 pins (15 if using the optional GPIO buttons) you need to take care when selecting an appropriate HD-15 cable. If you plan on using a HD-15 VGA cable that you already have, I strongly suggest you use a multi-meter to verify if it is an all-pins wired cable. Using a cable with many of the pins bound to ground can short the GPIO pins and potentially damage the Pi and/or the PiTFT.

If you need to purchase an HD-15 cable that is suitable for the VDU, you can purchase one from Cabling4Less. This cable is perfect if you don't intend on installing/using the optional GPIO buttons. Although this cable is listed as "all pins wired" three of the pins utilised for the optional GPIO buttons are bound together for ground.

If you want to use the optional GPIO buttons you will need to source a truly all-pins wired cable or alternatively make your own.

To sum-up what we have covered in this Instructable so far:

  • We briefly covered the origins of the PiKon Telescope and the VDU project.
  • Listed the required tools, parts and components
  • Mounted the PiTFT to the 3d printed enclosure
  • Added the optional GPIO programmable buttons
  • Built the power distribution circuit
  • Broke out the GPIO header to the HD-15 connectors
  • Performed some basic tests and inspections
  • Applied the finishing touches and secured the cover and back panel

With the hardware all taken care of that only leaves one final step, setting up the software on the Raspberry Pi.

Step 8: Raspberry Pi Software Setup

Before you can start using your newly assembled VDU/PiTFT you need to setup your Pi to enable the kernel support. Adafruit have a set of step-by-step DIY installer instructions as well as a ready to go Raspbian image pre-loaded with the kernel, links to these are provided below:

Download the Jessie-based PiTFT image for Pi1 and Pi2 (September 24, 2015) from Adafruit

Download the Wheezy-based PiTFT Image for Pi1 and Pi2 (September 9, 2015) from Adafruit

DIY installer instructions on Adafruit

Once you have installed the kernel and configured the Raspberry Pi as instructed above, you should now have a working PiTFT and touchscreen.

By default the Pi Camera is controlled using the command line interface in terminal. To make the PiKon more user friendly I wanted more of a point-and-click approach to the UI. To achieve this we'll be using the Cam.py program from the "DIY WiFi Raspberry Pi Touchscreen Camera" project. This provide an easy-to-use UI, as well as support for DropBox and extra features such as adding visual effects to your photos.

If you are using the Cam.py program mentioned above or you plan on creating your own UI using PyGame, you may need to downgrade the SDL on your Raspian OS. There are some incompatibilities when using SDL 2.x and SDL 1.2.15-10 with a touchscreen. To check which SDL version you are running type the following command into a Raspberry Pi terminal:

dpkg -l | grep libsdl

The following value needs to be returned:

ii  libsdl1.2debian:armhf      1.2.15-5+rpi1      armhf      Simple DirectMedia Layer

If you have a newer version you need to correct this by downgrading your SDL version, follow the steps below or see the article on the Adafruit forum for more info:

Create/Edit a new file with:

sudo nano installsdl.sh

Paste in the following text:

#enable wheezy package sources
echo "deb http://archive.raspbian.org/raspbian wheezy main
" > /etc/apt/sources.list.d/wheezy.list
#set stable as default package source (currently jessie)
echo "APT::Default-release \"stable\";
" > /etc/apt/apt.conf.d/10defaultRelease
#set the priority for libsdl from wheezy higher then the jessie package
echo "Package: libsdl1.2debian
Pin: release n=jessie
Pin-Priority: -10
Package: libsdl1.2debian
Pin: release n=wheezy
Pin-Priority: 900
" > /etc/apt/preferences.d/libsdl
#install
apt-get update
apt-get -y --force-yes install libsdl1.2debian/wheezy

Save the script created above and run:

sudo chmod +x installsdl.sh
sudo ./installsdl.sh

This will force SDL to 1.2.15-5, you should now be ok to continue with PyGame or Cam.Py

In the next step we can make some customisations and tweaks, these include adding a splash-screen, making Cam.py start automatically when we switch on the Pi as well as shutdown when we exit Cam.py, also disabling the red LED on the Pi Camera module. As I'm using the Cam.py with my PiKon telescope, we also need to add some additional code to rotate and flip the image to compensate for the reflecting mirror and allow for the camera rotation.

Step 9: Customisations, Settings and Tweaks

Standalone Mode

You can set the Pi to boot straight into the Cam.py software at startup by editing:

sudo nano /etc/rc.local

Add the following lines before the exit 0

cd /home/pi/adafruit-pi-cam-master
python cam.py

Next time you boot it should show the text console for a few seconds then start Cam.py.

Auto Shutdown

To have the Pi shutdown when exiting the Cam.py software simply edit the rc.local file as above and add the following line after python cam.py but before exit 0

shutdown -h now

Increase Camera Speed and Redraw rate

This is a performance improvement to make the camera more responsive, do the following:

sudo nano /boot/config.txt

Look for the dtoverlay line near the bottom and update the speed and fps values:

dtoverlay=pitft28c,rotate=90,speed=80000000,fps=60

Disable the Red LED on the Pi Camera Module

If like me you are using your Raspberry Pi Camera on the PiKon telescope, you'll probably find that the red LED on the camera can add unneccessary glare on the mirror. If you bought your camera as part of the PiKon kit you normally find that there is some black removable paint covering the LED. If you want to make doubly sure that your LED is not glaring across your mirror you can disable the LED via a software setting, just do the following:

sudo nano /boot/config.txt

Add the following line to the end of the file:

disable_camera_led=1

Reboot the Pi and the next time you use the camera, the LED will be disabled.

Rotate or Flip the Camera Orientation when using the PiCamera Module

These commands apply when you are using the python-picamera module, the code below specifically applies to the Cam.py program. At around line 170 of the Cam.py file, you can add/modify the various values supported by the picamera module, in this example we are adding vflip and rotation values.

# Init camera and set up default values<br>camera            = picamera.PiCamera()
atexit.register(camera.close)
# Adjust camera orientation to compensate for mirror and rotation
camera.vflip     = True
camera.rotation      = 90
camera.resolution = sizeData[sizeMode][1]
#camera.crop       = sizeData[sizeMode][2]
camera.crop       = (0.0, 0.0, 1.0, 1.0)

More information on the python-picamera interface is available here.

Add a Splash screen to the Cam.py Program

If you want to add some customisation to your Pi based camera, you can easily add a splash screen by having the program load an image during startup. To do this you'll need to upload your chosen image to the Pi, I suggest you size the image to 320x240 to match the PiTFT's resolution. Add the following line to the Cam.py file at line 41:

# Display Third Earth Design - PiKon splash screen on start-up with 5 second delay
os.system("sudo fbi -T 2 -d /dev/fb1 -noverbose -a tedpikon320x240.jpg")
time.sleep(5)

Replace the file name with the path and name that matches your image, I've used the time.sleep command to keep the splash screen on long enough to see it properly.

Step 10: Enjoy!

You've completed your build, setup the software and made some tweaks, now it's time to get out there and have some fun with it! I've included some of my moon snaps above, I hope you find the Instructable helpful, please let me know if you have any comments or questions, they are always welcomed.