Come leggere le misure di temperatura, umidità e luce con Contiki-OS?
Domanda
Vorrei sapere come misurare la temperatura, la luce e l'umidità con un programma Contiki.
Sto usando un Mote Telosb (Sky Mote), quindi questi tre sensori sono integrati nel Mote stesso.
PS: Sto lavorando su Contiki-OS 2.7
Soluzione
Per utilizzare i sensori di luce e temperatura dovrai aggiungere il successivo:
#include "dev/sht11-sensor.h"
#include "dev/light-sensor.h"
.
Quindi è possibile utilizzare le funzioni successive:
static int
get_light(void)
{
return 10 * light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC) / 7;
}
static int
get_temp(void)
{
return ((sht11_sensor.value(SHT11_SENSOR_TEMP) / 10) - 396) / 10;
}
.
Ad esempio, un'applicazione minima per mostrare i valori di tali sensori sarebbe:
#include "contiki.h"
#include "dev/sht11-sensor.h"
#include "dev/light-sensor.h"
#include "dev/leds.h"
#include <stdio.h>
//Declare the process
PROCESS(send_sensor_info_process, "Print the Sensors Information");
//Make the process start when the module is loaded
AUTOSTART_PROCESSES(&send_sensor_info_process);
/*---------------------------------------------------------------------------*/
static int
get_light(void)
{
return 10 * light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC) / 7;
}
/*---------------------------------------------------------------------------*/
static int
get_temp(void)
{
return ((sht11_sensor.value(SHT11_SENSOR_TEMP) / 10) - 396) / 10;
}
/*---------------------------------------------------------------------------*/
//Define the process code
PROCESS_THREAD(send_sensor_info_process, ev, data)
{
PROCESS_BEGIN();
SENSORS_ACTIVATE(light_sensor);
SENSORS_ACTIVATE(sht11_sensor);
printf("Light: %d \n", get_light());
printf("Temperature: %d \n", get_temp());
PROCESS_END();
}
. Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow