Getting Started with Z1

From Zolertia

Jump to: navigation, search

The fastest and easiest way to program a Z1 is using the combination of Ubuntu, TinyOS and the Z1 sdk for TinyOS. If you already have a TinyOS installation or you're using windows you'll find instructions here.

The official Z1 code is already merged in the main trunk at TinyOS googlecode, however if you like to use the 2.1.1 version you can follow the next steps. We keep a version of TinyOS 2.1.1 code Here


Contents

Install

TinyOS installation has been proved with Ubuntu 8.04LTS Hardy Heron, 9.10 Karmic Koala, 10.04LTS Lucid Lynx, 10.10, 11.10 and 12.04. You can browse and download the Ubuntu version which fits you the most in Here


Installing TinyOS 2.1.2 (released on August 21 2012)

Using stanford repository (be sure to replace "lucid" according to your Ubuntu distro):

$ sudo echo "deb http://tinyos.stanford.edu/tinyos/dists/ubuntu lucid main" >> /etc/apt/sources.list
$ sudo apt-get update
$ sudo apt-get install tinyos-2.1.2

On a clean VM machine using Ubuntu 10.04LTS this is what it looks like (say yes when prompted to install unauthenticated files), if your machine has some mileage (or a previous tinyos install) you will surely will need to install fewer packages:

z1@z1-desktop:~$ sudo apt-get install tinyos-2.1.2 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-2.6.32-21 linux-headers-2.6.32-21-generic
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  avr-binutils-tinyos avr-gcc-tinyos avr-libc-tinyos avr-optional-tinyos
  avr-tinyos avr-tinyos-base avrdude-tinyos ca-certificates-java deputy-tinyos
  graphviz icedtea-6-jre-cacao icedtea-netx java-common libice-dev
  libpthread-stubs0 libpthread-stubs0-dev libsm-dev libx11-dev libxau-dev
  libxcb1-dev libxdmcp-dev libxt-dev msp430-binutils-tinyos msp430-gcc-tinyos
  msp430-libc-tinyos msp430-tinyos msp430mcu-tinyos nesc openjdk-6-jdk
  openjdk-6-jre openjdk-6-jre-headless openjdk-6-jre-lib tinyos-base
  tinyos-required-all tinyos-required-avr tinyos-required-msp430 tinyos-tools
  ttf-dejavu-extra tzdata-java x11proto-core-dev x11proto-input-dev
  x11proto-kb-dev xtrans-dev
Suggested packages:
  graphviz-doc default-jre equivs openjdk-6-demo openjdk-6-source visualvm
  icedtea-plugin sun-java6-fonts ttf-sazanami-gothic ttf-kochi-gothic
  ttf-sazanami-mincho ttf-kochi-mincho ttf-telugu-fonts ttf-oriya-fonts
  ttf-kannada-fonts ttf-bengali-fonts
Recommended packages:
  sun-java5-bin sun-java6-bin
The following NEW packages will be installed:
  avr-binutils-tinyos avr-gcc-tinyos avr-libc-tinyos avr-optional-tinyos
  avr-tinyos avr-tinyos-base avrdude-tinyos ca-certificates-java deputy-tinyos
  graphviz icedtea-6-jre-cacao icedtea-netx java-common libice-dev
  libpthread-stubs0 libpthread-stubs0-dev libsm-dev libx11-dev libxau-dev
  libxcb1-dev libxdmcp-dev libxt-dev msp430-binutils-tinyos msp430-gcc-tinyos
  msp430-libc-tinyos msp430-tinyos msp430mcu-tinyos nesc openjdk-6-jdk
  openjdk-6-jre openjdk-6-jre-headless openjdk-6-jre-lib tinyos-2.1.2
  tinyos-base tinyos-required-all tinyos-required-avr tinyos-required-msp430
  tinyos-tools ttf-dejavu-extra tzdata-java x11proto-core-dev
  x11proto-input-dev x11proto-kb-dev xtrans-dev
0 upgraded, 44 newly installed, 0 to remove and 122 not upgraded.
Need to get 148MB of archives.
After this operation, 195MB of additional disk space will be used.
Do you want to continue [Y/n]? y
WARNING: The following packages cannot be authenticated!
  tinyos-base avr-tinyos-base avr-binutils-tinyos avr-gcc-tinyos
  avr-libc-tinyos avrdude-tinyos avr-tinyos avr-optional-tinyos nesc
  tinyos-tools deputy-tinyos msp430-binutils-tinyos msp430-gcc-tinyos
  msp430-libc-tinyos msp430mcu-tinyos msp430-tinyos tinyos-required-msp430
  tinyos-required-avr tinyos-required-all tinyos-2.1.2

And that is all!

Be sure to check if the toolchain is properly installed by running:

$ msp430-gcc --version

And then configure your work environment as showed Here, be sure to replace the location of tinyos-2.1.2 or comment/comment the toolchain path out if you have multiple setups.


Installing latest toolchain from TinyProd and bleeding edge TinyOS code

Follow the instructions provided in TinyProd to install the toolchain, the official one is the msp430-46 but you can also install msp430-47 but keep in mind this is a development version.

The 4.6.3-LTS20120406 repository contains the following packages for the i386 (32 bit) and amd64 (64 bit) architectures:

  • msp430-46: 20120715
  • msp430-binutils-46: 2.21.1-LTS20120406
  • msp430-gcc-46: 4.6.3-LTS20120406
  • msp430-gdb-46: 7.2-LTS20120406
  • msp430-libc-46: 20120224-LTS20120406+20120502
  • msp430mcu-46: 20120406-LTS20120406+20120502
# Add the following keys
$ gpg --keyserver keyserver.ubuntu.com --recv-keys 34EC655A
$ gpg -a --export 34EC655A | sudo apt-key add -
 
# Add the repository, update and install
$ cd /etc/apt/sources.list.d
$ sudo echo "deb http://tinyprod.net/repos/debian squeeze main" >> tinyprod-debian.list
$ sudo echo "deb http://tinyprod.net/repos/debian msp430-46 main" >> tinyprod-debian.list
$ sudo apt-get update
$ sudo apt-get install msp430-46 nesc tinyos-tools

The msp430-46 tools install into /opt/msp430-46. This allows the default and experimental mspgcc compilers to be installed side by side on the same system. Selection of the operational toolchain is done via the PATH environment variable. This allows for easy comparisons between current and experimental toolchains. This also avoids collisions with tools from the main distribution.

export PATH=/opt/msp430-46/bin:$PATH

If you want to uninstall:

$ sudo apt-get autoremove --purge msp430-46


Then get a fresh copy of TinyOS, you can download directly from the googlecode repository, or from the git mirror site:

$ svn checkout http://tinyos-main.googlecode.com/svn/trunk/ tinyos-main-read-only
git clone git://hinrg.cs.jhu.edu/git/tinyos-2.x.svn   tinyos-2.x


Installing TinyOS 2.1.1

This release is old, I have not retested the packaging (toolchain, etc) kept by Stanford (official packagers), you can also checkout some tinyos-legacy packages from TinyProd. The following instructions may be out of date, so if you need the TinyOS 2.1.1 base files we keep a copy Here, you will need to patch it with the Z1 specifics as instructed below.

You will need to add the following repositories:

For Ubuntu 10.10

sudo su -
echo "deb http://tinyos.stanford.edu/tinyos/dists/ubuntu edgy main" >> /etc/apt/sources.list
echo "deb http://tinyos.stanford.edu/tinyos/dists/ubuntu feisty main" >> /etc/apt/sources.list

For other Ubuntu releases (listed in Prerequisites)

sudo su - 
echo "deb http://tinyos.stanford.edu/tinyos/dists/ubuntu hardy main" >> /etc/apt/sources.list

Now proceed with the installation:

apt-get update
apt-get install tinyos-2.1.1
exit
echo "source /opt/tinyos-2.1.1/tinyos.sh" >> ~/.bashrc

Used this as reference

Download and install using the following command in a terminal:

wget http://sourceforge.net/projects/zolertia/files/tinyos-z1-2.1.1/tinyos-z1-2.1.1-18_i386.deb
sudo dpkg -i tinyos-z1-2.1.1-18_i386.deb

Now exit the terminal for apply the changes.


Final touches

An example of how the tinyos.sh scripts looks like:

#! /usr/bin/env bash
# Here we setup the environment
# variables needed by the tinyos 
# make system
 
echo "Setting up for TinyOS"
export TOSROOT=
export TOSDIR=
export MAKERULES=
 
#TOSROOT="/opt/tinyos-2.1.1"
TOSROOT="/opt/tinyos-2.1.2"
TOSDIR="$TOSROOT/tos"
CLASSPATH=$CLASSPATH:$TOSROOT/support/sdk/java/tinyos.jar
MAKERULES="$TOSROOT/support/make/Makerules"
#export PATH=/opt/msp430-z1/bin:$PATH
#export PATH=/opt/msp430-47/bin:$PATH
 
export TOSROOT
export TOSDIR
export CLASSPATH
export MAKERULES

Remember to change the location of the toolchain in the $PATH and the $TOSROOT TinyOS directory according of the installed version.


Validate the installation

To check if there is a Z1 mote connected:

$ motelist
Reference  Device           Description
---------- ---------------- ---------------------------------------------
Z1RC1031   /dev/ttyUSB0     Silicon Labs Zolertia Z1

Note: due to the recent integration with TinyOS core at trunk, the scripts "motelist" and "tos-bsl" was formerly named "motelist-z1" and "z1-bsl". If you have an outdated version of the Z1 patch file offered above (tinyos-z1-2.1.1-18), you can either manually rename the old scripts. To see where the scripts are located and resolve any possible conflict look at the locations:

$ whereis motelist motelist-z1

Compiling the first TinyOS Program

To check if the installation succeeded we have to open a new terminal and execute the following commands:

cd $TOSROOT/apps/Blink
make z1

If the setup is correct the output should be similar to this:

compiling BlinkAppC to a z1 binary
ncc  -o build/z1/main.exe  -Os -fnesc-separator=__  -mdisable-hwmul  -Wall -Wshadow -Wnesc-all -target=z1 -fnesc-cfile=build/z1/app.c
-board= -DDEFINED_TOS_AM_GROUP=0x22 -DIDENT_APPNAME=\"BlinkAppC\" -DIDENT_USERNAME=\"jordi\" -DIDENT_HOSTNAME=\"jsoucheiron\"
-DIDENT_USERHASH=0x145d5669L -DIDENT_TIMESTAMP=0x4afab531L -DIDENT_UIDHASH=0x6fa552eaL  BlinkAppC.nc -lm 
    compiled BlinkAppC to build/z1/main.exe
            2286 bytes in ROM
              54 bytes in RAM
msp430-objcopy --output-target=ihex build/z1/main.exe build/z1/main.ihex
    writing TOS image


Programing the Z1 for first time

We can program the Blink application in our Z1 executing the following commands:

cd /opt/tinyos-2.1.1/apps/Blink
make z1 install

If you've programmed successfully the Z1 you should see the leds blinking


Known Issues

Permission denied errors

  • It may not be possible to compile programs with non privileged users. To solve this issue there are 2 easy solutions:
    • Use sudo
    • Change tinyos-2.1.1 folder permisions:
sudo chown -R YourUser:YourGroup /opt/tinyos-2.1.1/


Install legacy versions

You can install the old packages using the packages from TinyProd

The packages you want are the -legacy ones. So the steps are the following:

1. Remove the previously installed tinyos packages:

sudo dpkg -P `dpkg -l nesc '*tinyos*' | grep ^ii | awk '{ print $2 }' | xargs`

2. Add the following line to /etc/apt/source.list:

deb http://tinyprod.net/debian-dev squeeze main

3. Install the new packages:

sudo apt-get update
sudo apt-get install nesc msp430-tinyos-legacy avr-tinyos-legacy
Personal tools
Navigation
MansOS Support
General guides and apps
Assistance