unnamed

 

 

Using the open source software OpenHAB, we’ll be building a Raspberry Pi touchscreen command center that can interface with over 150 different “smart home” products, and provide an interface for control and task scheduling. Instead of using an existing product though, we’ll build our own WiFi enabled RGB LED strip that interfaces with OpenHAB, allowing you to wirelessly control it from your smartphone or any computer on your network.

OpenHAB is great because it interfaces with so many products, it’s free, it’s open source, and extremely flexible. It also runs on Windows, OS X, and Linux, so you don’t necessarily have to use a Raspberry Pi for this project. If you have an old laptop or desktop kicking around, you can just as easily run the same setup.

We also want to thank Arrow Electronics for sponsoring this build. They’ve given us access to their vast inventory of electronic components in order to make this project series possible. We’re super excited to share what we’ve come up with!

The main parts for this build are a Raspberry Pi and touchscreen, as well as the components used to control the NeoPixel strip. You can purchase the components from Arrow, or other online electronics vendors. You’ll also need a few tools for soldering and programming the microcontroller.

 

What will the next generation of Make: look like? We’re inviting you to shape the future by investing in Make:. By becoming an investor, you help decide what’s next. The future of Make: is in your hands. Learn More.

Project Steps

Assemble the Raspberry Pi and touchscreen

Without instructions, assembling and attaching the screen to the Raspberry Pi can be a bit tricky.

Start with the screen face down and flip the display controller board over so that the large connector is visible. Connect the large ribbon cable from the screen to the controller, being sure to push the cable in fully and securing it with the clip on the connector.

Flip the display controller board onto the back of the screen, and push the small touchscreen cable into its connector. Screw the standoffs into the back of the screen, through the holes in the controller board.

Insert the ribbon cable into the display connector on the side of the controller board, then place the Pi on top of the standoffs and screw it in. Connect the other end of the ribbon cable to the display connector on the Pi.

In order to run power and ground to the touchscreen, we’ll use the GPIO pins on the Pi. Take the red jumper wire that came with the screen, and plug it into the rightmost lower 5V GPIO pin on the Pi, then plug the other end into the rightmost pin on the controller board below it. Use the black jumper wire to connect the GPIO GND pin (two pins over from the red wire 5V pin) on the Pi to the leftmost pin on the controller board below it.

Setup the microSD card and configure Raspbian

Download the latest build of Raspbian from the Raspberry Pi website and flash it onto a microSD card. Then insert the card into the Pi.

Plug in a keyboard, mouse, and wifi adaptor, then insert the card into the Pi and boot it up.

Go through the configuration process, and when it’s fully booted, connect to your WiFi network.

In order to get the touchscreen to work, you’ll likely need to run a few commands from the command line to update Raspbian:

sudo apt-get update
sudo apt-get upgrade

This will probably take a while, so be patient!

If you restart the Pi after the update, the touchscreen will flip upside-down. If that’s a bother to you, you can flip it by adding lcd_rotate=2 to the last line in the config file in the boot folder, using the following command:

sudo nano /boot/config.txt

Then hit Ctrl+X to save and exit.

Install OpenHAB

Now it’s time to install our home automation control software, OpenHAB, and the OpenHAB addons we’ll be using.

Open a command line on the Pi, and enter the following commands:

sudo mkdir /opt/openhab
cd /opt/openhab
sudo wget https://bintray.com/artifact/download/openhab/bin/distribution-1.7.1-runtime.zip
sudo unzip distribution-1.7.1-runtime.zip
sudo rm distribution-1.7.1-runtime.zip

Now we’ll enter a few more commands to configure OpenHAB to run at startup:

sudo wget http://www.element14.com/community/servlet/JiveServlet/download/38-152207/openhab.zip
unzip openhab.zip
sudo rm openhab.zip
sudo cp openhab.sh /etc/init.d
sudo chmod 777 /etc/init.d/openhab.sh
sudo update-rc.d -f openhab.sh defaults

We’ll also need to install the OpenHAB MQTT addons, since that’s the protocol we’ll be using to communicate with our LED strip:

sudo wget https://bintray.com/artifact/download/openhab/bin/distribution-1.7.1-addons.zip
sudo unzip distribution-1.7.1-addons.zip -d /addons
sudo cp /addons/org.openhab.binding.mqtt-1.7.1.jar /opt/openhab/addons
sudo cp /addons/org.openhab.persistence.mqtt-1.7.1.jar /opt/openhab/addons
sudo rm distribution-1.7.1-addons.zip

