This is only a preview of the May 2006 issue of Silicon Chip. You can view 39 of the 112 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Items relevant to "Lead-Acid Battery Zapper & Condition Checker":
Articles in this series:
Items relevant to "Universal High-Energy LED Lighting System, Pt.2":
Items relevant to "A Passive Direct Injection Box For Musicians":
Items relevant to "Remote Mains Relay Box":
Items relevant to "Vehicle Voltage Monitor":
Articles in this series:
Purchase a printed copy of this issue for $10.00. |
Pt.2: By CLIVE SEAGER*
* Clive Seager is Technical Director of Revolution Education Ltd, the developers of the
PICAXE system.
PICAXE Goes
Wireless
Get your PICAXE projects talking over the airwaves using
the latest high-tech 2.4GHz XBee modules!
I
N PART 1 LAST MONTH, we des
cribed how to build and test a
pair of wireless data communications
nodes based on AXE210 project boards
and XBee modules from MaxStream.
This month, we look at some of the
more advanced features of the XBee
modules.
By way of example, we then learn
about some of these features during
the construction of a wireless light
and temperature sensor, based on one
of the AXE210 boards. As part of the
project, we also see how to receive and
log the data from the wireless sensor to
disk with the aid of the second AXE210
board and a PC.
Finally, we dispense with the PC
altogether and see how easy it is to get
a PICAXE-to-PICAXE wireless link up
and running!
XBee networking
Fig.1: here’s a screen shot of the XBee
Setup wizard, showing the correct
settings for board #1. Remember to
swap the DL and MY values around
when programming board #2!
88 Silicon Chip
As demonstrated last month, sending and receiving data between two
XBee modules is quite straightforward.
In those examples, we relied on the
XBee’s default settings.
However, consider the case where
more than one module is within receiving range. Unless we specifically
want to send a “broadcast” message
to all modules, then some means of
addressing the data to the intended
recipient is required.
This is where the XBee’s intelligent
networking features come into play.
For a start, each module is factory programmed with a unique serial number,
allowing it to be explicitly addressed.
In addition, each XBee module can
be identified with a programmable
“nickname” for ease of use.
Other powerful networking features include the ability to arrange
modules into groups, or “private
area networks” (PANs). By assigning
a common group ID to all members,
modules not part of that group are
automatically excluded.
So how do you set an XBee module’s nickname or group ID? Well
for modules connected to a PC, it’s
quite straightforward; you’d use the
Programming Editor’s “XBee Setup”
wizard. We’ll investigate this method
in more detail shortly.
You can also set these parameters
using a microcontroller such as our
PICAXE-18X. Although we don’t cover
this method here, it’s simply a matter
of sending the appropriate commands
to the XBee module before sending or
receiving data over the radio link.
To do this, the module is first placed
in command mode by sending a special sequence of characters. Once in
command mode, the command(s)
and any other parameters (such as
the nickname mentioned earlier) are
sent. A final “exit” command returns
the module to idle mode, ready to
send and/or received data over the
airwaves.
siliconchip.com.au
Table 1: Module Settings
Parameter
Board #1
Board #2
Baud rate <BD>
2400
2400
Broadcast
channel <CH>
C
C
Network group
<ID>
3332
3332
Destination
nickname <DL>
4321
1234
My nickname
<MY>
1234
4321
Before continuing, we strongly recommend that you download and
review the XBee datasheet, available
from www.maxstream.net. There you
will find a detailed description of the
XBee’s networking features and the
various commands needed to make
them work.
In the following project examples,
we’ll refer to a subset of the XBee’s
commands and their related terms.
An informative summary of these is
given in Table 2.
Putting it into practice
If all the addressing information
sounds a bit confusing, don’t worry – it
should become clearer with a couple
of examples! In this first of these, we
will wire up a temperature sensor and
a light dependent resistor (LDR) to the
PICAXE chip on one of the AXE210
Connect boards. We’ll then transmit
data gathered from the sensors via the
on-board XBee module to a second
XBee module connected to a computer,
where is can be viewed on-screen or
logged to disk.
This example uses “nickname”
(short) addressing. We’ve arbitrarily
chosen address “1234” for board #1
and “4321” for board #2, so let’s begin
by programming these addresses into
the two XBee modules.
Initially, we’ll configure both boards
for “PC to XBee interface” use (mode
#2), as described last month. To do
this, insert the MAX3232 chip into
its 16-pin socket on each AXE210
Connect board (remove any PICAXE
chip) and make sure jumper J1 is in
the “top” position).
Next, start the PICAXE Programming
Editor and open the “XBee Setup” window by selecting PICAXE -> Wizards
-> AXE210 PICAXE Connect from the
toolbar. The settings required for each
siliconchip.com.au
Fig.2: light and temperature sensors are wired to board #1 for the first
project. This simplified circuit shows the connections, made via the row
of solder pads next to the serial socket.
Table 2: Introduction To XBee Buzzwords
Broadcast Channel <CH>
XBee modules can communicate on 16 different “broadcast channels”. All XBee modules
in the same network must share the same channel number. Different channels can be
used for different networks for privacy reasons or to reduce interference. In addition,
switching channels can sometimes be an effective means of reducing interference from
competing transmitters, such as computer WiFi networks, microwave ovens and cordless telephones.
Baud Rate <BD>
This is the data rate on the XBee serial interface (ie, between the XBee and PICAXE or
computer). When using a PICAXE micro, choose a baud rate of 2400 for maximum compatibility. Although slow by modern standards, this rate is adequate for most projects.
Network Group <ID>
XBee modules can be arranged in network groups (also called “Personal Area Networks”,
or “PANs”). Each module will only respond to others in its group, as defined by a 16-bit
ID number.
Serial Number <SH> <SL>
Each XBee module has a unique, factory-assigned 64-bit serial number (also called a
“long address”). The serial number is printed on the bottom of the module and obviously
cannot be changed. Data can be addressed to a specific device by including its 64-bit
serial number.
Nickname <MY>
Optionally, an XBee module can be addressed by its “nickname” (also called a “short
address”) rather than by serial number. Nicknames have the advantage of being userprogrammable and are only 16-bits long – so they consume less memory in a PICAXE.
Using this method of addressing, any module in a network can be replaced with a new
unit (which would have a different serial number) simply by programming it with the existing nickname.
module are shown in Table 1.
As you can see, all of the settings
are the same, apart from the “my nickname” and “destination nickname”
values, which have been swapped.
This allows the two modules to correctly identify each other. Fig.1 shows
a screen shot of the settings for the
XBee module in board #1; remember
to swap the DL and MY values around
when programming board #2!
After altering any parameter, note
that the associated “Write” button must
be clicked otherwise your changes
May 2006 89
XBee Communications Checklist
Fig.3: once you’ve fitted the sensors
and downloaded the program in
Listing 1, the board will immediately
begin transmitting its data. Here’s
the result, as received by the second
board and displayed in the Editor’s
terminal window.
Fig.4: data gathered from the sensors
can be saved to disk with this
excellent freeware RS232 logging
program from Eltima. Be sure to alter
the serial port options to suit the
PICAXE system.
will not be saved. Once you’ve configured both boards, it’s a good idea to
perform a ping test to verify that the
units are in fact communicating. Details of how to do this test were given
in last month’s article.
Light & temperature sensor
We’ve chosen board #1 to operate
as the remote temperature and lightsensing node, so remove the MAX3232
chip and plug the PICAXE-18X into its
18-pin socket. This is the “PICAXE to
XBee interface” configuration (mode
#1) described last month.
Next, wire a light-dependent resistor (LDR) and DS18B20 temperature
90 Silicon Chip
(1)
All modules must use the same baud rate (recommended).
(2)
All modules must be on the same broadcast channel.
(3)
All modules must be in the same network group.
(4)
An XBee module can be configured to transmit to:
• any other module,
• a module(s) with a specific nickname, or
• a specific module, using its 64-bit serial number.
(5)
An XBee module can be configured to receive data:
• from any other module,
• only when its nickname is used, or
• only when its 64-bit serial number is used.
sensor to input0 and input7 of the
PICAXE, as shown in Fig.2. A row of
solder pads along the top of the board
provides easy access to the port input
pins, as well as +5V and ground.
As the circuit is extremely simple,
it could be wired “point-to-point”
with light gauge hook-up wire. Alternatively, you could use a small
solderless breadboard for the job; see
Pt.3 of the “PICAXE in Schools” series,
published in July 2005 for ideas on
breadboard use.
Now connect board #1 to your
computer and download the program
shown in Listing 1 into the PICAXE
chip. The “init” section of the program
sets the serial pin high and then waits
for 100ms. This gives the XBee time
to wake up. The main loop then reads
the light value (readadc on input0)
and temperature value (readtemp on
input1) and transmits the data every
second.
Disconnect board #1 from the computer and connect board #2 (fitted
with a MAX3232). The data being
transmitted by board #1 should now
be displayed in two columns in the
Terminal window (see Fig.3) – it’s
that simple!
Logging data
PICAXE users often ask for serial
datalogging software to allow readings
from a project like this to be stored in
a computer file, so that the data can
be analysed later. Our favourite piece
of software to do this is “RS232 Data
Logger” from Eltima Software (www.
eltima.com), as it’s free and very easy
to use.
To use the RS232 Data Logger, just
highlight the COM port of interest,
enter the filename and select the
appropriate serial port options (see
Fig.4). All you then need to do is click
on the “Start logging” button!
Once the logging is complete, click
on the “Stop logging” button. The file
created can then be opened in Excel
and many other applications, depending on your requirements.
Light and temperature warning
This second project demonstrates
wireless PICAXE-to-PICAXE communication. Board #1 remains unchanged, while board #2 must be fitted
with a PICAXE chip and two LEDs.
These will be used to indicate the state
of the temperature and light readings
received from board #1.
Begin by fitting the PICAXE chip to
board #2 (don’t forget to remove the
MAX3232!). The two LEDs are connected to output0 and output1 of the
PICAXE, as shown in Fig.5. A row of
solder pads along the bottom of the
board provides easy access to the port
output pins and ground.
That done, connect board #1 to
your computer and download the new
program shown in Listing 2. As you
can see, we no longer have the “#”
character before the variable names,
because we are now transmitting raw
byte data, rather than ASCII characters.
Two “$55” characters also precede
each transmission; this is a simple
means of ensuring that the receiver
accepts only valid data.
Now connect board #2 to your computer and download the receiving program in Listing 3. This program waits
for valid data from the transmitter and
then switches the LEDs according to
the predefined temperature and light
threshold values.
Initially, the debug command can
siliconchip.com.au
Parts List For
Project Examples
Fig.5: two LEDs
and their current
limiting resistors
are connected to
board #2 for the
second project. The
connections are
made via the row of
solder pads situated
between the two
reset switches.
1 DS18B20 digital temperature
sensor
1 light-dependent resistor (LDR)
2 3mm or 5mm LEDs
light-duty hook-up wire
Resistors (0.25W 5%)
1 10kW
2 330W
1 4.7kW
The temperature sensor (Part No.
DS18B20) and LDR (Part No.
SEN002) are available from MicroZed Computers, phone 1300
735 420 or browse to www.microzed.com.au
be used to display the received values
on-screen. As shown, the program
uses “40” as the light threshold value
and “20” as the temperature threshold. You may need to tweak these
slightly, depending on your ambient
conditions.
Reducing power consumption
If you are designing your own
project based on the AXE210, you
are likely to be considering batteries as the power source. Two simple
improvements to the project board
are immediately obvious. The first is
to power the whole circuit from a 3V
battery pack, allowing you to bypass
the two relatively inefficient voltage
regulators.
Of course, you’ll need to disable the
two voltage divider circuits on output6
& output7 when the PICAXE is running
on the lower 3V supply. If you’ve already built the boards, then the easiest
way to achieve this is to remove one
10kW resistor (the one connected to
0V) from each divider string.
You can also use the “sleep” function of the XBee module to reduce
power consumption. By installing
jumper J4 on the board, the SLEEP pin
of the XBee module is connected to
output6 of the PICAXE chip. This then
allows you to place the XBee module
in low-power sleep mode with a low
command and wake it up when needed
with a high command.
Note that to allow the XBee module
to enter low power mode using the
external SLEEP input, you must first
configure it to do so via the advanced
siliconchip.com.au
Program Listings
settings in the XBee Setup wizard.
Click the “>” button to see the advanced settings.
You’ll note that two pin-controlled
options are available under the “Set
Sleep Mode” heading – “Pin Doze”
and “Pin Hibernate”. The difference
between these two options is summarised as follows:
Option
Current Drain Wakeup Time
Pin Doze
<50mA
2ms
Pin Hibernate <10mA
13.2ms
Increasing range
Need more range? A higher-powered
version of the XBee module called the
“XBee Pro” is also available. It boasts a
transmit power of 100mW, versus the
1mW of the standard XBee. The two
modules are pin-for-pin compatible, so
no changes are required to the AXE210
board to use the uprated module.
But before spending more money
on the “Pro” module, check out Stan
Swan’s 2.4GHz gain antennas in this
issue. They cost virtually nothing, are
fun to build and can increase range by
two times or more!
Summary
The XBee modules make serial
communication between PICAXE
projects a breeze. Additionally, their
range can be increased significantly for
little cost using home-brew antennas.
For more information on the XBee
modules, point your browser to www.
SC
maxstream.net
Listing 1
symbol TAB = 9
init:
high 7
pause 100
serout 7, T2400, ("Light",TAB,"Temp",CR,LF)
main:
readadc 0,b0
readtemp 1,b1
serout 7, T2400, ( #b0,TAB,#b1,CR,LF)
pause 1000
goto main
Listing 2
init:
high 7
pause 100
main:
readadc 0,b0
readtemp 1,b1
serout 7, T2400, ($55,$55,b0, b1)
pause 1000
goto main
Listing 3
main:
serin 7, T2400, ($55,$55),b0, b1
debug
test_LDR:
if b0 > 40 then LDR_high
low 0
goto test_temp
LDR_high:
high 0
test_temp:
if b1 > 20 then temp_high
temp_low low 1
goto main
temp_high:
high 1
goto main
May 2006 91
|