Difference between revisions of "Sensor acquisition"

From Contiki
Jump to: navigation, search
(Code)
Line 6: Line 6:
  
 
This article is about the Sensor Acquisition Program, which is used to show the Temperature, Humidity and Light Intensity in the vicinity of Tmote Sky.
 
This article is about the Sensor Acquisition Program, which is used to show the Temperature, Humidity and Light Intensity in the vicinity of Tmote Sky.
 +
 +
== Sensor Acquisition Program on the Tmote Sky! ==
 +
 +
=== Step 1 ===
 +
 +
Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.
 +
 +
:: <code>make TARGET=sky savetarget</code>    (This save the target for any future compilations)
 +
:: <code>make hello-world.upload</code>    (This will upload the code on the Tmote Sky)
 +
:: <code>make login</code>    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)
 +
 +
=== Step 2 ===
 +
 +
Press the reset button on the Tmote Sky. The following message will appear on the terminal window
 +
 +
:: <code>Contiki 2.7 started. Node id is set to 3.</code>
 +
:: <code>Rime started with address 3.0</code>
 +
:: <code>MAC 00:12:ff:11:65:23:52:ed</code>
 +
:: <code>Starting 'Hello world process'</code>
 +
:: <code>Hello, world</code>
 +
 +
: 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.
 +
 +
  
 
== Code ==
 
== Code ==
  
<code><nowiki>PROCESS(sensor_acq_process,"Sensor Acquisition");
+
<code>PROCESS(sensor_acq_process,"Sensor Acquisition");
 
AUTOSTART_PROCESSES(&sensor_acq_process);
 
AUTOSTART_PROCESSES(&sensor_acq_process);
  
Line 71: Line 99:
 
       PROCESS_END();
 
       PROCESS_END();
  
}</nowiki></code>
+
}</code>
  
 
== You will learn ==
 
== You will learn ==
Line 102: Line 130:
  
 
This will print the words "Hello, world" on the terminal window. 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.
 
This will print the words "Hello, world" on the terminal window. 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.
 
 
:: <code>make TARGET=sky savetarget</code>    (This save the target for any future compilations)
 
:: <code>make hello-world.upload</code>    (This will upload the code on the Tmote Sky)
 
:: <code>make login</code>    (This will enable us to view the output. If permission error occurs, use sudo command at the beginning)
 
 
=== Step 2 ===
 
 
Press the reset button on the Tmote Sky. The following message will appear on the terminal window
 
 
:: <code>Contiki 2.7 started. Node id is set to 3.</code>
 
:: <code>Rime started with address 3.0</code>
 
:: <code>MAC 00:12:ff:11:65:23:52:ed</code>
 
:: <code>Starting 'Hello world process'</code>
 
:: <code>Hello, world</code>
 
 
: 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.
 
  
  
  
 
[[Contiki_tutorials | Back to Contiki Tutorials]]
 
[[Contiki_tutorials | Back to Contiki Tutorials]]

Revision as of 11:31, 3 August 2014

Back to Contiki Tutorials

Introduction

This article is about the Sensor Acquisition Program, which is used to show the Temperature, Humidity and Light Intensity in the vicinity of Tmote Sky.

Sensor Acquisition Program on the Tmote Sky!

Step 1

Using the opened terminal window compile and upload the Sensor Acquisition program on the Tmote Sky.

make TARGET=sky savetarget (This 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)

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.


Code

PROCESS(sensor_acq_process,"Sensor Acquisition"); AUTOSTART_PROCESSES(&sensor_acq_process);

PROCESS_THREAD(sensor_acq_process,ev,data) {

     static struct etimer et;
     static int val;
     static struct sensors_sensor *sensor;
     static float s = 0;
     static int dec;
     static float frac;
     PROCESS_BEGIN();
     printf("Starting Sensor Example.\n");


     while(1)
     {

etimer_set(&et, CLOCK_SECOND * 2); SENSORS_ACTIVATE(light_sensor);

     	   SENSORS_ACTIVATE(sht11_sensor);
       

PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));


          val = sht11_sensor.value(SHT11_SENSOR_TEMP);
     	   if(val != -1) 
     	   {

s= ((0.01*val) - 39.60);

     	  	dec = s;
     	  	frac = s - dec;
     	  	printf("\nTemperature=%d.%02u C (%d)\n", dec, (unsigned int)(frac * 100),val);               
          }

val=sht11_sensor.value(SHT11_SENSOR_HUMIDITY); if(val != -1)

     	   {

s= (((0.0405*val) - 4) + ((-2.8 * 0.000001)*(pow(val,2))));

     	  	dec = s;
     	  	frac = s - dec;
     	  	printf("Humidity=%d.%02u % (%d)\n", dec, (unsigned int)(frac * 100),val);               
          }
          val = light_sensor.value(LIGHT_SENSOR_TOTAL_SOLAR);
     	   if(val != -1) 
     	   {
     		s = (float)(val * 0.4071);
     	  	dec = s;
     	  	frac = s - dec;
     	  	printf("Light=%d.%02u lux (%d)\n", dec, (unsigned int)(frac * 100),val);               
          } 

etimer_reset(&et);

   	   SENSORS_DEACTIVATE(light_sensor);
   	   SENSORS_DEACTIVATE(sht11_sensor);
     } //end of while
   
     PROCESS_END();

}

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

Step 4

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

./hello-world.native

Step 5

This will print the words "Hello, world" on the terminal window. 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.


Back to Contiki Tutorials