My first excercises with a microcontroller - part 2

Show or discuss your existing Home automation project here, so a detailed explanation!.....
Post Reply
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

My first excercises with a microcontroller - part 2

Post by Digit »

Recently i bought 2 XBee RF Modules.

For those who have no clue what these modules can do, here some specs:
- Power output: 1mW
- Indoor/Outdoor range: Up to 30/100 m
- RF data rate: 250 Kbps
- Interface data rate: Up to 115.2 Kbps
- 6 x 10-bit ADC inputs
- 8 x Digital I/O
- Configuration: API or AT (Hayes) Commands.
- Operating frequency: 2.4 GHz
- Networking topology: Point-to-point, point-to-multipoint, & peer-to-peer
- Addressing: 65,000 network addresses available for each channel
- Supply voltage: 2.8 - 3.4 VDC
- Transmit current: 35/45 mA @ 3.3 V for normal/boost mode
- Receive current: 50 mA @ 3.3 V
- Sleep current: <10 A
- Interface options: 3V CMOS UART
- Size: 24 x 28 mm
- Weight: 3g

Primary goal for getting these 2 XBee modules was to get familiar with the XBee/Zigbee concept and do some experiments with these modules. For example, i wanted to see if I could get my Arduino wireless. After a lot of reading I decided to give it a try; and here is a summary of how surprisingly easy it was to get the 2 XBee modules working and getting my Arduino wireless as an extra bonus.

<b>Buying</b>
The first experiment was to connect one Xbee module to my PC and another one to my Arduino.
For that I bought the following items:

<u>2 x Digi XBee 802.15.4 (Series 1) module</u> (Digi Article Number XB24-ACI-001)

<u>2 x Xbee Adapter kit</u>
This adapter is used to plug in the XBee modems and takes care of:
- Onboard 3.3V regulator to power the XBee;
- Level shifting circuitry that makes it easy to connect it to 5V circuitry such as an Arduino;
- Two LEDs, for activity (red) and power (green)
- 10-pin 2mm sockets included to protect the modem and allow easy swapping, upgrading or recycling
- http://www.adafruit.com/index.php?main_ ... cts_id=126
- Specifically created for use with the FTDI cable mentioned below.

<u>1 x USB TTL-232 cable - TTL-232R 3.3V</u>
This is a cable with a FTDI FT232RL usb/serial chip embedded in it. It has a 6-pin socket at the end that connects perfectly to the Adapter Kit mentioned above.


<b>Soldering & Configuration</b>
After soldering the 2 Adapter kits and plugging the Xbee modules into the adapter, connecting the USB cable to an adapter and the PC, the green LED started blinking right away; so far so good! Make sure you have the latest FTDI drivers on your PC, otherwise the cable wont work.
After testing both combinations of adapter and module, I could have started working with the Xbee modules right away, but I chose to change a few things in the modules before doing that:
- updating the Xbee modules firmware to the latest version;
- selecting my own PAN ID instead of leaving it to the factory default.

Changing the baud rate is another useful option to consider at this point. I left the baud rate to 9600 for now.
Configuration can be done in different ways. Either by use of a terminal program (Hyperterminal or whatever your favorite is) or by using a (Windows only) tool made by Digi, called X-CTU. If youre using a terminal program make sure you set the COM port settings to 9600,8,N,1. Connect, and type +++. The Xbee module should respond with an OK. Sounds familiar, right? Yep ,the XBee module can be configured with AT commands. For example, ATBD 3 means setting the baud rate to 9600, ATBD 4 will set it to 19200 baud. ATWR saves the new settings to the flash memory.

If you dont want to look up all the AT commands you need to configure the Xbee module the way you want, the X-CTU tool from Digi is the easiest way. This is what X-CTU looks like:

Image

Very easy to use; you can perform firmware upgrades with it, save configuration profiles and reload those into the Xbee module, it has some testing tools like a terminal window, etc. It works very easy; no need for F1. (maybe thats why it doesnt even have a help file). For Linux users, AFAIK, the only option is by means of a terminal program. More experienced users should be able to make a script to send all the necessary AT commands to the serial port.

XBee module connected to PC:
Image
Image


<b>"The other side"</b>
Ok, now we have 2 Xbee modules, configured and ready to use. Now it's time to prepare the other side, my new Arduino. So i placed 1 XBee adapter on the breadboard next to the Arduino that was still running its silly 3 blinking LEDs test sketch.

Now it was time to make that sketch a bit more interactive so i created a new sketch that will scan the Xbee Serial data arriving at the Arduino for ASCII characters R, Y, G and (space). The R will toggle the Red LED, the Y will toggle the Yellow LED, the G will toggle the Green LED and the (space) will toggle all LEDs. Just a simple sketch to start with.

Code: Select all

//
// LED switching by means of XBee
// Sep 2009
//

#include <NewSoftSerial.h>

NewSoftSerial XBSerial = NewSoftSerial(2, 3);

int ledPinR = 10;    // Red LED connected to digital pin 10
int ledPinY = 11;    // Yellow LED connected to digital pin 11
int ledPinG = 12;    // Green LED connected to digital pin 12
int Rval = LOW;      // initial state of Red LED
int Yval = LOW;      // initial state of Yellow LED
int Gval = LOW;      // initial state of Green LED

void setup()  {

  // Set all pins for OUTPUT
  pinMode(ledPinR, OUTPUT);
  pinMode(ledPinY, OUTPUT);
  pinMode(ledPinG, OUTPUT);
  
  // Set all LEDs to initial state
  SetPin(ledPinR, Rval);
  SetPin(ledPinY, Yval);
  SetPin(ledPinG, Gval);

  // Setup SoftwareSerial port
  XBSerial.begin(9600);
  // send informational message to terminal window
  XBSerial.println("Setup finished.");
}

void loop()                     // run over and over again
{
  if (XBSerial.available()) {
      // read serial data byte by byte
      byte inByte = XBSerial.read();
      // scan for specific characters: R,Y,G and space.
      switch (inByte) {
        case 82:    // R toggles Red LED
          Rval = Rval==HIGH?LOW:HIGH;
          SetPin(ledPinR, Rval);
          break;
        case 89:    // Y toggles Yellow LED
          Yval = Yval==HIGH?LOW:HIGH;
          SetPin(ledPinY, Yval);
          break;
        case 71:    // G toggles Green LED
          Gval = Gval==HIGH?LOW:HIGH;
          SetPin(ledPinG, Gval);
          break;
        case 32:    // Spacebar toggles all LEDs
          Rval = Rval==HIGH?LOW:HIGH;
          SetPin(ledPinR, Rval);
          Yval = Yval==HIGH?LOW:HIGH;
          SetPin(ledPinY, Yval);
          Gval = Gval==HIGH?LOW:HIGH;
          SetPin(ledPinG, Gval);
          break;
      }
      // echo the inByte
      // (no specific purpose)
      XBSerial.print((char)inByte);
  }
  delay(10);
}

void SetPin(int pin, int value)
{
  digitalWrite(pin, value);
}
Verify, change code, Verify, change code, Verify, change code, Verify, (hey, were talking C here [:D])
Another cup of coffee and finally: Compile, Upload, Running!

Here's the Arduino board with the other XBee module:
Image

The Xbee adapter is now powered with 5V from the Arduino (red and black wires) and the adapters RX/TX lines go to pins 2 and 3 (green and white). Normally you would use pins 0 and 1 for that, cause those 2 pins are designated for serial I/O, but that would mean I would lose the USB connection to upload sketches to the Arduino. And with very little programming experience on the Arduino that didnt look like a good idea. Fortunately theres a library called NewSoftSerial that makes it possible to do Serial I/O on other pins as well.

Now, when I have a terminal window open and connected to the Xbee module, I can use the keyboard to toggle the 3 LEDs. Yeah, I know, this wont win any "most innovative project" price, but at least I can see my 2 Xbee modules communicating with each other, and my Arduino is wireless. Mission accomplished!

