Hello World

From Contiki
Jump to: navigation, search

Back to Contiki Tutorials

Introduction

This article is about the Hello World program, which is used to show the compilation and upload steps of a simple program on a Tmote Sky.

You will learn

This tutorial teaches you how to compile a program on Contiki OS and also the most basic syntax of programming in ContikiOS.

Step 1

Open the terminal window.

Step 2

In the terminal window, go to the hello world example folder.

 cd /examples/hello-world

Step 3

Compile the code for the native platform (to be used when no mote is connected to the laptop.)

 make TARGET=native

If there is any bug during compilation which says "#include<curses.h> : No such file or directory" you need to do the following on Ubuntu.

If you are currently in the terminal, type "sudo apt-get install libncurses5-dev"(for which you should have installed the "apt" for 32-bit using "sudo dpkg -i apt_0.8.16~exp12ubuntu10.10_i386.deb" and for 64-bit using sudo dpkg -i apt_0.8.16~exp12ubuntu10.10_amd64.deb")

You need to also install a version of javac compiler using the command "sudo apt-get install openjdk-7-jdk".

Step 4

Once the compilation is over, run the Hello World program.

 ./hello-world.native

Step 5

You should be seeing the following on the terminal:

 Contiki 3.0 started with IPV6, RPL
 Rime started with address 1.2.3.4.5.6.7.8
 MAC nullmac RDC nullrdc NETWORK sicslowpan
 Tentative link-local IPv6 address fe80:0000:0000:0000:0302:0304:0506:0708
 Hello, world

The code will appear to hang, however, it is still running on Contiki, but not producing any output as the Hello World program is finished. Press Ctrl-C to quit.

Hello World on the Tmote Sky!

Step 1

Using the opened terminal window, compile and upload the Hello World program on the Tmote Sky.

 make TARGET=sky savetarget    (This to save the target for any future compilations)
 make hello-world.upload    (This will upload the code on the Tmote Sky)
 make login    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)

- If you are getting errors after running the command make TARGET=sky savetarget , please make sure you run the following to install a package:

 apt-get install gcc-msp430

- If you get Permission Denied message as below:

could not open port: [Errno 13] Permission denied: '/dev/ttyUSB0' make[2]: *** [sky-r._dev_ttyUSB0] Error 1 make[2]: Target `sky-reset-sequence' not remade because of errors. make[2]: Leaving directory `/home/user/contiki-2.7/examples/hello-world' make[1]: *** [sky-reset] Error 2 make[1]: Leaving directory `/home/user/contiki-2.7/examples/hello-world' make: *** [hello-world.upload] Error 2

Please make sure you are running as root by typing the following:

 sudo -s

- If you are getting the following error after running the make login:

using saved target 'sky'

 ../../tools/sky/serialdump-linux -b115200 /dev/ttyUSB0
 ../../tools/sky/serialdump-linux: 1: ../../tools/sky/serialdump-linux: Syntax error: Unterminated quoted string
 make: *** [login] Error 2

Please follow the below steps:

1. Download the new serialdump-linux file from the web page:

  https://github.com/cmorty/contiki/blob/pull/serialdump/tools/sky/serialdump-linux

2. Rename the current serialdump-linux file with the name serialdump-linux.bck in the /contiki/tools/sky directory.

3. Copy the new serialdump-linux file in the directory contiki/tools/sky

4. Change the permissions of the new serialdump-linux file with the command

 chmod  775 serialdump-linux

Step 2

Press the reset button on the Tmote Sky. The following message will appear on the terminal window

 Contiki 2.7 started. Node id is set to 3.
 Rime started with address 3.0
 MAC 00:12:ff:11:65:23:52:ed
 Starting 'Hello world process'
 Hello, world
The boot up code of Contiki-OS prints the first four lines whereas the last line is printed by the Hello World program.

Step 3

Press Ctrl-C to quit.

Try This

You can upload and login with one line. You can also point the upload and/or login to a specific device path (use `dmesg` to find the device path of a mote after inserting it to your computer). Try the following command:

 make TARGET=sky MOTES=/dev/ttyUSB0 hello-world.upload login


Back to Contiki Tutorials