Making a custom RaspberryPi case

Bulk made enclosures are useful when you just want basic underwear on your Pi but what if you need to put something else in there and it won’t fit? I’ve built a Pi enclosure for my home automation gateway before but it was just 3 layers of acrylic to hold everything together, turned out nice. In this post I will show another example enclosure for a Pi gateway.

I am finishing up a separate project where I needed to put a Pi gateway in an elegant enclosure along with an ATXRaspi+power button, and a Moteino. This guide can be used as a guide to build a RaspberryPi+ATXRaspi+Moteino setup that can all live together in a nice box to serve as an internet gateway to your Moteino or other wireless Internet Of Things network.

I will show you how I made the case and the steps I took to avoid wasting material while adjusting the cutouts. I will include the corel and DXF files that I used to lasercut the case. I have a 60W laser cutter imported from china, and that makes for a very nice prototyping tool to cut and engrave the boxes, but they are becoming widely available at hacker spaces and workshops all around.

First let’s see what components go in the box: Continue reading

PiGateway upgraded to MightyBoost

ATXRaspi is great for enhancing your Pi with a power button that will gracefully shut down your Pi without the need to login to do that. I’ve been running my Pi like that for at least a year. But I felt like I needed something new, more powerful.

Enter MightyBoost – a multi purpose PSU that can supply the power a Pi needs, and also be controllable by a Moteino (including wirelessly controllable if needed) such that it would duplicate the functionality of ATXRaspi. And most importantly to be able to run it on battery backup in case power is lost, to avoid SD card corruption and downtime. Also it can monitor the battery (via Moteino A7) and shutdown the Pi in time before the battery runs out, as a last resort. Without a Moteino it can be used as a general purpose 5V boost-from-lipo power supply, that can also charge your tablet/iPhone/droid/etc.

I have now upgraded my Pi gateway to using MightyBoost. I had to lasercut a new mid layer for my existing Pi Gateway lasercut case. I have posted the changes (corel and DXF files) in the github repo so you can customize &/or lasercut your own if you’d like. As usual, I like to cut the new template in cardboard and do a fitting test, measure any adjustments, re-cut if needed, then finally when it’s perfect cut it in the more expensive translucent acrylic. Continue reading

Laser cut case for RaspberryPi gateway

Since I imported my new laser cutter from China I wanted to give my RaspberryPi gateway setup a facelift and organize it in a nice custom case which I can actually show off to friends. Before we move on into the details, here’s a perfect spot for a BEFORE/AFTER shot:

This post will describe how I built this case and will include the source files that you can use to customize your own case based on these blueprints. Continue reading

RaspberryPi home automation gateway – Hardware and Demo

UPDATE: An updated version of this gateway install guide is published here. The rest of this post is kept here for legacy purposes, some links to source files might be obsolete or not work any longer, please see the linked guide above for the latest code and walkthrough.

In this last part of the RaspberyPi home automation gateway series I will show an example of hardware implementation that talks to the RaspberryPi secured realtime home automation gateway, and share the firmware source code.

GarageMote is a garage door controller shield that can be used to remotely control a garage door from anywhere on the web or from your smartphone.

GarageMote was created for several reasons. Mainly because as I’m adding more Moteino based home automation devices around my property, one of the nice things I wanted to be able to do is control the garage door remotely. It’s become so routine to close the garage door when I leave from home that sometimes when I’m already 5 or 10 minutes away I wonder if I actually closed it. And so I want to be able to check the door status and close it if it was left open by mistake, without having to drive back home. Or maybe it’s useful to be able to let someone in without giving them the garage code every time.

Continue reading

RaspberryPi home automation gateway – Setup

In this third part of the RaspberyPi home automation gateway series I’d like to present the RaspberryPi software stack that will allow a secured realtime webserver-websocket gateway to your home automation project.

As a webserver I decided to try Nginx. I’ve previously used Apache which always felt a bit slugish and had a large disk and memory footprint. There are many bechmarks that contrast webservers performance, here’s a nice one that focuses on RaspberryPi, and it includes Nginx and Apache.

