Accelerometer using TELOSB & ADXL345
Embedded Systems Course, TAU, Fall 2013/14
Aviv Zaharoni & Tal David
Supervision of Prof. Sivan Toledo


Our project main goal is to measure person acceleration in different daily actions and present the results visually as a graph.

Our product consists of a Tmote-sky TelosB board with MSP430 MCU, and a ADXL345 triple axis accelerometer. The code is written over the Contiki OS.

The interface is very simple: while the board is on, the ADXL perform an acceleration measurement (x,y,z axis) every given amount of seconds (this is set in the code) and the result is written to the external flash memory of the TelosB. Tapping on the device causes the ADXL to sleep, and the measurements stop. When the device is connected to a PC via USB, one can use our Python script to read the data from the flash and generate graphs. NOTE: pressing the RESET button on the board erases the content of the flash (previous measurements).

Basic Design

Our first step was to connect the ADXL345 to the TelosB module. The ADXL345 as schematic symbol is shown below:

taken from Sparkfun
In the following schematic symbols, taken from the TelosB datasheet (attached at the 'Datasheets & Code' section), we marked the pins we used to connect the two modules in order to use SPI 4-Wire protocol.

The TelosB pins which are used used to connect the ADXL345

Using ADXL Registers (Reading and Writing)

We communicate with the ADXL345 using 4-wire SPI protocol. The basic communication is reading from the ADXL registers and writing to them. Reading from the registers is the way to get the measurements results, and writing to them is the way to set measurements configuration (i.e. resolution) and change the mode of the ADXL (sleep mode, measurement mode, standby mode, etc.).

In order to read from the register, we implemented a function that performs the following protocol. The function controls the clock for the ADXL during the reading transaction (Bit banging). All the delays are specified in the datasheet (and in the code).

SPI 4-Wire read transaction schematic diagram

Similarly, we implemented a function to write to a register at specified address. In addition to the register’s address, this function takes the 8-bit data word to write as a parameter. This function performs the SPI 4-Wire write protocol that is shown in the following figure.

SPI 4-Wire write transaction schematic diagram

To implement the read/write functions correctly, we used the Contiki built-in function clock-delay to create dealy of a given amount of nano-seconds.

Using the Flash

The TelosB board uses the ST MP2580 serial flash memory for external data and code storage. We used this memory to store measurements results. The flash holds 1024kB of data, and is decomposed into 16 segments, each of size 64kB. The flash shares SPI communication line with the CC2420 transceiver.

MP2580 schematic symbol, taken from the TelosB datasheet

Main Obstacle
We used RADIO_SO pin, which is the Q input pin of the flash, to commuincate with the ADXL345. Therefore, we cannot communicate with both the ADXL and the flash memory simultaneously. The direction of this pin depends on whether we communicate with the flash or with the accelerometer.

We used the built-in Contiki functions in /dev/xmem.c to perform writing of data to the flash memory and to read this data afterwards.

Python Utility

In order to visually show the measurements result, we used Python modules matplotlib to generate graphs.

A text file with the data from the flash is created, and the graph are made out from it by the python tool.


The following graph was generated by random movements of the board. The corresponding results' text file is attached.

Datasheets & Code