Tuesday, May 15, 2012

Install Contiki 2.5 on ubuntu 11.10

  • Contiki – a dynamic operating system for networked embedded systems
  • Loadable modules, multiple network stacks,
  • multiple threading models
  • Open source; 3-clause BSD licence
  • Small memory footprint
  • Designed for portability
Here I will explain you how to install it manually in Ubuntu 11.10. (This method works for any ubuntu distribute and any contiki distribute). You can use Instant contiki Instead of this method.

1. Install msp430 tool chain. Type this command in terminal

sudo apt-get install binutils-msp430 gcc-msp430 msp430-libc

2. Install the AVR tool chain. Type this command in terminal

sudo apt-get install gcc-avr binutils-avr gdb-avr avr-libc avrdude

3. Now you need JRE and JDK. Ubuntu is not providing sun java repositories now. So you can install openjdk as a substitute for it (Works well). Use this commands to install.

sudo apt-get install openjdk-7-jdk openjdk-7-jre

4. Then you need to setup JAVA_HOME and PATH environment variables. Refer this link to setup java path. Or if you need to install sun(oracle) java refer this link.

5. To run cooja simulator you will need Ant. To install it type this command in the terminal. 

sudo apt-get install ant

6. Then you need to download contiki source code. Use this sourceforge link to download it. You can select what version you like.

7. Ok now you have installed enough sufficient tools to run contiki. Unzip the contiki2.5.zip and change directory in to it. Then you need to go in to Examples/Hello-world. 

8. Type this in terminal. make TARGET=native hello-world. If no error occur type this in terminal. ./hello-world.native. If you get this out put, you just say hello to contiki world, congratulations. 

9. Now you need to check your program in cooja simulator. Run this commands. 

$cd contiki-2.5/tools/cooja
$ant run

Then cooja simulator will be opened. Follow the instructions on the website that I linked. 

10. Then you need to check your program in mspsim simulator. 
Here I used my own simple code to check mspsim.

$cd contiki-2.5/Examples/blink
make TARGET=sky blink.mspsim

Here is the screen shot of what I get

Ok. Now you correctly and manually installed contiki 2.5 in ubuntu.  

If you get an error on step 9 and 10 (this occurs when using msp430 micro controller chips,Avr do not have this issue) that is msp430 tool chain problem in ubuntu (sys/unistd.h missing). There is a naive method to solve it. Its very simple than change your operating system to ubuntu 11.04 or use instant contiki. You need to download this file. Then you need copy that file in to/usr/msp430/include/sys. 

To do it run this command. 
sudo cp unistd.h /usr/msp430/include/sys

Ok then your problem should be solved. 

Again I have to ask you, are you getting this kind of error? 
"/core/dev/ds2411.c:199: undifined reference to 'BV'."

Add these lines to following file. 

#define _BV(bitno)   1<<bitno   
#define BV(bitno) _BV(bitno)


Ok. I think you are now free to do any development using contiki.


  1. Hi All,
    >Then cooja simulator will be opened. Follow the instructions on the website that I linked.
    when i follow the instructions, i created one simulation and added one motes, it all went well. but when i click start on Simulation Control panel. it failed, dumped these out.

    any help will be appreciated.


    at se.sics.cooja.mspmote.MspMote.execute(MspMote.java:310)
    at se.sics.cooja.mspmote.MspMote.execute(MspMote.java:277)
    at se.sics.cooja.motes.AbstractWakeupMote$1.execute(AbstractWakeupMote.java:48)
    at se.sics.cooja.Simulation.run(Simulation.java:280)
    at java.lang.Thread.run(Thread.java:679)
    Caused by: se.sics.mspsim.core.EmulationException: Executing MSP430X instruction but MCU is not a MSP430X
    at se.sics.mspsim.core.MSP430Core.emulateOP(MSP430Core.java:1032)
    at se.sics.mspsim.core.MSP430.stepMicros(MSP430.java:253)
    at se.sics.cooja.mspmote.MspMote.execute(MspMote.java:304)
    ... 4 more

    1. can you add mote type cooja (contiki) and start simulation?


    2. > make broadcast-example.cooja TARGET=cooja
      gcc -I'/include' -I'/include/linux' -fno-builtin-printf -Wall -g -I/usr/local/include -DCLASSNAME=Lib1 -DWITH_UIP6=1 -DUIP_CONF_IPV6=1 -DUIP_CONF_IPV6_RPL=1 -I. -I../../../platform/cooja/. -I../../../platform/cooja/dev -I../../../platform/cooja/lib -I../../../platform/cooja/sys -I../../../platform/cooja/cfs -I../../../platform/cooja/net -I../../../core/dev -I../../../core/lib -I../../../core/net -I../../../core/net/mac -I../../../core/net/rime -I../../../core/net/rpl -I../../../core/sys -I../../../core/cfs -I../../../core/ctk -I../../../core/lib/ctk -I../../../core/loader -I../../../core/. -I../../../apps/servreg-hack -I../../../platform/cooja/ -c ../../../platform/cooja/./contiki-cooja-main.c -o contiki-cooja-main.o
      ../../../platform/cooja/./contiki-cooja-main.c:39:17: fatal error: jni.h: No such file or directory
      compilation terminated.
      make: *** [contiki-cooja-main.o] Error 1
      Process returned error code 2

      Chathuranga, thanks a lot for your help.

    3. $uname -a
      Linux Ubu 3.0.0-26-generic #43-Ubuntu SMP Tue Sep 25 17:20:50 UTC 2012 i686 i686 i386 GNU/Linux

    4. Please install java again or set path correctly.

  2. help me please

    Thank you very much

    > make hello-world.elf TARGET=micaz
    avr-gcc -DCONTIKI=1 -DCONTIKI_TARGET_MICAZ=1 -Wall -mmcu=atmega128 -gdwarf-2 -fno-strict-aliasing -I../../platform/micaz -I. -I../../core -I../../cpu/avr -DF_CPU=7372800UL -DAUTO_CRC_PADDING=2 -Os -I. -I../../platform/micaz/. -I../../platform/micaz/dev -I../../platform/micaz/dev/sensors -I../../cpu/avr/. -I../../cpu/avr/dev -I../../core/dev -I../../core/lib -I../../core/net -I../../core/net/mac -I../../core/net/rime -I../../core/net/rpl -I../../core/sys -I../../core/cfs -I../../core/ctk -I../../core/lib/ctk -I../../core/loader -I../../core/. -I../../platform/micaz/ -MMD -c ../../cpu/avr/dev/flash.c -o obj_micaz/flash.o
    In file included from ../../cpu/avr/dev/flash.c:4:0:
    /usr/lib/gcc/avr/4.7.0/../../../avr/include/avr/boot.h:112:16: error: attempt to use poisoned "SPMCR"
    make: *** [obj_micaz/flash.o] Error 1
    Process returned error code 2

    1. try with this

      make TARGET=micaz hello-world.upload PORT=/dev/ttyUSB0

  3. hi
    As Josh specified iam also facing the same issue when tried to run a .csc file in cooja simulator. What can be done to overcome that?

  4. you may experience with Java issues. Please install correct version of java

  5. [java]
    [java] > make hello-world.cooja TARGET=cooja
    [java] gcc -I'/include' -I'/include/linux' -fno-builtin-printf -fPIC -Wall -g -I/usr/local/include -DCLASSNAME=Lib1 -I. -I../../platform/cooja/. -I../../platform/cooja/dev -I../../platform/cooja/lib -I../../platform/cooja/sys -I../../platform/cooja/cfs -I../../platform/cooja/net -I../../core/dev -I../../core/lib -I../../core/net -I../../core/net/mac -I../../core/net/rime -I../../core/net/rpl -I../../core/sys -I../../core/cfs -I../../core/ctk -I../../core/lib/ctk -I../../core/loader -I../../core/. -c ../../platform/cooja/./contiki-cooja-main.c -o contiki-cooja-main.o
    [java] ../../platform/cooja/./contiki-cooja-main.c:39:17: fatal error: jni.h: No such file or directory
    [java] #include
    [java] ^
    [java] compilation terminated.
    [java] make: *** [contiki-cooja-main.o] Error 1
    [java] Process returned error code 2
    Can anyone help me out on this problem.