ETH Zurich :
Computer Science :
Pervasive Computing :
Distributed Systems :
Education :
WSN SS2007 :
Tutorial
Wireless Sensor Networks Tutorial
Back to main page
Introduction
If you are reading this, you have hopefully attended the introductory session where you received
- 2 BTnodes with BTsense board
-
- 2 USB programming boards
- 2 USB cables
- 4 AA batteries
If you are missing any of these, please contact Benedikt Ostermaier.
In this tutorial, you will learn how to set up your computer to work with the BTnodes. This will involve installing all the necessary drivers and tools, as well as setting up your programming environment. Then, we will download the source code for the BTnode and upload a sample application onto the BTnode.
1. Toolchain Installation
For the sake of this tutorial, we will be working in Windows XP.
It is also possible to work with BTnodes in Linux or Mac OS X,
though you will need a reasonably up-to-date system (e.g., kernel 2.6.12 and above for Linux).
For the Windows platform, most of the installation steps are described below - note
that you need administrator privileges for the installation process.
For more information,
as well as information about toolchain installation on Linux and Mac OS X systems, see
the "Getting Started"
section on the official BTnode site. Continue with step 2 (OS Installation) after you installed the toolchain, do not install the OS from CVS as suggested on the official BTnode site!
Cygwin
We strongly recommend to install Cygwin on your Windows machine. The main reason in this context is the command line building tool make that comes with Cygwin and that we require to compile our C projects. There are other possibilities, but here we will stick with Cygwin. You can download it from http://www.cygwin.com, and make sure to select the make package during installation. If you have worked with the Tmote sensor nodes before, we strongly suggest that you re-install Cygwin in order to avoid potential problems.
USB Driver
In order to communicate with the BTnode, we use an extension board
with a Silabs CP2101 USB connection that allows us to attach the device to the computer. For Windows, this requires us to install the appropriate drivers that create a virtual COM port (aka serial port) to communicate with the BTnode: Download it here and install it.
Linux should have support for the CP2101 built-in, so things should work out-of-the box. For Apple computers, you can download the CP2101 driver
here.
WinAVR
The BTnode is based on the ATmega128 from the Atmel AVR series. In order to
compile programs for this platform and to upload code to the device, we need
to install WinAVR (release 20071221), which can be
found here. This
installer automatically inserts the WinAVR directory into the path which means
we can access the avr-gcc compiler from any shell location and from
inside Eclipse.
Important: WinAVR comes with a set of DLLs that will conflict with your Cygwin installation.
Since we will be using the Cygwin-versions of those libraries, you will need to remove the ones that
came with WinAVR. They can be found in the WinAVR\bin directory and
are called cyg*.dll .
Eclipse
We suggest using the Eclipse IDE 3.3 (Integrated
Development Environment) to develop BTnode programs. If you want to use your favourite
text editor, then just skip the Eclipse-related instructions below.
Eclipse was originally
designed for Java programming and is also written in Java. Hence it requires
a JRE (Java Runtime Environment) to be installed. The latest JRE is available
from http://www.java.com.
Eclipse 3.3 can be downloaded from www.eclipse.org.
Extract the zip archive to your location of choice. This can be C:\Program Files
or even C:\ , which we will use here.
In order to create and maintain C or C++ projects, you need to
install an Eclipse plugin called CDT
(C/C++ Development Tools). This can be done by directing the Eclipse Update Manager to
the Europa Update Archive.
2. Obtaining the OS
Now we have installed everything we need to be able to write, compile and
upload programs to our BTnode. It is time to get the source code for the
operating system we need to compile our code against and some sample programs
to help us understand how to program the BTnode.
Our BTnodes use the BTnut OS, a particular
extension of another open source, embedded systems OS called ethernut.
To make life simpler for us, we will not use daily CVS builds from the BTnut system development, but instead use
a snapshot that we prepared for our lecture. Download this snapshot from here and extract it to your
"workspace" (here we will assume C:\workspace ). Note: To extract a tgz -file, you can use your Cygwin installation!
Simply save the above file in C:\workspace , start a Cygwin shell, and issue:
$ cd /cygdrive/c/workspace
$ tar xvfz btnut_system_WSNLab2008_r1.tgz
Note: Do not install any of the official builds from
the BTnut homepage, as these might not support all the exercises and features that we
will be discussing in class!
Creating Eclipse Projects (if you use Eclipse)
Now we have all the source code we need, but before we can program, we need to create the
corresponding projects in Eclipse. Therefore open Eclipse (with the CDT
plugin installed). Set the workspace to whatever you have defined. Open
File => New => Project , then select C => Standard Make C Project ,
and click Next . Enter btnut and click Finish .
Eclipse will then ask you to switch to the C Perspective. Answer yes. Now,
open File => New => Standard Make C Project , enter nut
and press Finish . You should have one project folder for btnut
and one for nut . Next, expand the btnut project on the left
side and open the app/bt-cmd folder. Here, open the bt-cmd.c file.
Look at the source code - this is a BTnode application.
PS: If you rather use your favorite text editor to program, you do not need any of the above steps - this is just if you
like to use the IDE-capabilities of Eclipse...
3. Compiling
In order to link our applications against the system libraries, we will need to
compile the entire operating system. In order to do this directly from within
Eclipse, please refer to Section 2.3 of the GettingStarted Guide.
We will compile from command line. For this purpose, navigate your Cygwin shell
to the btnut directory by typing cd /cygdrive/c/workspace/btnut
and start the build process by entering make . This will take some time
and should look as follows:
user@host:/cygdrive/c/workspace/btnut
$ make
c:/WinAVR-20071221/utils/bin/make -C btnode install
make[1]: Entering directory '/cygdrive/c/workspace/btnut/btnode'
c:/WinAVR-20071221/utils/bin/make -C bt install
make[2]: Entering directory '/cygdrive/c/workspace/btnut/btnode/bt'
avr-gcc -c -mmcu=atmega128 -Os -Wall -Werror -Wstrict-prototypes -Wa,-ahlms=bt_hci_transport_uart.btnode3.lst -D__HARVAR
D_ARCH__ -D__BTNODE3__ -I../../btnode/include -I../../../nut/include -I../../extras bt_hci_transport_uart.c -o bt_hci_t
ransport_uart.btnode3.o
avr-gcc -c -mmcu=atmega128 -Os -Wall -Werror -Wstrict-prototypes -Wa,-ahlms=bt_hci_dispatch.btnode3.lst -D__HARVARD_ARCH
__ -D__BTNODE3__ -I../../btnode/include -I../../../nut/include -I../../extras bt_hci_dispatch.c -o bt_hci_dispatch.btno
...
avr-size uart-suart.btnode3.elf
text data bss dec hex filename
15888 430 105 16423 4027 uart-suart.btnode3.elf
required flash size in bytes: 16318
available flash size on btnode3 in bytes: 131072 (resp. 122880 with bootloader)
avr-objcopy -O ihex uart-suart.btnode3.elf uart-suart.btnode3.hex
rm uart-suart.btnode3.elf
make[2]: Leaving directory '/cygdrive/c/workspace/btnut/app/uart-suart'
make[1]: Leaving directory '/cygdrive/c/workspace/btnut/app'
c:/WinAVR-20071221/utils/bin/make -C doc doc
make[1]: Entering directory '/cygdrive/c/workspace/btnut/doc'
doxygen btnut.doxygen
process_begin: CreateProcess(NULL, doxygen btnut.doxygen, ...) failed.
make (e=2): The system cannot find the file specified.
make[1]: *** [doc] Error 2
make[1]: Leaving directory '/cygdrive/c/workspace/btnut'
make: *** [doc] Error 2
user@host:/cygdrive/c/workspace/btnut
$
Note: The tools doxygen and dot are only required for the building of the
documentation - it is okay if you do not have them installed (in fact, the building
process is faster when these tools are not installed.)
Now we have compiled the btnut system, including all the applications
that are already included. These applications are compiled in binary format suitable
for the BTnode (*.hex ).
4. Configuring the Upload-Port
Finally, we need to know how to upload application code to the BTnode. For this
purpose you need to have the BTnode connected to your computer via USB and you
need to know which virtual COM port it is using.
On Windows, you can use the script
list_usb2uart.vbs to acquire the COM-Port
(COMx) of the BTnode, or simply look at the Device-Manager
(Start => Control Panel => System => Hardware => Device Manager => Ports ) while
connecting a BTnode (the COM-port should appear/disappear automatically when you
connect/disconnect the BTnode).
On Linux, see the official BTnode site for Linux USB Access
There is a special make target that will send the program to the
BTnode, but first we need to tell make which port to use.
Therefore, go back to Eclipse and open the file btnut/Makedefs .
Look for the statement BURNPORT = //./COM50 and change this to
BURNPORT = //./COMx where x represents your port number.
5. Uploading our first program to the BTnode
Let's upload one of the sample applications that are contained in the BTnut
OS package. Change into the btnut/app/bt-cmd directory, e.g.,
within the Cygwin shell. Then execute make burn btnode3 , which
will trigger the avrdude uploader to send the created binary
file to the BTnode. This is a bit tricky, as you need to press the reset
button on the BTnode (use this picture of the BTnode reset button for guidance), and release it when the uploader is ready to send the data. If all goes well, it should look like this:
user@host /cygdrive/c/workspace/btnut/app/bt-cmd
$ make burn btnode3
c:/WinAVR-20071221/utils/bin/make burn.btnode3
make[1]: Entering directory `c:/workspace/btnut/app/bt-cmd'
avrdude -pm128 -cavrisp -P//./COM50 -s -U flash:w:bt-cmd.btnode3.hex:i
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e9702
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "bt-cmd.btnode3.hex"
avrdude: writing flash (69970 bytes):
Writing | ################################################## | 100% 13.30s
avrdude: 69970 bytes of flash written
avrdude: verifying flash memory against bt-cmd.btnode3.hex:
avrdude: load data flash data from input file bt-cmd.btnode3.hex:
avrdude: input file bt-cmd.btnode3.hex contains 69970 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 10.87s
avrdude: verifying ...
avrdude: 69970 bytes of flash verified
avrdude: safemode: Fuses OK
avrdude done. Thank you.
make[1]: Leaving directory `c:/workspace/btnut/app/bt-cmd'
make: Nothing to be done for `btnode3'.
Congratulations, you have just uploaded your first program to the BTnode!
Note that the Windows driver for the CP2101 will assign a COM-Port for each USB-Port you are using. Therefore,
make burn btnode3 is only convenient if you are always using the same USB-port.
However, if you get a not in sync error instead (see below), then just try again
-- it is quite normal that it takes a number of trials until this "press,
trigger and release" process works out.
user@host /cygdrive/c/workspace/btnut/app/bt-cmd
$ make burn btnode3
c:/WinAVR-20071221/utils/bin/make burn.btnode3
make[1]: Entering directory `c:/workspace/btnut/app/bt-cmd'
avrdude -pm128 -cavrisp -P//./COM50 -s -U flash:w:bt-cmd.btnode3.hex:i
avrdude: stk500_getsync(): not in sync: resp=0xe6
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x18
avrdude done. Thank you.
make[1]: *** [burn.btnode3] Error 1
make[1]: Leaving directory 'c:/workspace/btnut/app/bt-cmd'
make: *** [burn] Error 2
If you continue getting this error, try the tips at the end of this document.
If this still does not help, try out different BTnodes and see whether the
problem persists. If it does, your BTnode might be defective -- please let
Benedikt Ostermaier know.
6. Communicating With Your Program
Now the program is running on the BTnode, which is indicated by the blue blinking LED.
In order to see what the program is doing, we need to access its terminal, again using the
virtual COM port. For this purpose, we will use HyperTerminal, which you can find in the
start menu under Start => Programs => Accessories => Communications => HyperTerminal .
(For Mac OS X, you can use ZTerm, for Linux, you can use minicom -- see the official BTnode site for details on setting up minicom).
First, it will prompt you for a connection name, and you can choose whatever you like. Next,
you need to select the appropriate COM port. In the following dialog, you need to set the
following connection settings:
- Bits per second: 57600
- Data bits: 8
- Parity: None
- Stop bits: 1
- Flow Control: None
You can now save this connection for later. If you press the reset button on your BTnode once, you should see the bt-cmd interface like this:
# ------------------------------------------------------
# Welcome to BTnut (c) 2006 ETH Zurich
# bt-cmd program version: 20070330-1204
# $Id: bt-cmd.c,v 1.48 2006/12/15 12:24:13 yuecelm Exp $
# running @ 7.3533 MHz, NutFreq=1024l Hz
# -----------------------------------------------------
booting Bluetooth module...
Bluetooth MAC address: 0004:3f00:0111
HCI version: 2 00C9 2 0012 003D
LMP features: 03 10 00 FF FF 05 F8 1B
Local name: 'ZeevoEmbeddedDevice'
hit tab twice for a list of commands
[bt-cmd@01:11]$
Starting up bluetooth takes a few seconds, this is normal. From the command
prompt, you can hit tab twice to find out all the possible commands. For now,
we will be content with checking that the MAC address of the device is indeed
the same as the one on the label on the side of the BTnode. Therefore, enter
bt addr and compare the two.
[bt-cmd@01:11]$ bt addr
Local bt_addr: 00:04:3f:00:01:11
If this is successful, you are finished. You have now installed all the necessary
tools to be able to write programs, compile them, upload them to the device, and
interact with them.
If flashing fails under WinXP
|