Ever since I got a Raspberry Pi I wanted a small standalone case to put it in. There are any number of cases available already (simply search Thingiverse for a nice range of options) but each of them simply provided a case to protect the circuit board, what I was looking for was something more like a small computer case that I could simply plug a power cable (and optionally a network cable) into and have everything else built in. This project is what I came up with - you can see the end result in the image to the right.
For the impatient here are some quick links to everything you need to replicate the project for yourself:
The physical frame is fully 3D printable and all the design files (OpenSCAD sources) are available in the GitHub repository and on the Thingiverse project page. The Thingiverse pages also includes the generated STL files.
Choosing an LCD
For a display you will need a small (5" or less) LCD screen. I've designed it for a small screen I got from eBay. This will need to be dismantled (simply remove the plastic case it is provided in) and the OpenSCAD files will have to be adjusted to fit the size of the components inside (I've defined these sizes as constants in the header for the source files so it should be fairly easy to modify). If you want to reuse the circuits I've provided you will need to get an LCD that operates off a 12V DC supply and has a composite video input.
Generally there will be two main boards inside the LCD casing - the LCD itself and a control board. These two parts are generally connected by a flat ribbon cable. As well as adjusting the space for the LCD screen itself (it needs to be a tight fit so the LCD will remain in place without the need for glue) you need to determine the additional spacing required for the control board - it is important to allow enough space so the button input board can be added without overlapping.
Apart from the Raspberry Pi and the LCD there are two additional circuit boards that need to be added. These are not off the shelf, they have been designed specifically for this project (they are available as Fritzing project files in the GitHub repository).
For both of the additional boards the Fritzing project contains the schematic, a strip-board layout and a single sided PCB layout. You will need to solder these up yourself (the components used are common and readily available - there is nothing magic about them).
The first board is the power board. This serves a number of purposes:
- Provides a regulated 5V output from a 12V DC input to drive the Raspberry Pi.
- Routes connections from the the LCD (Video and Audio) to pin headers that can be connected to the Raspberry Pi.
Provides a direct 12V power supply for the LCD itself.
In this version I'm using a standard LM7805 linear regulator to generate the 5V output. Because of the current being drawn (about 450mA for the Raspberry Pi and a Bluetooth dongle) I had to add a heat-sink to the regulator and a wire wrapped resistor to the circuit to help dissipate the excess heat generated (I cover the details on this in an earlier post).
The connectors coming off the power board are:
12V DC input. This goes to a barrel connector that you can plug a 1A/12V DC power adaptor into.
- A 4 pin connector to the LCD. This carries 12V, Ground, Video and Audio signals to the LCD.
- A 2 pin connector to the Raspberry Pi. This is connected to the 5V and Ground pins on the GPIO header.
- A 2 pin video connector. This is wired to an RCA plug that connects to the composite video output on the Raspberry Pi.
- A 2 pin audio connector. This is wired to a 3.5mm audio plug that connects to the headphone socket on the Raspberry Pi.
To provide input without a keyboard I designed a simple 4 button input device that connects to the Raspberry Pi GPIO pins. This uses standard momentary push buttons to simulate input. There is a six wire cable from this board to the GPIO header - one cable goes to the 3.3V generated by the Pi, another to ground and the remaining four can be connected to any GPIO pin that can be configured as an input.
Each input is pulled high and pressing the corresponding button will short the input to ground. This means that when you read the GPIO input a 'high' value indicates an idle button while a 'low' value indicates a pressed button.
The circuit board for the buttons is mounted on the front panel underneath the LCD. The buttons I'm using are fairly standard but if you use something different you will have to modify the OpenSCAD files to allow for spacing.
The Physical Frame
The entire frame is 3D printable and consists of four main parts - the front panel, a base and two side panels. I've kept the entire structure open to help with heat dissipation (mainly from the power board) and to make access to the GPIO pins simple. The parts can be glued together with superglue or some other plastic adhesive.
My printer has a maximum build area of 15cm x 15cm so all the parts have been designed to fit that restriction. If you have a larger build area available to you then you have a bit more flexibility to rearrange things.
The base plate has slots in it to hold the Raspberry Pi and the power board in a vertical position (see the image to the right). The supplied OpenSCAD files are designed to hold them tightly based on the width of normal strip-board (about 1.5mm). You will have to adjust this if you are using custom boards or a main board other than the Raspberry Pi. If the hold is not quite tight enough (the tension of the cables pulls a board out of vertical for example) you can use a little bit of BluTack in the slots to help hold them in place.
Total print time is about 6 hours on my printer and (because of the tight tolerances needed for external components) you need another hour or so with sandpaper and files to get everything to fit smoothly. Overall you need to allocate at least a day to prepare all the printed components needed.
I've gone through several iterations of this design to get everything fitting nicely. This is my recommended procedure for assembly for your first unit (and I highly recommend that you follow this if you have modified any of the OpenSCAD files).
Verify the LCD
The first thing to do is to verify that the LCD works with your Pi. Before you disassemble it simply plug it into your Pi and make sure you can get output on it. You may need to modify the config.txt file on your SD card to set a resolution that the LCD can display (and more importantly, that you can read).
With the screen I'm using (which has a 16:9 aspect ratio) I can get a readable console at 320x180 pixels and usable X11 graphics at 480p (856x480 pixels). I also had to adjust the over-scan values to maximum the use of the display area.
It's a lot easier to play with this and get it working to your liking before you start hacking it to pieces - it makes it a lot easier to verify everything is working later.
Build the Power Board
The next step is to build and verify the custom circuits - the power board and the button board. Most importantly you should verify the power board is generating a nice regular 5V output for the Pi and that none of the other external connectors are accidentally shorted to either the 12V or 5V lines. If you get this wrong you might destroy your Pi.
Connect it to a 12V supply and check every external connector - the only high voltages should be 5V on the power output to the Pi and 12V on the power output to the LCD. All ground pins should read 0V. Check the signal pins (video and audio) and make sure they aren't accidentally connected to one of the voltage rails - at idle they should all read unconnected or 0V.
Once you are satisfied it's safe you now need to hook everything together. Hook it all up so the LCD and Pi are driven from the power board and the video and audio signals are coming through the power board to the Pi. Make sure everything runs up and acts as you would expect. I recommend running it on the bench like this for a few hours and checking the heat generated by the power supply before you proceed any further.
Build the Button Board
The button board is very straight forward. Build it up and then connect it to the GPIO pins on the Pi. Make sure you use a 3.3V pin on the GPIO and not a 5V pin for the power supply. I've provided a small test program in the GitHub repository that will help you verify that you are getting the inputs you expect.
The test program is written in Python and requires the RPi.GPIO library. You need to run it as root for it to work.
Print the Front Panel
The first component to print is the front panel. You need to make sure the LCD components fit in tightly and there is still enough room for the button board. Make sure there is enough clearance for you to fully depress the buttons and make contact. The OpenSCAD files provide spacers to separate the PCB from the front panel to give you this movement - you may need to adjust the size of these spaces to suit the buttons you are using.
Print the Base Plate
Now print the base plate and make sure that the PCBs mount and hold their place properly. Adjust the width of the slots as needed to ensure a tight fit (or use some Blu-Tack to make sure they fit in properly).
Mount the LCD and the button board into the front panel and hold it in it's relative position above the base plate to make sure there is enough clearance. Most importantly you need to make sure the heat-sink on the regulator and the large resistor are not anywhere near a plastic component or circuit board. A gap of about 5mm should be enough - anything less and you are creating a fire hazard.
Assemble the Frame
Now you need to print the two side parts of the frame and assemble it all together. I used superglue to join them and held things in place with rubber bands until the glue set.
First you need to glue the side panels to the base and wait for them to dry. Then you need to add the face-plate.
Add the Circuit Boards
Insert the LCD screen and attach the LCD control board to the back. In the version shown here I used Velcro tape to attach them, it works but is a little bit loose for my liking. For future versions I'm simply going to superglue the control board to the back of the LCD screen.
Attach the button board next by gluing it to the spacers provided. Finally you can slot in the Raspberry Pi and power board and wire everything together. You need to make sure you have enough slack in your connector wires (for video etc) so that tension doesn't pull things out of alignment. Once you are happy with the layout and the way everything fits together power it all up and enjoy your PiStation :)
This gives you a nice physical framework and a system that works but there are a few rough edges that need to be sorted out. I'm working on a few of these niceties myself (and changes will be pushed up to GitHub) but if you make your own changes I'd love to hear about them.
Some specific things that I have in mind include:
- Button board software support. I'm working on a small daemon that will turn button presses into standard keyboard input through the Linux uinput framework so they can be treated as a normal (although very small) keyboard without requiring any magic code in your application.
- Reduce heat issues. I'd like to change the power board to use a switching regulator instead of a linear regulator so heat dissipation is not such an issue. Unfortunately linear regulator design is a bit beyond my capabilities for now so I'll probably use a module to provide the functionality which will increase the cost.
A nice UI framework optimised for the limitations of the system. This will be a reasonably large software project but would be nice for dedicated projects. Ideally it would provide a framework for a number of different languages that allows the development of applications that utilise the entire (small) screen area and can be driven by the four button input without needing a full keyboard or pointing device. It's almost (but not quite) an embedded UI. I'm planning on using this for my Bench Tester project as well so it may get a bit more love than the other enhancements in the near future.
Overall this project has worked well for me so far and I'll be building a few more instances of it to provide the framework for other projects in the future. If you decide to use it as a basis for your own work please let me know in the comments here or on the Thingiverse page - I'd love to hear about what you are working on.