Saturday, April 15, 2017

Home Automation Controls - Simple Esp8266 Wifi Relay Part 1

Follow Along as I play with this. I'm just wingin it. Relay Control Server The esp8266s are great. They've got a lot of punch and built in wifi. Plus, being Arduino compatible, getting a prototype up and running is pretty fast.

A Simple Relay Server

A relay server should be able to operate a relay and accept wifi Http requests. The requests should include getting the state of the relay and switching the state of the relay. That seems like a decent set of simple requirements. So, this first iterations should be pretty simple with items we listed above. We should have a GET endpoint /relaystate?relaynumber=#, where relaynumber is a number we define for an individual relay. This will be more clear later. Let's also make two other GET endpoints to turn the relays on and off, /relayon?relaynumber=#, /relayoff?relaynumber=#. Using these endpoints we can set the state of each relay individually. This seems like a good enough start and we can get fancy later on.

Arduino Esp8266 Webserver

This webserver library makes putting things on a network a super simple. Check out the esp8266 Webserver example that comes with the esp8266 library in the Arduino ide.

Driving Relay Coils

Like many microcontrollers, the esp8266 has plenty of power in terms of computing and peripherals, but the output from the pins are not enough to power much. At 3.3V, the esp8266 lacks the current and voltage to drive current hungry modules, but this is common. We'll need to select a device to help us drive the relatively large coils. 

A transistor is a great way drive larger loads, like a motor or an LED. They're pretty simple devices that can be thought of like a voltage controlled switch. The PN2222A is a general purpose transistor and just about every tinkerer has a few of these floating around their tool box. They can be picked up at Radioshack. The interesting part about the transistor is when we put the transistor into "saturation" mode, the transistor becomes a sort of switch. You can also use other devices that are analogous to a transistor like a mosfet or motor driver IC's.

I happen to have a few L293D motor drivers, another fantastic little IC to use in your projects. Inside a L293 is four half H bridge drivers with flyback/kickback diodes. Awesome. I'm going to use these to drive my relays. 


Home Automation Controls - Why I'm not Using Qt 5.8

Follow Along with my Development on this project. I'm just kind of wingin' it Github - HomeControls

Simply, it's a pain. Qt 5.3 is available from the repositories and an all you need is an apt-get install on the Rpi to be in the game. While it seems simple enough to compile 5.8 for the Pi (setting up the cross compiler or compiling natively), it's not more simple than just typing apt-get install qtcreator qt5-default, which installs the ide as well as the dependencies. Yes, I'm going to be missing some of the new features in 5.8, but my goal right now is to create automation controls. The next iteration will be to make them more whizbang.

Also, I'm going to compile the qt projects natively on the Pi. I'm not going to worry about setting up a cross compiler environment for the time being. I'm going to use SCP to copy the qt project over to the pi, then compile the project natively. The process is simple enough SCP -> qmake -> make -> run the program. I'll detail the build steps in greater detail.

Hardware Setup

Adafruit makes these nice little TFT shields for the Raspberry Pi. The frame rate may be on the low side, but the compactness is pretty awesome. I may switch over to a small HDMI screen to see if there is a performance boost. Adafruit also makes a similar product, but with an HDMI screen.
The touch screen is a resistive film type and seems to have good enough resolution to poke even the smallest of window controls. A stylus is a good addition for this screen or make sure your style your buttons large enough for fat fingers like mine.

Software Setup

For the interface side, I'm going to rely on Qt's awesome qml. It's flexible, fast, and anchoring. Anchoring is everything you wish HTML had. Here's a novel idea in qml, centering something in a container is easy. What a thought....

If you've never seen qml before, I recommend you find a tutorial online. The official Qt documentation is quite good. I'll throw in the practical bits on hooking things up.

Thursday, April 13, 2017

Home Automation Controls - Raspberry Pi - QT

Home automation is a great way to tinker and learn some new skills. I'm going to use Qt and its fantastic UI system and the Raspberry Pi to build some nice interfaces and controls for my home.