Table Of Contents

Previous topic

gadgets.devices

Next topic

gadgets.sensors

This Page

ShiftRegisterSwitch

class gadgets.devices.switch.shift_register.io.ShiftRegisterIO(addresses, channel)[source]

Implements the gadgets io api (on, off, close, and status) see gadgets.io.io.

A Beaglebone has lots of gpio pins available, so why use a power logic shift register (such as a TPIC6B595)? The gpio pins cannot provide enough current to power much more than a transistor. So if you want to turn on a sollid state relay or a solenoid then you need to use a transistror or mosfet. The use of the shift register elminates the need for transistors in many cases. Also, you can chain multiple shift registers together and get many more gpio pins than you could get with a single beaglebone:

>>> from gadgets import get_gadgets
>>> arguments = {
...     "locations": {
...         "back yard": {
...             "sprinklers": {
...                 "type": "shift register switch",
...                 "channel": 3,
...                 "on": "water {location}",
...                 "off": "stop watering {location}"
...            }
...         }
...     }
... }
>>> gadgets = get_gadgets(arguments)

Note that you can pass in an ‘on’ and ‘off’ argument for a device. This allows you to turn the device on with a command other than the default. The default on and off commands in this case would have been ‘turn on back yard sprinklers’ and ‘turn off back yard sprinklers’. Now in another terminal:

>>> from gadgets import Sockets
>>> sock = Sockets()
>>> sock.send('water back yard for 10 minutes')

XBee

class gadgets.devices.switch.xbee.io.XBeeIO(addresses, channel, address)[source]

Implements the gadgets.io interface for XBee switches.

Why XBee? Gadget systems can be distributed across many BeagleBones or Raspberry Pis. However if all you need is some remote Switch objects, it may be cheaper to use xbee radios. XBee series 2 modules have 9 gpio pins each, and by using API mode you can control multiple remote XBee modules with a single XBee coordinator connected to your Beaglebone or Raspberry Pi. The XBee modules do not need to be connected to a microcontroller, so all you have to do is provide power. That should be less expensive than buying a Raspberry Pi along with a power supply, sd card and WiFi dongle.

Here is an example:

>>> from gadgets import get_gadgets
>>> arguments = {
...     "locations": {
...         "back yard": {
...             "gnome": {
...                 "type": "xbee",
...                 "channel": 3,
...                 "address": 0x0013A200409825C1,
...                 "device": '/dev/ttyUSB0',
...            }
...         }
...     }
... }
>>> gadgets = get_gadgets(arguments)

Address is the address of the XBee. One way to find the address is to look at the label on the bottom of the module. It will look something like this:

 ---- 004-revE
|bar |0013A200
|code|409825C1
 ----

You combine the middle line (address high) with the bottom line ( address low) to come up with the address that you use as an argument in the example above.

Before any of the above will work, you need two XBee series 2 modules - one connected to the BeagleBone or Raspberry Pi, and one one that is connected to the physical devices that you wish to control. The one connected to the gadgets system must be running the ‘coordinator api’ firmware and the remote XBee(s) must be running ‘router at’ firmware. They must also be configured with the same pan id.

Now you can turn it on by creating a socket and giving the switches a RCL command:

>>> from gadgets import Sockets
>>> s = Sockets()
>>> s.send("turn on back yard gnome")

NOTE: XBeeIO depends on pyctu for its XBee API mode communication:

$ easy_install pyctu