Install the MQTT broker

As we mentioned, we’ll be communicating with our LED strip using a protocol called MQTT. In order to set this up, we’ll need to install Mosquitto, an open source MQTT broker.

To install Mosquitto, enter the following commands in the command line:

sudo wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
sudo apt-key add mosquitto-repo.gpg.key
cd /etc/apt/sources.list.d/
sudo wget http://repo.mosquitto.org/debian/mosquitto-wheezy.list
sudo apt-get update && sudo apt-get install mosquitto

Install the OpenHAB configuration files

Finally, download our pre-made OpenHAB configuration files, and install them in the associated OpenHAB folders.

(See the included README file for folder locations for each file)

Soldering the ESP8266 header pins

With OpenHab set up on our Raspberry Pi, it’s time to switch to building our NeoPixel strip controller. The cheap, WiFi enabled Adafruit ESP8266 HUZZAH board is perfect for this.

First, solder the provided header pins to the board so we can program it using an FTDI adaptor.

Soldering the logic level converter

Because the ESP8266 uses 3.3 volt logic level instead of the NeoPixel strip’s 5 volts, we’ll need to solder a logic level converter between them.

On the low level side of the converter, solder a wire from pin 2 from the ESP to A1, another from pin 3V to LV, and a third from GND to GND. On the high side of the converter, solder a wire from pin B1 is to the NeoPixel data pin wire (that’s the striped wire on the NeoPixel connector), and another wire from GND to GND. Solder a red wire to the HV pin on the converter, and another red wire to the V+ on the ESP.

The male end of the NeoPixel strip will provide power for the ESP, so solder the red wire from the strip to the red wires coming from the V+ and HV pins, then solder the black wire to GND. After that, plug the NeoPixel strip into the wall with the provided cord, and make sure that the ESP is getting power by hitting the reset button to see if the onboard LED flashes.

Setting up the Arduino IDE

With everything wired up, it’s time to flash the ESP using the Arduino IDE. First we need to make some changes to the Arduino IDE though.

Download the PubSubClient library from https://github.com/Imroy/pubsubclient, and extract the folder into the Arduino libraries folder.

Open the Arduino IDE, then go to Sketch > Include Library > Libraries Manager… and install the Adafruit NeoPixel library.

Finally, we’ll add the Adafruit HUZZAH ESP8266 board to the boards list. Go to Arduino > Preferences, and add “http://arduino.esp8266.com/stable/package_esp8266com_index.json” into the Additional Board Manager URLs field and click OK. Go to Tools > Board: > Boards Manager… and install the ESP8266 package.

Flashing the ESP8266

Download and open the provided Arduino sketch, then edit the sketch to include your WiFi network settings and Pi IP address. You can check your Pi’s IP address by typing “ip addr show” into the command line.

Connect your computer to the ESP with an FTDI cable, and set your board and port in the Arduino IDE. Put the ESP into programming mode by holding the GPIO0 button down and pressing the Reset button, then upload your code.

After it’s flashed, open the serial monitor and make sure that the board connects to your WiFi network successfully.

Install the OpenHAB tablet or mobile app

With OpenHAB configured, and our NeoPixel strip on the network, it’s time to test it out!

Download the OpenHAB app to your phone or tablet (it’s available for both Android and iOS), then open it and select Settings in the upper right corner. Change the OpenHAB URL field to your Pi’s IP address, followed by a colon and 8080. Exit the menu, and your phone should connect to OpenHAB, bringing up your LED controller.

Alternatively, you can also control the LEDs from any computer on the same network (including the Pi) by entering the Pi’s IP address, followed by “/openhab.app?sitemap=home”.

If you need to troubleshoot, you can install the Chrome app called MQTTLens to verify that OpenHAB is sending out MQTT messages. Just edit the settings to point to the IP address of the Pi, and add a subscription to the topic # to see all MQTT messages the Pi is sending.

Play!

OpenHab is extremely versatile, and we’ve only just scratched the surface of what it can do. You can control things with voice commands, monitor sensor networks, and even set up rules for automating devices from email or IFTTT. In the next few videos, we’ll show you how to build other cool devices that connect to OpenHab and make your house even smarter.