Things used in this project

Hardware components

Software apps and online services

ngrok

Story

This project began last year as a fun freshman design project at Drexel University, that continued into the summer on my own time. It has a ways to go, but basic functionality is proven.

Currently looking for help with debugging/testing. Also would appreciate help from any web developers or especially Javascript developers to improve UI and backend and also to add better task scheduling functionality.

The software design is based around a JSON file. This file allows changes to the hardware devices that are attached to the Pi to be easily updated. The software renders the GUI and initializes GPIO pin on the Pi based on this file. Below is a sample of the instruction manual that was written last spring.

Adding Entries to device.json

In the main directory of this
project is a file called “device.json”. When a client connects to
the Node.js server, the server parses this file into a Javascript
object, and packages this information into websocket data to send to
the client. The entire system is based on the information contained
in this file. The HTML control.html file does not contain any device
specific information, it is simply a skeleton structure that allows
the client-side javascript (contained in the /js/control.js file) to
parse the data sent over websockets, and draw the page using
JavaScript. This makes it relatively easy to add and remove devices
from the Pi. By simply editing this file the whole interface is
redrawn to accommodate those changes.

{

"pin" : 2,

"state" : "out",

"name" : "Alarm",

"id" : "buzzer"

},

{

"pin" : 27,

"state" : "in",

"name" : "Button",

"id" : "button",

"highmsg" : "Button pressed",

"lowmsg" : "No change..."

},

These are two examples of an object found in the device.js file. All
objects must contain a “pin” key matched with an integer value.
Pin corresponds to the GPIO pin on the Pi that the device is
connected to, should be an integer.
Note that there are two numbering systems used to refer to Rpi GPIO
pins. The Pi has 40 pins, while referencing the relative position of
pins, the board is always oriented so that the pin header is in the
top right of the board. One numbering method numbers each pin from
1-40, starting the with top left pin as pin 1 (THIS IS NOT THE SYSTEM
USED BY DEVICE.JSON). The numbering
method used by the device.json
file uses an arbitrary
numbering scheme that is dictated by the processor design
and follows no logical order on the pin header. Use the image below
to determine the pin that your device is connected to. Use the
integer that is prefixed with “GPIO”.

The first JSON entry above is an input object. For each output
device connected the object must contain these fields: pin,
state, name, id.

pin is the GPIO pin that the device is attached to, this pin
can either be high (3.3V) or low (0V aka ground)

state is either “in” or “out”, we are discussing
output device here so this should be “out”

name is the string that will be displayed on the site
interface. It can be anything but should be relatively short (so the
page layout is not negatively impacted) and unique

id must also be unique. This should be very short, less than
6 characters, and descriptive of the device that is connected. This
value will be used in the schedling interface to refer to the
devices that will change state on a certain date.

The second object above is an input object. Output objects
contain the same four keys of the input, however they add two more
keys: highmsg and lowmsg

state is “in”

highmsg should have a string value that will be displayed
when the state of the input pin is high.

lowmsg should have a string value that will be displayed when
the state of the input pin is low.

The syntax of these objects is called JSON, aka JavaScript Object
Notation. This syntax is very picky. If it is incorrect your object
will not behave properly. Use http://jsonlint.com/
to check your JSON syntax before uploading. And check out W3 schools
http://www.w3schools.com/json/
for more information on JSON.

Physically attaching a device to the Pi

What kind of device do you want to
attach? It could either be an input (i.e. a sensor, or something
that will take measurements of the surrounding environment) or and
output (i.e. something that interacts with the surrounding
environment, like an led or buzzer, or relay).

The device's power requirements
are an important consideration. The raspberry pi can only supply so
much power. If too much power is drawn by an output device, your
system could experience sporadic behaviors (especially “brownouts”
where too much power is drawn and the system shuts down for a
fraction of a second, appearing to spontaneously reboot). Find out
the power requirements of your device. If the device has 3 wires the
wires will be attached to power(+5V or +3.3V), Ground (0V), and
GPIO. If there are two wires (such as an LED) the device could
possibly be driven directly from the GPIO but not without a series
resistor to limit current. Check the device's datasheets to see
which pin/wire corresponds to what. If your 3-wire device is a 5V
device it can likely be powered directly from the 5V rail on the Pi,
just plug the +5V (aka VCC) pin into the 5V pin on the Pi's header.
The 3.3V header is limited to a total current draw (for all devices)
of 50 mA. Do not exceed this. You may have to use external power for
3.3V devices.

The GPIO pins can supply 3.3 volts
and a MAX of 16 milliamps each. However, in my opinion, you should
not attempt to draw anywhere close to 16 mA from a GPIO pins. For
more information on powering devices from the Pi see:
(http://raspberrypi.stackexchange.com/questions/9298/what-is-the-maximum-current-the-gpio-pins-can-output)

Make sure that the power supply
for the Pi (the wall socket with a micro-usb cable) can supply atleast 1.2 amps and 5 volts. Better yet play it safe and get a 2 amp 5 volt
charger, most modern phones (including the iPhone) ships chargers
capable of supplying this amount of power.

If
you want to connect an LED, find an online resistor calculator, or
use pen, paper and Ohm's law (Voltage = Amperage*Resistance), to
calculate the appropriate resistance for the LED. Keep in mind the
16 mA limit, and how many other devices will be connected.

For
5 volt, 3-wire devices (input or output), connected ground to
ground, +5V to +5V, and signal(input or output) to the GPIO pin (as
recorded in device.json). Keep in mind that if your 5V device draw
more than 100mA (or so) you may need to build an external voltage
regulator, see step 8. Note that the power limit for 5V devices is
limited by the amount of power available over the USB supply into
the Pi, there is allot more leeway around 5V devices than there is
for 3.3V devices.

For
3.3V 3-wire devices, if the power requirement fit within 50mA for
ALL 3.3V devices, connect the +3.3V to +3.3V, ground to ground, and
signal to the GPIO pin (as recorded in device.json).

If
3.3V device draws more than 50mA, get a breadboard (or protoboard)
and put together a simple 3.3V regulator circuit with a few dollars
worth or parts. Look online for instructions on how to do this. When
complete plug the +3.3V power pin of the device into the +3.3V
output from the power regulator on the external circuit. (this can
also apply to 5V, just get a 5V regulator instead).