Monthly Archives: April 2016

Control an LED from the Internet part 1

XBee – XIG – Arduino Remote Control of Things

Our goal is to control Things over the internet. If we can control an LED – we can control anything. We’ll start with an LED to make this as simple as possible and then move on to controlling a servo motor. By the end of the series we’ll have created a web app to control our things.

The basics steps to control devices from the internet are relatively simple – the complexity is in the details. In this post we abstract away much of the complexity so we can get to controlling an LED.

If this is your first attempt at using XBee radios you might want to check out a simple chat tutorial first. Or you can skip that and hit this with a hammer until it works – my method anyway.

Parts

I’ve linked to sparkfun.com – look around net for cheapest price. You can find Arduino kits on Amazon which will contain some of the components below…
Ardunio Kit

2 – XBee series 1 801.15.4 radios  – any XBee series is fine.
https://www.sparkfun.com/products/8665

1 – XBee Explorer (either one will do)
https://www.sparkfun.com/products/11697
https://www.sparkfun.com/products/11812

1 – XBee breakout board (maybe get 2)
https://www.sparkfun.com/products/8276

1 – Header Pins (maybe get 2 or more… always useful)
https://www.sparkfun.com/products/116
Note: you need to solder the header pins to the breakout board. You can find others on the internet if you don’t want to solder but these are inexpensive. If you are heading down the IoT road – time to learn to solder. Make sure you note which side is up on the breakout board before soldering.

A basic soldering iron is inexpensive – don’t forget solder and flux. Some desodlering braid is also useful if you make a mistake while soldering and need to desolder – it happens )

Many tutorials out there on soldering header pins. Easy way is to put the headers pins into a breadboard to hold in place while you solder the breakout board. Some ‘helping hands’ are helpful and inexpensive.

1 – Breadboard
https://www.sparkfun.com/products/12002

Jumper wires (you can never have enough – 22 gauge wire would do instead)
https://www.sparkfun.com/products/11026
https://www.sparkfun.com/products/12794

1 – 2-AA Battery Holder (If you have an arduino you can use its 3.3v supply)
https://www.sparkfun.com/products/9925

1 – LED (or get a few – many LED kits out there)
https://www.sparkfun.com/products/9590

Note: If you want to control a servo add the following.

1 – Arduino Uno or clone
https://www.sparkfun.com/products/12757

1- Servo Motor (Any will do)
https://www.sparkfun.com/categories/245

1- LED pack
https://www.sparkfun.com/products/12062

Configure XBee Radios

The first radio will be used as our gateway. This needs to be connected to a computer running the XIG (XBee Internet Gateway). XIG is a python program that handles commands sent from Device Cloud. Device Cloud is an IoT (Internet of Things) web service. We can use Device Cloud to shuttle commands from the internet (http web requests) to the XIG and on to our XBee radios.

HttpToThings

Note: You should reset both radios before starting – unless they are new.

Download XCTU -> Start the program, -> Insert a radio to the XBee explorer -> connect to a USB port. Follow the steps below.

  1. Click Add Radio Button -> Select radio USB port –> Choose Finish
  2. Select Radio to add to Configuration Panel.
  3. Click Default Button
  4. Configure the following settings. Note the search box helps to find the parameter to change…

XIG Gateway Radio Settings – Label this somehow – scotch tape with a X
ID:          3332
AP:         1
D6:         0

Arduino/LED Radio Settings (Note do this after the first radio is done through step 5)
ID:          3332
DH:         13A200
DL:          Set to SL of XIG Radio above
D0:         4 – Low

  1. Click the Write button to write new parameters

XCTU

Wire up the Remote XBee Radio

  1. Place your Arduino/LED radio into your breadboard.
  2. I’ve use an Arduino  below to power the XBee – you can use 2 AA batteries if you choose. Check the power requirements of your radio – I’ve fried one before.Note: Make sure you confirm your XBee pins on the breadboard. Place the XBee in the breakout board and then insert into breadboard. A mulitmeter allows you to check continuity but is not necessary.  Don’t need to get an expensive one. I’m still using one I bought 20 years ago for 10 bucks. Although it’s time for me to upgrade )

XBee Led

XIG

  1. Download XIG v 1.5.1 – Choose the appropriate version for your OS – I’m using xig-windows-1.5.1.zip. Unzip the file (don’t worry about any encryption error when unzipping).
  2. Place your XIG radio in an XBee explorer and plug into a USB port.
  3. Open the XIG folder, delete ‘settings.json’ file and then run the file xig_app.exe.You will get an error when you run the first time. Shut down the web browser and the console window. The file ‘settings.json’ will have been recreated. Open the json file and make the following change. Change “idigi_certs_file” to  “” – just remove idigi_certs_file and leave the blank quotes. Now run the file xig_app.exe again.This will run XIG (XBee Internet Gateway) so we can send commands from the internet to the XBee attached to the computer and then on to the XBee on the breadboard.
  4. Once you run xig_app.exe a browser window will open. Select the appropriate Baud Rate (9600) and COM port (whichever one you connected the XBee too). Once you see a green button in the upper right you are connected. Note the Device ID on this page – you’ll need it in Device Cloud to add the device.

Device Cloud

  1. Create a Developer Account in Device Cloud (It’s free) –> login.
  2. Choose Device Management tab -> Add Device
  3. Select ‘Device ID’ form the drop down list and paste in the Device ID you copied from the browser window and select ‘Add’. If you get an error saying the device exists. Close the XIG app, shut down the XIG browser window, delete ‘settings.json’  in the XIG folder and run xig_app.exe again. Then repeat step 3.
  4. You should now see your device listed in the Device Management tab. Note you might need to refresh a few time before the device status icon turns from red to blue (connected).

Test Your Connection

  1. In Device Cloud choose Documentation -> API Explorer
  2. Select ‘SCI Target’
  3. Choose Device from ‘Add Targets’ dropdown -> Add -> OK
  4. Choose Examples -> SCI -> Python Callback
  5. Update code to match below.
    1. Your device id will already be set to id of XIG device
    2. Edit target to “xig”
    3. Change the hw_address x’s entries to match the DL of the Arduino device
      <at hw_address=”00:13:A2:00:xx:xx:xx:xx!” command=”D0″ value=”5″ />
  6. Hit send. You’ll have to login to Device Cloud the first time you test. Your LED should turn on. If it doesn’t have patients and start checking all steps. This is not for the faint of heart.
  7. Once you get the light to turn on change value=”4” – this will set “D0” to low and turn LED off.

SCI Example

Downloads

Device Cloud: http://www.digi.com/products/cloud/digi-device-cloud

XCTU: http://www.digi.com/products/xbee-rf-solutions/xctu-software/xctu

XIG: https://github.com/XBeeInternetGateway/XIG/releases

Going Forward.

In the next post we’ll develop a web application so we can toggle the LED from our own web page.