Afterwards i made a small executable with 4 buttons that illustrates it all:


And what has actually been created here? The basics for a wireless, programmable interface with 14 Digital I/O Pins (of which 6 can provide PWM output) and 6 Analog Inputs! If that aint nice

Total costs:

Code: Select all

Arduino                  22,50
USB cable                18,50
2 XBee modules           31,30  ($ 46,00)
2 XBee adapters          13,60  ($ 20,00)
<b>Total                 85,90</b>
<b>Whats next?</b>
- Getting hold of another kind of Xbee adapter that will Ethernet-enable a Xbee module so I can talk to it from my HA system;
- Integrating Xbee/Arduino combo in my HA system as an additional Interface so I can make use of all of the capabilities the Arduino has to offer from within my HA system;
- Buying a Pan & Tilt mechanism (to cheap to DIY) and hooking it up to the Arduino to learn more of the I/O capabilitys of the Arduino;
- And probably the most important one to result in more new ideas: exploring the capabilities of a stand alone Xbee module (as in: what can you do with the onboard Analog and Digital I/O an Xbee module has to offer)!

To be continued...


<hr noshade size="1"><font size="1">Robert
http://www.hekkers.net <i>Digit's Online Home.</i></font id="size1">
Alexander
Global Moderator
Global Moderator
Posts: 1532
Joined: Sat Mar 10, 2007 11:19 pm
Location: Netherlands

My first excercises with a microcontroller - part 2

Post by Alexander »

Mmmm i see a possibility to use this system as a RFID kind of system? Or better use it for our cars. What is your opinion Robert?

Alexander
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

My first excercises with a microcontroller - part 2

Post by Digit »

A powered XBee module without anything to 'extra' will not transmit AFAIK. So you would need something that triggers the XBee to do just that i guess. Doesn't a RFID tag do that???
Definitely something to look into!

<hr noshade size="1"><font size="1">Robert
http://www.hekkers.net <i>Digit's Online Home.</i></font id="size1">
Alexander
Global Moderator
Global Moderator
Posts: 1532
Joined: Sat Mar 10, 2007 11:19 pm
Location: Netherlands

My first excercises with a microcontroller - part 2

Post by Alexander »

microcontroller that send every x seconds its id ;-)

Alexander
User avatar
Willem4ever
Global Moderator
Global Moderator
Posts: 805
Joined: Mon Oct 30, 2006 3:48 pm
Location: Uithoorn / Netherlands

My first excercises with a microcontroller - part 2

Post by Willem4ever »

Interesting modules those XBee's. Is there no interference with Wireless (802.11n) any experience with that ...
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

My first excercises with a microcontroller - part 2

Post by Digit »

Alexander,
Then you would probably choose something like this:
http://moderndevice.com/RBBB_revB.shtml
This is a minimal sized Arduino compatible device for $ 12.
It should be possible to attach this board to the car battery.
Add a XBee for $10 and you're done.
However, somehow i have the feeling using the Arduino platform for this is overkill in terms of hardware.
Maybe there are smarter and better ways that i don't know of...

<hr noshade size="1"><font size="1">Robert
http://www.hekkers.net <i>Digit's Online Home.</i></font id="size1">
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

My first excercises with a microcontroller - part 2

Post by Digit »

Willem,
From what i've read so far interference should not be an issue.
Not much personal experience, since i only have 2 XBee modules running for 24-36 hours now.
No problems, but that doesn't say much.
Here's what Digi has to say about interference:

Digi's unique XII Interference Immunity technology is a proprietary hardware and software feature set that allows product designers using Digi products to create wireless systems that are immune to most RF interferers (cell phones, pagers, other wireless systems, etc.).

When operating within the 900 MHz and 2.4 GHz frequency bands, cell phones, pagers and other wireless systems can dramatically interfere with wireless links.

Digi's XII technology can block 60 dB of interference. Interference just 1 MHz away can be 1 million times stronger than the Digi signal and only degrade the receiver sensitivity by 3 dB. This interfering device would have to output more than 100,000 Watts to significantly affect the transmission of Digi products.

