Spring 2009 - CSE 591

Design of Embedded Systems 

Home | Schedule | Homework | Labs | Reader

Pre-Lab #1 (before Lecture 2/11/09) 
TinyOS Basics
      NOTE!!!
If your group does not have a laptop for lab, please send e-mail ASAP.
  • Install TinyOS 2.0 (Instructions) on your group's laptop and/or on a home machine. (Windows/Linux, something else? Try google for instructions)  
    • We are using TelosB motes from Crossbow. Make sure you are follow the directions for this hardware. (In Step 3 of installation: use the TI MSP430 Tools).
    • In addition download and install the FTDI VirtualCom driver (needed for TelosB motes). The installation exectuable will work for Windows. Download and run it. It will prompt you when it is done.
    • Installation on each computer is unique (sadly). So, you may run in to errors and issues along the way. The best way to get past these is to check the TinyOS help archives, try a google search, and check/post to the blackboard discussion board. Most likely any problem you are having, someone has had it before you. Please read (and respond to!) to postings on the discussion board -- do not e-mail us with questions about the installation, they will not be answered. I will monitor the discussion board and answer questions there for everyone. Also, you can ask questions on the TinyOS mailing list. BUT, before you ask/spam the list, make sure to check the archives and ask the class on the discussion board. 
      • TOSSIM is a simulator for TinyOS which we will get to next. This will enable you to work from any machine you choose, and to test your code outside of lab. 
    • Read through and understand TinyOS Tutorials #1-6.  You should obtain a basic understanding of how to compile and load modules on the motes, how to use the radio, and read data from the sensors.
      • Tutorial #1 will step you through verifying if your Installation is working.

Lab #1 (in Lecture 2/11/07) PDF
TinyOS Basics
    • By the end of class, each group should verify they have a good working installation of TinyOS. In addition, the goal is to have a solid foundation for the basics of TinyOS.
    • Initially, set your Radio Channel to your group number plus 10
      • For each application which uses the radio, you must set the radio channel in order to avoid packet collisions between groups. 
      • To set the channel, add the following line to the beginning of your Makefile before the include Makerules (of EACH application that you create/modify). Replace x with (your group number+10). There are a total of 16 channels, which are numbered from 11-26
                CC2420_CHANNEL=x
      • Additionally, since we are working in small groups and in a single room, using the maximum transmit power is not necessary. 
      • To set the transmit power, add  the following line to the beginning of your Makefile before the include Makerules (of EACH application that you create/modify). Valid levels are 1-31, with power 1 equal to -25dBm and 31 equal to max power (0 dBm).
                                CFlags = -DCC2420_DEF_RFPower=3
    • Step 1: Verify that TinyOS is working with the Blink Application
      • See Tutorial 1 or follow instructions below:
        • cd $TOS_BASE/apps/Blink (where $TOS_BASE is the directory where you installed the TinyOS software
        • make telos -- this compiles the Blink application. You should see something like:
          mkdir -p build/telos
          compiling Blink to a telos binary
          ncc -o build/telos/main.exe -Os -fnesc-target=msp430 -gcc=msp430-gcc -mmcu=msp430x149 -Wall -Wshadow -DDEF_TOS_AM_GROUP=0x7d -Wnesc-all -target=telos -fnesc-cfile=build/telos/app.c -board= -DIDENT_PROGRAM_NAME="Blink" -DIDENT_PROGRAM_NAME_BYTES="66,108,105,110,107,0" -DIDENT_USER_HASH=0xcd8f8e91L -DIDENT_UNIX_TIME=0x4158b324L -I/home/lair/mdw/src/tinyos/tinyos-1.x/tos/lib/CC2420Radio Blink.nc -lm
          compiled Blink to build/telos/main.exe
          2338 bytes in ROM
          45 bytes in RAM
          msp430-objcopy --output-target=ihex build/telos/main.exe build/telos/main.ihex
          If you see any errors, then there is a problem with your TinyOS setup.
        • Plug a Telos mote into a USB port. (For a Telos mote that has not been programmed before, the LEDs will strobe in a mesmerizing pattern. If this does not happen, the mote is not receiving power from the USB port, so there might be a problem with the USB interface on your machine.)
          Windows: make telos install.1 bsl,2 
          Linux: make telos install.1 bsl,/dev/ttyUSB0
          In the Windows command above, the last "2" on the line refers to COM3. Use the appropriate number for the COM port that your machine uses for the USB interface.

          The red and green LEDs on each corner of the mote should blink, indicating that the node is being reprogrammed. After programming has completed, just the red LED should blink on and off once a second.

          Congratulations -- you have successfully programmed a mote!

    • Step 2: Quickly, step through Tutorials 2 & 3, for TinyOS and nesC programming understanding.
    • Step 3: Verify that TinyOS and Java is working by doing the TestSerial check in  Tutorial 4 & the Oscilloscope in Tutorial 5.
    • Step 4: Begin working on a simple sensor reading application (originally designed by Matt Welsh). Code and  Demo will be due by end of Lab II on 2/15. (Note that on 2/15 we will also have a short presentation on TOSSIM).
      • To learn the ropes of TinyOS program development, your first task is to write a simple program in which the status of each node's light sensor is shown on the LEDs of the other  motes. You will be given three motes to Demo with. One of them will be "red", the other "green", and the last"blue". The appropriate color LED should be lit on the mote, as well as the other motes, when the light sensor reading on your "red" is above some threshold value. When the light sensor is below the threshold, the LED should be off on all motes. This is a pretty silly/simple program but requires you to deal with sensors, timing, and radio communication.

        There are two light sensors on the Telos mote: A "total solar radiation" (TSR) sensor, and a "photosynthetically active radiation" (PAR) sensor.  You are required to use only the TSR sensor. This sensor is fairly sensitive, so you will need to use a fairly low threshold (between 30 and 50) to distinguish between "light" and "dark" in your application.

        To get started with your program, we suggest you take the code from a simple program (e.g., Blink) and modify it. You must use the same Makefile format as other TinyOS applications. That is, don't try to write a new Makefile "by hand" -- the file must include the lines

        COMPONENT=YourAppName
        include $(MAKERULES)
        where YourAppName is the name of the main component in your application, and MAKERULES has been set previously as part of your Telos installation. You are welcome to develop your program outside of the tinyos-2.x/apps directory, but be sure you include the Makerules file appropriately (and keep in mind that you need to set the MAKERULES environment variable as explained here). The TinyOS make system is pretty sophisticated and we strongly suggest you simply use it this way rather than trying to hack together your own Makefiles.

        In order to avoid packet collisions with other groups, select your Radio Channel in the Makefile.

        NOTE (for your knowledge): Another approach to avoid packet collisions with other groups, is to select an Active Message GroupID in the range 0x10 through 0x50. The GroupID is used to differentiate between radio messages transmitted among "groups" of nodes. To set the GroupID, set the following line at the top of your Makefile, before it includes the Makerules file: DEFAULT_LOCAL_GROUP = 0x40 # For example!!!! The GroupID must be the same on all motes that you are programming in order for them to see each other's packets.

        This program is fairly straightforward. The red node should periodically sample their light sensor (every second). If the sensor value is below the threshold, it should turn on its appropriate LED color. Likewise, if the value is above the threshold, it should turn off its LED. In both cases, the node should broadcast a radio message indicating its state to the other node. Upon reception of such a message, a node should turn the appropriate LED (it's designated color) on or off.

        A node can identify itself using the macro TOS_LOCAL_ADDRESS which is set when you type

        make telos install.1 
        In this case, the mote is being programmed with TOS_LOCAL_ADDRESSset to 1. You can substitute '1' with any other numeric value to give the node a different ID.  This allows you to use the same application for all nodes, and just use a case statement to select the mode in use. IE. Use this address to select LED color of the node (e.g., red=1, green=2, etc.) .
      • Extra Credit: Collaborative Sensor Readings (Demo, in addition to above, at Lab #2)
        • Each mote should periodically sample and communicate their light sensor (every second). 
        • Each mote should not display it's own reading, but turn on it's LED for identification purposes. Meaning the red mote, should always light the "red" LED.
        • For each sensor with a value which is above the threshold, the nodes should turn on the  appropriate LED colors. For example, if "red" and "green" are above the threshold, then the "green" node should light "red", the "red" node should light "green", and the "blue" node should light "red" & "green".  

Lab #2 (in Lecture 2/18/09)
TinyOS Basics (continued
  • Prior to 2/18/07:
    • Work on the simple application (see Lab I). Code (submit TAR/ZIP file link by e-mail) and Demo will be due by end of Lab II on 2/18.
      • You make discuss implementation with other groups and on the discussion board. 
      • DO YOUR OWN WORK!!!!! DO NOT pass around code. If any plagarism is found, you will FAIL. 
  • On 2/18/07:
    • Load your sensor reading application on the motes. Show your successful Demo to either the Prof. or TA, and get your Lab signed off on. 
    • Use the remaining part of Lab to use/ask questions about TinyOS, or experiment with the motes.

Lab #3 (in Lecture 3/4/09)
Simon Game [pdf]

Lab #4 (in Lecture 5/6/09)
Sensor Network Projects [pdf]