Programming Assignment 1
Programming the motes:
The purpose of this assignment is to become familiar with programming on mica2 motes. This assignment will involve reading through the tinyos tutorial lessons 1 through 4 and uploading applications 1 and 4 on the mica motes. And trying out exercise listed on lesson 1 and exercise 2 of lesson 4. Exercise 2 of lesson 4 requires you to sense light data in one mote and transmit data and display the last 3 bits of the light reading on another mote. To upload the applications onto the motes, you have to use the machine that has been setup in BY517BB. There will be a signup sheet for using the machine.
The Mica2 mote has a processor, radio, and leds on it. It also has provision for interfacing with sensor boards. MTS300CA is an example of a sensor board that can be interfaced with Mica2 motes. This sensor board contains temperature, light, acoustic and sounder sensor devices.
The motes can be programmed by attaching them to a Mote Interface Boards (MIB510). The MIB510 is interfaced by connecting it to the serial port. The Mica2 motes have an on board flash that can be programmed. The mote that is to be programmed is connected to the 51 pin male connector on the board. Motes run a multithreaded operating system called TinyOS. TinyOS is based on component model. Each component declares the commands it uses and the events it will signal. A simple FIFO scheduler will be part of each program uploaded onto the mote. The program will consist of code for components that will be used. The components communicate with each other by passing commands. Events are usually initiated by hardware devices. Based on the event, the component related to that event will issue one or more commands to other components. TinyOS system, libraries, and applications are written in the NesC language. NesC has a C-like syntax. The machine to which the MIB is connected contains the TinyOS code, (i.e.) the code for the components. We write our code by using the component code that is already present in TinyOS. To compile the program, we use an ncc compiler. The output by default is called main.exe. Then avr-objcopy converts the exe file produced by ncc into a text format that can be used for programming the mote's flash.
To program the motes, first run the cygwin batch file located on the desktop. Cygwin is a linux like environment for Windows machines. Attach the mote to a MIB510, then attach the MIB510 to the PC via the serial port. Change directory in the cygwin window to /opt/tinyos-1.x/. This directory contains the source files for tinyos. The /opt/tinyos-1.x/apps contains sample applications that can be run on motes. The apps directory contains a set of directories, each of which contain an application. To compile an application, change to the particular directory, and type "make mica2". If it is successful it will output the amount of RAM and ROM space the program will require. The output of the make command will be main.srec. Now this can be used for programming the flash memory. The make file has an install option that takes care of uploading the program onto the flash. The install option uses a program called "uisp" to upload the program onto the flash. The TinyOS directory also contains tiny os tutorial. It also contains manuals for motes, sensor boards and for tiny os.
The machine in BY517BB will have a programming board attached to it. The following command is used to program a mote using programming board "MIB510=COM1 make mica2 install".
To complete this assignment it would be a good idea to install tinyos (available from tinyos.net which includes the cygwin installation) on your own machine. You'll be able to examine the tinyos code, modify example application and compile them. After this you can come to the lab to upload applications in lesson 1 and 4 onto motes. TinyOS comes with a simulator called TOSSIM. You use TOSSIM to test the example programs. Lesson 5 of tinyos tutorial gives an introduction to TOSSIM.