Digi products utilize frequency hopping spread spectrum communication that, by design, delivers additional protection against interference.


<hr noshade size="1"><font size="1">Robert
http://www.hekkers.net <i>Digit's Online Home.</i></font id="size1">
User avatar
Willem4ever
Global Moderator
Global Moderator
Posts: 805
Joined: Mon Oct 30, 2006 3:48 pm
Location: Uithoorn / Netherlands

My first excercises with a microcontroller - part 2

Post by Willem4ever »

Sounds good, I have some other low-costs wireless stuff on the shelfs here but XBEE seems more interesting. I might order some to toy around with. You ordered your froms Adafruit ? I just found them here as well.
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

My first excercises with a microcontroller - part 2

Post by Digit »

You're right, those are the same modules.
But i didn't find the adapter kit at Antratek, so that's why i ordered it all at adafruit.

Have a good look at the prices. I was lucky at my first order, for example the same XBee module:

http://www.eztronics.nl/webshop/catalog ... cts_id/242

30 Euro,

http://www.adafruit.com/index.php?main_ ... cts_id=128

< 16 Euro!


<hr noshade size="1"><font size="1">Robert
http://www.hekkers.net <i>Digit's Online Home.</i></font id="size1">
User avatar
Willem4ever
Global Moderator
Global Moderator
Posts: 805
Joined: Mon Oct 30, 2006 3:48 pm
Location: Uithoorn / Netherlands

My first excercises with a microcontroller - part 2

Post by Willem4ever »

Is the XBEE explorer not doing the same for the pc connection ?
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

My first excercises with a microcontroller - part 2

Post by Digit »

Yes. But because i had to put 1 module on the breadboard i chose the adapter kit.
With the next purchase i'll order this one to.
BTW soldering the adapter kit takes about 20 minutes, even for me ;-)

<hr noshade size="1"><font size="1">Robert
http://www.hekkers.net <i>Digit's Online Home.</i></font id="size1">
User avatar
Willem4ever
Global Moderator
Global Moderator
Posts: 805
Joined: Mon Oct 30, 2006 3:48 pm
Location: Uithoorn / Netherlands

My first excercises with a microcontroller - part 2

Post by Willem4ever »

More questions Digit :-) why didn't you go for series 2.5 ?

digikey.com my favourite site for electronics is also selling but not exporting to Holland (price 15 euro)

"Due to U.S. export controls, we are unable to add this item to your order"
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

My first excercises with a microcontroller - part 2

Post by Digit »

You mean those mentioned here: http://ftp1.digi.com/support/documentat ... 0866_C.pdf ?
Mainly because this was a fist exercise with only need for point-to-point and where the 2.5 series seem more appropriate for Zigbee operation with different firmware versions for different operation modes. I didn't want to make it to difficult for myself :-)


<hr noshade size="1"><font size="1">Robert
http://www.hekkers.net <i>Digit's Online Home.</i></font id="size1">
User avatar
Willem4ever
Global Moderator
Global Moderator
Posts: 805
Joined: Mon Oct 30, 2006 3:48 pm
Location: Uithoorn / Netherlands

My first excercises with a microcontroller - part 2

Post by Willem4ever »

This One a version compatible with Zigbee of other venders is also available here. Very cool stuff takes all the protocol issues out of your hand and still affordable. Getting a zillions ideas to do with it. If I only had time ....
Bwired
Administrator
Administrator
Posts: 4704
Joined: Sat Mar 25, 2006 1:07 am
Location: Netherlands
Contact:

My first excercises with a microcontroller - part 2

Post by Bwired »

Nice!
Willem look at this tiny webserver from your link.
http://www.sparkfun.com/commerce/produc ... ts_id=9360
Robert I think this will work with your setting as well........

<hr noshade size="1"><font size="1">Pieter Knuvers
http://www.bwired.nl <i>Online House in the netherlands. Domotica, Home Automation.</i></font id="size1">
Post Reply

Return to “Home Automation Projects”