The stack will be a webserver (Nginx) and a websocket server ( The websocket will be proxied through Nginx, and everything will be encrypted with SSL and authenticated with auth_basic. A bunch of other things need to be setup and configured to make these work nicely together. Continue reading

RaspberryPi home automation gateway – Approach

In the previous part of this post I described the conceptual high altitude picture of a secured, realtime home automation gateway. In this part I will go into more detail and show some of the issues I’ve faced and and solutions to address them.

First, the webserver had to be put behind a mandatory SSL connection. All incoming HTTP port 80 traffic would be permanently redirected to secure sockets layer port 443. That was pretty easy with a self signed SSL certificate and some webserver configuration. Then HTTP basic authentication was put in place so that users would first need to be authenticated before web access would be granted. Again, not too complicated, using a .htaccess file and some changes in the webserver config file. Custom authentication can also be implemented, but for the purpose of this tutorial basic auth is good enough.

Now to the harder part. I wanted the websocket server as a separate entity from the main webserver. Several reasons for that, but mainly because of scaling and I like to keep separation of concerns and have a modular design. That exposes several issues. Continue reading

RaspberryPi home automation gateway – Intro

The title is actually incomplete but didn’t want to make it too long. What I’m about to describe is an initiative on how to put together an encrypted, authenticated, realtime, RaspberryPi powered home automation gateway. It will be a few separate posts that will go from concept to implementation, using a real world example of how to control something in the house. I’ll break it down and explain the big picture and each part that needs to be addressed. But first, a little more background and reasoning behind this effort.

My makeshift home automation gateway

Above you can see my temporary gateway setup. It’s very simple – I have a RaspberryPi powered through an ATXRaspi, and a Moteino which acts as the gateway to my wirelessly controlled house. It’s hard wired to my home router because the wireless adapters are simply junk, not reliable. Also hooked up to a monitor and keyboard.

I’ve seen tons of blogging and articles on how to make something blink, turn a servo or LED on, even do more real things like turn ON lights, change the thermostat or control some household appliance, from your smart phone. All cool and dandy. But almost everyone seems to completely skip security. The blog posts end when the LED or light turns on, and everyone seems to be super excited about the cool thing they just did. But I’m left there with a raised eyebrow wondering if those people know what they are doing. Security is of major concern to me because if I hook up my garage doors, lights and perhaps other appliances to the interwebs, I don’t want unauthorized access. Is that a nobrainer or am I paranoid? Continue reading

ATXRaspi 2.1 released

ATXRaspi now comes in red soldermask!
Other than that a few things were moved around a little to make more space for the 2.1mm barrel input jack which previously could only be soldered without the uUSB connector.
The LEDs have been rearranged to match the “BootOK” and “Shutdown” silkscreen markings – each is now next to the relevant LED for less confusion.
Also the button is now taking only about 3 seconds to hold until a shutdown is triggered, and a total of about 7 seconds for an unconditional power cutoff.


Introducing ATXRaspi R2

A new revision of ATXRaspi was in the works for a long time. Based on user input and other suggestions I came up with what I think is a better incarnation of it. Special thanks to Mike from mikesmicromania for all the valuable feedback and suggestions on this new revision!


Among other features:

  • all SMD components yield a more efficient layout and a leaner profile
  • More input options: microUSB, 0.1″ header, 2.1mm barrel jack
  • More output options: 0.1″ header, USB type A (female)
  • poly fuse footprint allows you to add your fuse of choice directly on the ATXRaspi (through hole or SMD)
  • onboard SMD LEDs help visualize signals between ATXRaspi and RaspberryPi
  • extra output power header pins (2x5V, 3xGND)
  • backwards compatible

This version is making a huge difference in manufacturing, as I assemble everything by hand. R1 was difficult and time consuming to assemble. While R1 worked great, the relay would be prone to voltage spikes and drops depending on the quality of the input supply, hence causing glitches and requiring multiple button presses to turn power on (an effect that was reduced by wrapping the output power wire around a ferrite bead). This new design uses a mosfet which drops only 10-15mV of power and these effects should not be manifested any more.

Just for fun, here’s the stencil I produced for ATXRaspi R2 with my DIY stencil method, and the results after paste application:

Please use the forum to submit more feedback and suggestions which are always welcome!

Sump pump alert with Moteino & HC-SR04

UPDATE: This project has been replaced/updated with SonarMote. See this blog post for a more rencent implementation of what you see here. The alerts are now implemented as simple events on the Moteino Gateway.

Here’s another project I wanted to do for a long time. I wanted a sump pump flood warning alert system in place, for peace of mind when I’m gone from home for prolonged periods. For whatever reason I thought this was going to be more difficult but no, it’s almost as easy as pie!

All I needed was a HC-SR04 sonar sensor and a USB 5V wall supply. The sensor only works at 5V so this method of powering the Moteino was very convenient since I already have an outlet close by for the sump pump.

The sensor has 4 pins clearly marked: VCC, GND, TRIG and ECHO. I connected VCC to VIN on Moteino, ECHO goes to D3 and TRIG to D4.


I used some of the code this instructable to get started and added my wireless code to handle packets and blink the LED and was done in no time. The setup was very simple, I estimated a good spot underneath the sump pump cover where there are no obstructions inside, cleaned it up, taped some velcro, secured the wires and that was pretty much it.

 Moteino_HC-SR04_SumpPumpAlert_cover Moteino_HC-SR04_SumpPumpAlert_installed

I added a few lines of code to my main Python script running on the RaspberryPi.
By the way, here’s how my RaspberryPi setup looks like, including the ATXRaspi power controller, the power button and the gateway Moteino (it’s an older R1 but just as good for as a gateway):


The Python script logs the data to EmonCMS and here’s a graph of how that looks like, the Moteino reports the distance to the water surface, so the spikes means the sump pump just kicked ON, and as water rises the distance decreases until the pump starts again:


It’s been a rainy spring so far here and I knew my pump kicks ON quite often, now I can see it in real time, and setup alerts if the water rises too much. Seems like the pump is always pumping water out when it rises to 32cm below basement surface. So setting an alert to something like 20cm below surface should be enough since I don’t expect the water to ever rise so much as long as the pump works. The alert code will send me a SMS message when this happens, here’s a test level, I set the live value at 20cm:


You can of course setup other types of alerts – like audio alerts or maybe a LED visual indicator (less useful when you’re not in your basement).

Fun/Scary fact: The sensor is very accurate even though there’s a variance of 1cm between some readings (resulting in a sawtooth graph) as water rises. Based on the graphs, how often the water is pumped (every ~23 minutes), and how big the reservoir is, I figured my sump pump removes roughly about 18.5 liters every cycle, or about 1158 liters (306 gal) every day, wow!

So now there’s an extra level of peace of mind when I leave on vacation. I guess being gone for even 1 day could mean disaster if the sump pump breaks down at the same time!

Time to think about how to gather/store all that water instead of throwing it away, after all, I pay something like $11 for every 1000 gallons of city water.

Source code is on GitHub: