Site Tools


Home automation updates

It's been a while since I have posted anything! I have been busy with work, but have been making some slow progress on my home automation system. Since posting about my Apartment Security System, I have moved to a new house and made some nice additions. I now refer to it as a “home automation system”, since its uses have evolved past just providing security.


Radio Thermostat CT-50 with WiFi

My new house has two thermostats, and I wanted to control both of them from my system. I briefly considered building my own thermostat, but decided I would like to be able to operate my AC when my automation system eventually has bugs/crashes/whatever. The next option was to buy a WiFi thermostat with an open API and control it that way. The Nest is the first thermostat that comes to most people's mind, and while it does have an open API, I didn't really want the other features or to pay brand name premium. Eventually, I found the Radio Thermostat CT-50 for $100. It has a completely open API (PDF) and there's even a Python library for it called radiotherm.

Thermostat info on automation web page

After hacking around with the Python library for a while, I was able to integrate it with my automation system. I replaced both of my thermostats with these models, and was able to add a web page to view the status of the thermostats. It was also not too difficult to add logging to the SQL database, so that the temperature display graphs included thermostat data right along side my EnviroNode data.

Unfortunately, the only way to control the thermostat with the system is by using the internal system commands. These commands can be accessed from the command line only, and I needed an easy way to execute these commands from the web. I decided to add a new feature, scripts. This would be how I began to control my thermostat.


Although it has always been one of my ultimate goals to make the system extremely script-able with flow control, variables, the works (maybe some D++ integration!), the current script system just processes commands sequentially. Commands like “tstat 1 cool 76”, or “leds blink” or “sound 41” are the usual commands used in scripts, and it let me put together some useful and fun scripts.

Script control web interface

The scripts are simply text files stored in a database with an index number. To execute a script on the web interface, it calls a JavaScript function which makes an HTTP GET request to a PHP page, which then makes another HTTP request to a CherryPy webserver running with the automation system (can you tell I am not a web developer?). This is a really un-elegant solution, but it was the fastest way for me to get something running.

While implementing this system, I began to look into more “proper” ways of exchanging data between a web interface and a Python server, but with this script control also came an easier way to control my LED lighting…

LED Lighting

I made some pretty cool LED lights to go with my house. Originally based on code from my LED_Panel, I designed a new PIC24 micro board to control the WS2812B LED strips, in addition to APA101 LED strips. I bought a bunch of WS2812B LED strips, wrapped them around a PVC pipe, spray-frosted a glass vase and put the pipe in the middle.

The lights have several modes, but they mostly run a hypnotic “ambient color mode” that pulses colors in a pleasant way. I have about 7 of these LED lamps around my house. They look super cool in person, and I definitely plan on doing a full write up as well as publish schematics and source code.

New Dashboard

Prototype thermostat control

Finally, a few months ago I began working on a new dashboard for my home automation system. With a little bit more JavaScript under my belt, plus playing around with CherryPy and JSON, I was able to pull together all of the system information and display it on a single page. I began re-working how the data was collected within the main Python program so that the entire system status could be summarized in a single JSON object. Using my crazy JavaScript-PHP-CherryPy work-around, I was able to get that JSON to the home page and display it with some oldschool HTML tables (oh god I don't even want to share this code).

Doing this made me realize I have a LOT more work to do. I need to make my system have full 2-way control using JSON and JavaScript, and I REALLY need to learn some modern web frameworks to make it pretty and more functional. I've been playing with some frameworks, and I'm going to continue to move forward so that I can control my system with the Raspberry Pi Security System Panel I have been somewhat working on. I've developed a prototype thermostat control that works, but it still uses HTML tables, and I really need to learn some of that fancy CSS so I can get my web skills out of the early 2000's…..

2017-08-23 20:13 · daniel

Bluetooth audio receiver antenna upgrade

I got a pretty nifty Bluetooth audio receiver with NFC to hook up to my speakers in the main room of my house. It works pretty well - the receiver stays on all the time so I can connect my phone to it whenever, and the 3.5mm audio out can be hooked into any powered speaker system.

There was one problem: the wireless range was pretty terrible. I could have my phone on me anywhere in the main part of the house, but if I walked into the kitchen or my bathroom with my phone in my pocket, the audio would stutter and lose connectivity.

The receiver has no external antennas, so I figured it must be using simple PCB trace antenna. Fancier devices might have multiple antennas for diversity, but I wasn't expecting that here.

I have this rule of thumb… a crappy antenna talking to a crappy antenna makes a bad connection. PCB trace antennas are great because they are basically free (part of the cost of the board) and don't add to a BOM (Bill of Materials), but they don't have the best performance. The 2.4 GHz antenna in your phone used for WiFi and Bluetooth will almost always be a terrible antenna. So… let's add a real antenna to this thing!

Inside the Receiver

Time to open this thing up and see what we've got…

Just as I expected. A nice little wiggle antenna, similar to the one I used for my security system modules.

It appears that the designers used a Bluetooth module and stuck it on their main PCB. This is very convenient for an antenna modification, because the PCB trace antenna is sticking off the main board. (there's also some headers with SPI pin labels near them… looks like this board could be fairly hackable!)

One little snip with some cutters, and the old antenna is gone…

For the best performance, the new antenna should be outside the enclosure. An external SMA connection would be the most convenient, so I grabbed one of my SMA to uFL pigtail adapters I got on eBay. I cut the uFL connection off, and using an x-acto knife and microscope, I was able to strip the tiny coaxial wire. This tiny coax has an inner conductor (signal), a clear dielectric, a braided outer shield (ground), and an outer sleeve. By cutting just the outer sleeve, I was able to unravel the shield. Then I cut just a small amount of the inner dielectric, so a very small amount of the inner conductor was exposed. The SMA connector also had a locking nut, which means it could be easily mounted on the case by drilling a small hole.

Next, I scraped off a small amount of the soldermask on the PCB trace that went to the old antenna. This is literally just scraping the top until there is enough exposed copper so that a solder connection can be made. I did the same on part of the ground plane next to this trace. With the aid of a microscope, I was able to solder the SMA connector to these exposed copper points. It's important to use as little solder as possible - we want the connection to be as smooth as possible to keep our impedance matched as close as possible. The individual wires for the ground and signal should also be as short as possible.

After that it was just a matter of putting it back together! This was actually more of a pain than I expected. The LED wouldn't go where it was supposed to and kept breaking off… but eventually, success! I paired the SMA connector with a 2.4 GHz antenna from DigiKey.

The receiver has significantly better range. I can keep my phone in my pocket and walk anywhere in my house - it still maintains the Bluetooth connection!

Add some speakers and an Amp

Okay, well, let's just make this a robust, cheap audio system!

The Dayton Audio B652 speakers are pretty awesome, especially for the price of $40 (and they often go on sale). I also got a cheap class-D audio amplifier on eBay based on the TDA7492 that pairs well with these speakers. (Parts Express also has a version of this amp). The audio cable needed a little splice to connect to the Bluetooth receiver. And there's no volume control - but you can control the input volume with the Bluetooth device.

And that's it! Now I just need some kind of 3D printed case to clean everything up…

2016-07-16 15:31 · daniel

Raspberry Pi Security System Panel

After a few months of designing some boards and buying hardware, I have put together a prototype for my next generation security system.

Although I have been working on my security system for a couple of years, I've already been planning the next version of the system. In fact, much of the design work for the hardware in this post started in early 2015. I'm still developing my current system, but eventually everything will integrate into the new system.

Current system control panel

The current system uses some LED panels with 4 buttons at each door to control some basic system functionality. This wasn't ever intended to be the “final” door panel, but I needed something to throw together quickly at the time that could at least tie me over until I designed something better. Well, over a year later I'm still using the same panels as the scope of my desired panel has grown.

Originally, I wanted something small and smiple. I knew I wanted a screen and buttons on the panel. I wasn't really a fan of the standard two-line LCD displays, however I do like black and white OLED panels. But I haven't been able to find any of a decent size. Eventually I decided to try out the PiTFT display from Adafruit, which is a pretty great screen. I even put together a pretty cool prototype touchscreen interface using pygame. Since my new panel was using a Raspberry Pi now and had a touchscreen, I needed a good speaker, audio amp, and hey why not a matrix keypad?

While I was thinking along this path, I realized how terrible the audio output is on the Raspberry Pi. This led me to develop the PCM2707 USB DAC + Amp and I2S Audio DAC + Amp. I decided I definitely wanted to use an I2S audio solution with a Pi hat, but this would be difficult to mix with the PiTFT.

It was about this time I found the Adafruit 5" HDMI Touchscreen. The screen was bigger, used HDMI, and had a better mounting solution. I just said screw it at this point, I'm just going to make a big awesome panel (inspired by awesome video game security panels). I figured I could make a Javscript web interface so that the system could be controlled from a panel or any other computer. I decided to add a new LED strip for lights, an NFC reader/writer, and a new environmental sensor.

A few of my friends have pointed out “why not just use an android phone or tablet? It has most of those features.” The answer is, of course, it's much more fun to build it yourself! :)

Below is a description of the hardware modules. I haven't written most of the software or firmware for these devices, but eventually once I've had a chance to develop them a little more, I will write more detailed documentation and upload the design files.


This hat is the central board that connects most of the components together. It is based around a dsPIC33EP512MC806 microcontroller, which communicates with the Raspberry Pi as well as 3 other devices over 3V3 serial. The PIC acts as a serial multiplexer so that the Python code on the Pi can communicate with the other 3 devices individually, as well as send commands to the micro itself. The micro also reads the matrix keypad.

Separate from the microcontroller, I used a PCM5122 as an I2S audio DAC. The PCM5122 is controlled over I2C, which is connected to the Raspberry Pi. I tested with drivers for the IQaudio DAC+ and the HiFiBerry DAC+, using these procedures, both of which use the same PCM5122. I'm not really sure if there is much of a difference between the two drivers, other than a different I2C address. The lower two bits of the 7 bit I2C address is determined by two pins on the PCM5122 that can be pulled high or low. IQaudio is kind enough to mention the I2C address used on their board (0x4C). HiFiBerry doesn't specify the address used, but by looking at high resolution closeups of their board (and trial and error), I determined it is 0x4D. The layout and design is based on the PCM5122 reference design. I also use a TPA2006D mono audio amp, which drives the panel's speakers. There is also a 3.5mm audio output jack before the amp, so it could be plugged into another system that already has an amp.

Power for the Raspberry Pi is provided through this board. I used a really thick trace and an extra 100uF cap.

Finally, there are headers on the bottom of the board that connect to the Raspberry Pi SPI pins, used for the NFC reader.


APA102 led-strip

The led-strip is based on my LED_Panel design. Not really sure why I made this, I mostly just wanted some cool LED's to go with it.

However, instead of using an Arduino (ATmega328P) and the WS2812 LEDs, I switched to using a PIC and the APA102 LEDs. The APA102 RGB LEDs are really cool because they have a clock and data pin instead of a single data pin. So no complicated timing required, you can just use SPI! Read more about them here!

The size of this board is designed to match the size of the touchscreen.

EnviroNode SP

Temp, humidity, light and prox sensor

The EnviroNodeSP is based on my EnviroNode design. It uses the same digital temp and humidity sensor, but drops the analog light sensor for the much beefier VCNL4010. Except this isn't just a light sensor, it's an active infrared proximity sensor as well. My hope is that the panel can respond to hand waving in front of it in addition to ambient light detection.

SP stands for “sensor package”, which was the code name for this module in some of my earlier drawings before I knew what it was going to be.

I haven't coded any firmware for this board other than blinking an LED, so hopefully the VCNL4010 is as cool as I think it is.


PN532 NFC module

I got this PN532 NFC module from eBay. There's a few different options on eBay. I would have liked to use Adafruit's module since I am using their Python code, but their module is freaking huge and too expensive. This one (branded “Deek Robot”) is much smaller, cheaper, and works just the same as far as I can tell.

I have done some basic testing with the module and it works great with Adafruit's Python code. For now I will use it just for basic authentication, but I have some ideas about dynamic NFC tags that could make this feature more interesting…

Power Module

micropwr module

Powering all of these modules was getting interesting as the total current consumption increased. Originally I was using some high quality 2.1amp phone chargers, but the voltage was sagging too much with the Pi, hat, touchscreen, audio amp, etc. I decided I'd rather provide ~12V somewhere and switch it down.

I built a break-out module for the PTN78060WAH switching regulator. The TI modules are little expensive but they are truly fantastic. The 3 amps is more than enough to power all the systems. Stupidly, I didn't include a breakout for the sense pins, which would have made even more sense. But by routing power to each of the boards individually, everything works well. I'll investigate the power systems a little more.

Speaker and Keypad

Speaker and Keypad

I got the Dayton Audio 1-7/8" full-range driver from PartsExpress. I need to make a proper enclosure for the speaker, as it doesn't work too well without a box. There's a few other drivers on DigiKey I was thinking about checking, but I need to do full testing with this driver first.

The Matrix Keypad from Adafruit is pretty simple. It would be nice to find a metal keypad, but this will work for now.

What's next?

Next up, I need to build an aluminum chassis for everything! Followed by writing lots of firmware and software…

2015-09-30 18:12 · daniel

Check out my security system

Putting all these sensors to work

I've been working on my apartment's security system for a little over two years now, and in the last few months it has finally taken shape into a really cool system. Lights, sound environmental, door sensors… all the basics for a security system.

Read more about the system!

2015-07-31 11:24 · daniel


Hello! I am currently updating The new will be based on the dokuwiki platform so that it's easier for me to add content. In addition to transitioning existing content, I plan on adding a significant amount of new content. I've worked on several really cool projects that I'll be uploading soon!

2015-05-20 14:26 · daniel
home.txt · Last modified: 2015-08-12 12:25 by daniel