Step #1: Assemble the Raspberry Pi and touchscreenPrevNext
- 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.
Step #2: Setup the microSD card and configure RaspbianPrevNext
- 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.
Step #3: Install OpenHABPrevNext
- 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
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
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
Step #4: Install the MQTT brokerPrevNext
- 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
sudo wget http://repo.mosquitto.org/debian/mosquitto-wheezy.list
sudo apt-get update && sudo apt-get install mosquitto
Step #6: Soldering the ESP8266 header pinsPrevNext
- 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.
Step #7: Soldering the logic level converterPrevNext
- 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.
Step #8: Setting up the Arduino IDEPrevNext
- 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.
Step #9: Flashing the ESP8266PrevNext
- 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.
Step #10: Install the OpenHAB tablet or mobile appPrevNext
- 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.
Step #11: Play!PrevNext
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.