Description, walkthrough and code for building an energy feedback appliance for Prince Edward Island.
The code in this repository and the README file you are currently reading are designed to guide the development of a simple, low-cost energy feedback appliance. The appliance described in this guide is an easy-to-build and low-cost system that aims to help people become aware of the sources of electricity they are currently using and allow them to adjust their daily consumption practices based on this information.
This guide provides instructions to allow others to build their own energy feedback device, including what hardware is needed, how to assemble the hardware, how to install free software on the hardware, downloading code to capture and display realtime data on electricity usage, and designing and 3D printing an enclosure to enclose and protect the components.
The end appliance should could look like the picture below. It is meant to sit in a visible area, and require only one cord for power. Once configured, it will communicate wirelessly with a router to access realtime data on the Web that it will display using its 2.3" touch screen. If touched the touch screen will cycle through charts displaying the energy usage and sources used on the Island for the last day.
Prince Edward Island (http://www.gov.pe.ca) has three sources of electricity: nuclear generated (imported from New Brunswick), wind-generated (from on-Island turbines), and a diesel generated (used to meet demand when the previous two sources cannot meet demand). The problem is that there is only a fixed amount of reliable electricity that makes up the majority of electricity used on Prince Edward Island (from nuclear energy). The capacity of the cables that carry electricity to the Island from New Brunswick is 200 MW [1]; however, the peak demand on the Island reached an all-time high of 252 MW [2]. This means that wind and the fossil fuel generation must make up the remaining demand above 200 MW. The problem faced on the Island is that wind is a periodic energy source and cannot always make up the difference between the demand over what is imported. The fossil fuel generator is in place to meet the remainder of the demand, but is not a desirable alternative for several reasons: the cost of maintaining the fossil fuel generator is extremely high, fossil fuel is increasingly expensive, and when the generator is turned on it releases a considerable amount of air polution. In addition, in January 2014, there was a failure to meet the peak demand because of a problem with the fossil fuel generator and a rolling blackout was put in place to avoid a total blackout [3].
This encouraged us to consider consumer devices that might allow people to have a better idea of when they can adjust there energy consumption during critical times on the Island, and perhaps even to target their higher-energy consumption activities (e.g., using the dishwasher, the clothes dryer, etc.) when overall demand is low (and there no fossil fuel being generated), and energy from "clean" sources is high (i.e., wind generation). There are several existing consumer devices that allow people to improve their energy consumption based on receiving feedback at the household level, and, in some cases, allowing for comparing consumption with houses of similar sizes, houses near by, or with personal history. However, rather than a focus on providing feedback on an individual household's consumption, this appliance is designed to provide feedback-based on the source of energy, based on real-time data about the Island's current energy consumption.
The goal of this guide is to allow anyone who has at least some comfort with computer technology to be able to build this device, or a device very similar to this one. It is assumed that you have at least some basic knowledge about how to download and unzip files, copying files, and are confident enought to type in and execute some simple commands at the command line. The only other thing you will needs is the ability to follow some directions, some free time (altogether this might take about 6 hours to get up and running), and some money to pay for supplies.
The guide has been designed to be read and followed sequentially, although skipping sections is possible. People who have at least some experience with programming, Linux operating systems, or computer electronics may feel more comfortable to customize their feedback appliance, but such experience should not be necessary.
The parts in grey boxes you see are commands that you will enter at the console prompt of your Raspberry Pi. These should be entered exactly as you see.
The project as described does require some basic soldering. Soldering is not that difficult and there are many very comprehensive videos on YouTube that do a good job of introducing the basic soldering equipment and techniques needed for this project. Here are two that we found helpful: Soldering Tutorial Part 1 and Soldering Tutorial Part 2.
If you get stuck, please contact me (@scottbateman) and I can hopefully provide some guidance.
To make building an energy feedback system as easy as possible we sourced all of the parts used in the project from Adafruit Industries. While it may be possible to order parts from other suppliers and save some money, we have found Adafruit reliable and they also offer tutorials and documentation with the parts they sell. This can greatly facilitate making use of the parts.
Below I outline all of the parts used in this project at the time of writing. It is assumed that you will also have a monitor with and HDMI connection and cable, a USB keyboard, and WiFi internet.
- Raspberry Pi - this is the computer and the brains of the operation
- WiFi Adapter - to connect to the internet wirelessly
- 5V 1A (1000mA) USB port power supply - to provide power
- Micro USB Cable - to connect the Pi to the power supply
- 8GB SD Card with OS Installer - this is the storage for the Pi, including the OS and all the files
- PiTFT Mini Kit - 320x240 2.8" TFT+Touchscreen for Raspberry Pi - this will provide the small display for displaying our energy information and interacting with the appliance once our project is complete.
- PiTFT Enclosure for Raspberry Pi Model B - a low-cost case that nicely enlcoses the pi and screen.
There are a number of operating systems (or OSs, that provide the basic software) available for the Raspberry Pi. We used Raspbian for this project beacuse it is the most popular, and, possibly, the most well-supported. Raspbian and the other OSs are Linux operating systems that provide the basic software to use hardware and perihpherals (including keyboards, mice, monitors, etc), and to run other software. This software includes a Windows manager that looks and behaves very much like Windows or Mac OS X. However, it is disabled by default and this project won't be using it. Rather this guide and system has been designed to run completely at the default command prompt.
To install Raspbian for your Raspberry Pi, you will need an SD Card with a capacity of at least 4GBs. You will need to first format the SD Card (i.e., delete all the files and make it ready to have an OS installed on it), and then download and unzip the NOOBS software, and copy the NOOBS software onto your SD card. You will then insert your SD card and follow the onscreen directions to install Rasbpian. If you purchased the SD Card recommended above, then you can skip down to the "Installing Raspbian" section.
To setup your SD card, the basic steps to follow are these (taken directly from the Raspberry Pi Download site):
- Format your SD card using the SD Card Association’s formatting tool, which can be downloaded here.
- Download and unzip the NOOBS zip file onto the SD card: [NOOBS download](Raspberry Pi Download site)
If these instructions are too vauge for you then Adafruit has a great walkthrough with images for preparing your SD Card.
Once your SD card is setup you are then ready to setup Raspbian on your system. You will now need to insert your SD Card into your Pi, attach a monitor using an HDMI cable (or a TV using an RCA cable), attach your USB keyboard, your USB wireless adapter, and finally your power cord. Once you attach power to the Pi it will startup. You will then use your keyboard (via the arrow, tab and enter keys) to select the Raspbian system to be installed.
Here are some pictures detailing what you should see.
The installation process takes a little while, but once everything is completed the Pi will restart and prompt you for a username and password. The default login is:
username: pi
password: raspberry
This guide and the provided software have all been designed to run from the command prompt, so the windows manager (the graphical interface that looks like Windows or Mac OS X) while available is not needed. You can always give this windows manager a try by typing in startx
at the prompt. However, you should have a mouse attached to give it a try.
One thing you may want to do is to activate the Pi's sshd program. This program allows you to easily connect to your Raspberry Pi and run software on it from another computer, even when it has no monitor or keyboard attached. The only requirement is that your Pi is running, it has sshd running, you know the network address of your Pi, and you have another computer on the network (with a monitor and keyboard) that you can use to connect to the Pi. This step is not necessary, but after you have completed this guide, you may want to be able to connect your Pi to update its software, use it for other purposes, or to learn how it works; having sshd available makes connecting to your Pi easy. Adafruit provides a guide for setting up sshd and connecting to your Pi from another computer.
I have had a problem with getting the wireless adapter to connect to both my home and the University networks using the default wireless service in Raspbian. If this is the case for you, the the easiest way I found to get around this was to install a new wireless networking service called, wicd. However, to do this you will need to find a wired ethernet port to connect your Pi to the Internet. This will allow you to download the software needed to more easily connect to your wireless network. To do this just run the following at the command prompt:
sudo apt-get update
sudo apt-get install wicd
sudo apt-get install wicd-curses
The first install command will provide the basic wicd software and also provide you with a graphical interface for when you are using Raspbian's GUI. The second command will install a command line interface for working with the wicd software. Since, we are working at the command prompt we will use wicd-curses.
You will then need to configure wicd, by typing the following:
wicd-curses
You will then get and interface that will allow you to select your wireless network:
- use the 'up' and 'down' arrow keys to select it from the list
- press the 'right arrow' key to configure your network
- the main thing you will need to do is to enter your wireless network key (in the line marked Key)
- to have your network connect automatically from now on, select the appropriate line and press space bar to mark the option
- once you have configured you can hit 'F10' key to save
- you will then need to use the arrow keys to select your newly configured wireless network and hit 'enter' to connect
- you will see status messages that describe your progress in connecting at the bottom of the screen
- when you are connected, you can press Q to quit the wicd-curses interface.
If you get lost at any point here is a good walkthrough to get wicd installed: [http://dembtech.blogspot.ca/2012/09/how-to-install-wifi-on-raspberry-pi.html](A Walkthrough with pictures of setting up wicd)
You should always keep your OS and software up to date, and once your Pi is connected to the Internet. Raspbian and all of the software it contains are often updated to take care of any security problems or fix any bugs. To update your Raspbian OS and software, you can run these commands at the prompt:
sudo apt-get update
sudo apt-get upgrade
Ultimately, your touch screen will work by simulating a mouse a click when you touch the screen, and display images to present the current energy information. However, we are working in the console and we don't have a windows manager that usually handles the jobs of displaying windows, buttons, images and the mouse cursor. So, to get a mouse and the ability to display images in the console, we will just need to install a couple of small pieces of software called GPM (for the mouse) and fbi (for the images).
sudo apt-get update
sudo apt-get install gpm fbi
After GPM is installed, and provided you have a mouse connected to your Raspberry Pi (you might not if you already have a keyboard and your wireless adapter connected), the you would be able to see your mouse cursor as you move it around the screen. If you don't have a mouse attached, no worries, the software is installed and waiting for your finger to do its job once we have the touch screen attached.
To be able to get information from the Web about current power production and consumption, we will use Python. Python comes pre-installed with Raspbian, but it does not yet know how to talk to the LEDs we will be wiring to the Pi to provide our visual feedback. We simply need to add a few libraries to make this possible:
sudo apt-get update
sudo apt-get install python-dev
sudo apt-get install python-rpi.gpio
Next we will need the software that downloads current energy usage data for the Island and displays it on the touch screen. This software is all written in the python scripting language and your Raspberry Pi already knows how to run this software, we just need to download it.
To download the software, unzip it, and give it a easy to type name (energy-app) run the following commands:
cd /home/pi
wget https://github.com/scottbateman/pei-energy-feedback-thingy/archive/master.zip
unzip master.zip
ln -s pei-energy-feedback-thingy-master energy-app
Next we need to make sure this code starts automatically as soon as the Pi starts up and is ready to go (which takes about a minute, once the power has been connected). To do this we need to tell the Pi to login and run our script automatically. The directions we used are from: http://elinux.org/RPi_Debian_Auto_Login
First type at the command line:
sudo nano /etc/inittab
Then go down to the line that says:
1:2345:respawn:/sbin/getty 115200 tty1
and tell the system to ignore the line by adding a # character at the front:
#1:2345:respawn:/sbin/getty 115200 tty1
and on the very next line add
1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1
Press Control+X to exit and Y to save your file.
Now when you reboot your Pi should login automatically. The next step will be to get our code to run automatically. To do this:
nano /home/pi/.bashrc
At the very bottom of the file add in a line:
/usr/bin/python /home/pi/energy-app/lib/main.py
Press Control+X to exit and Y to save your file.
Adding the screen takes a litle bit of work, but the instructions provided in this tutorial are really clear and comprehensive: [Add a compact 320x240 resolution screen to the top of your Pi] (http://learn.adafruit.com/adafruit-pitft-28-inch-resistive-touchscreen-display-raspberry-pi)
By default the screen will shutdown after about 30 minutes. To prevent this, you can disable the behaviour by doing the following:
sudo nano /etc/kbd/config
Change the following lines (located at different spots in the file):
# screen blanking timeout. monitor remains on, but the screen is cleared to
# range: 0-60 min (0==never) kernels I've looked at default to 10 minutes.
# (see linux/drivers/char/console.c)
BLANK_TIME=0 #(Was 30)
# Powerdown time. The console will go to DPMS Off mode POWERDOWN_TIME
# minutes _after_ blanking. (POWERDOWN_TIME + BLANK_TIME after the last input)
POWERDOWN_TIME=0 #(I think it was 15)
The enclosure that we recommended above is ideal because it fits around the Pi and the screen quite nicely. This will protect your Pi and make sure all the coponents are safe. Simply assemble your case and secure your Pi inside.
Your project is all completed. The only thing left to do is to find a good spot for Energy Feedback Thingy, plug it in an enjoy.
The software in this repo is released under the MIT License (please see the included license file). This readme file should be as work licensed under a [Creative Commons Attribution-ShareAlike 3.0 Unported License] (http://creativecommons.org/licenses/by-sa/3.0/).
This project was completed in collaboration and based on the extensive previous work of Peter Rukavina at Reinvented, see Peter's Prince Edward Island Energy Dashboard. In completing this work for Reinvented, Scott Bateman received funds into a research account at the University of Prince Edward Island to pay for the equipment used in the development of this project and to fund future research activities. This funding was provided through the NRC-IRAP programme. Additional support for this work was made available through the GRAND National Centre of Excellence and SurfNet.