Added PM10 GP2Y1010AU0F sensor driver and demo test

This commit is contained in:
Toni Lozano 2016-01-22 12:15:33 +01:00
parent 4907842821
commit 42e1beb931
6 changed files with 71 additions and 86 deletions

View File

@ -1,6 +1,5 @@
/*
* Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/
* Copyright (c) 2015, Zolertia - http://www.zolertia.com
* Copyright (c) 2016, Zolertia - http://www.zolertia.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -30,28 +29,17 @@
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
*
*
* \addtogroup zoul-examples
* @{
*
* \file
* Example demonstrating the Zoul module on the RE-Mote & AAC sensor 0-5V 50Amps AC
*/
#include "contiki.h"
#include "cpu.h"
#include "sys/etimer.h"
#include "sys/rtimer.h"
#include "dev/leds.h"
#include "dev/uart.h"
#include "dev/button-sensor.h"
#include "dev/zoul-sensors.h"
#include "dev/watchdog.h"
#include "dev/serial-line.h"
#include "dev/sys-ctrl.h"
#include "net/rime/broadcast.h"
#include "dev/adc-sensors.h"
#include <stdio.h>
#include <stdint.h>
/*---------------------------------------------------------------------------*/
@ -65,24 +53,16 @@ static struct etimer et;
static uint16_t counter;
/*---------------------------------------------------------------------------*/
PROCESS(zoul_demo_process, "Zoul demo process");
AUTOSTART_PROCESSES(&zoul_demo_process);
PROCESS(test_aac_sensor_process, "Test AAC sensor process");
AUTOSTART_PROCESSES(&test_aac_sensor_process);
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(zoul_demo_process, ev, data)
PROCESS_THREAD(test_aac_sensor_process, ev, data)
{
PROCESS_BEGIN();
counter = 0;
/* Configure the user button */
button_sensor.configure(BUTTON_SENSOR_CONFIG_TYPE_INTERVAL,
BUTTON_PRESS_EVENT_INTERVAL);
/* Configure the ADC ports */
/* Use pin number not mask, for example if using the PA5 pin then use 5 */
printf("return configure, %d \n", adc_sensors.configure(ANALOG_AAC_SENSOR, ADC_PIN));
@ -101,8 +81,6 @@ PROCESS_THREAD(zoul_demo_process, ev, data)
printf("-----------------------------------------\n"
"Counter = 0x%08x\n", counter);
//printf("ADC3 = %d raw\n", (adc_sensors.value(ANALOG_AAC_SENSOR)/1.76));
printf("AC Amps = %d mA\n", adc_sensors.value(ANALOG_AAC_SENSOR));
etimer_set(&et, LOOP_INTERVAL);
@ -114,7 +92,6 @@ PROCESS_THREAD(zoul_demo_process, ev, data)
}
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
* @}
*/

View File

@ -46,23 +46,28 @@
#include "contiki.h"
#include "dev/leds.h"
#include "dev/adc-sensors.h"
#include "dev/zoul-sensors.h"
#include "lib/sensors.h"
#include "dev/pm10-sensor.h"
/*---------------------------------------------------------------------------*/
#define ADC_PIN 2
#define SENSOR_READ_INTERVAL (CLOCK_SECOND / 8)
#define SENSOR_READ_INTERVAL (CLOCK_SECOND)
/*---------------------------------------------------------------------------*/
PROCESS(remote_pm10_sensor_process, "PM10 sensor test process");
AUTOSTART_PROCESSES(&remote_grove_loudness_process);
PROCESS(test_pm10_sensor_process, "Test PM10 sensor process");
AUTOSTART_PROCESSES(&test_pm10_sensor_process);
/*---------------------------------------------------------------------------*/
static struct etimer et;
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(remote_pm10_sensor_process, ev, data)
PROCESS_THREAD(test_pm10_sensor_process, ev, data)
{
PROCESS_BEGIN();
SENSORS_ACTIVATE(pm10);
uint16_t pm10_value;
static uint16_t pm10_value;
/* Configure the ADC ports */
/* Use pin number not mask, for example if using the PA5 pin then use 2 */
adc_sensors.configure(ANALOG_PM10_SENSOR, ADC_PIN);
printf("return configure, %d \n", pm10.configure(SENSORS_ACTIVE, ADC_PIN));
/* And periodically poll the sensor */
@ -72,10 +77,10 @@ PROCESS_THREAD(remote_pm10_sensor_process, ev, data)
leds_toggle(LEDS_GREEN);
pm10_value = adc_sensors.value(ANALOG_PM10_SENSOR);
pm10_value = pm10.value(NULL);
if(pm10_value != ADC_WRAPPER_ERROR) {
printf("%u\n", pm10_value);
printf("PM10 value = %u ppm\n", pm10_value);
} else {
printf("Error, enable the DEBUG flag in adc-wrapper.c for info\n");
PROCESS_EXIT();

View File

@ -1,6 +1,5 @@
/*
* Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/
* Copyright (c) 2015, Zolertia - http://www.zolertia.com
* Copyright (c) 2016, Zolertia - http://www.zolertia.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -30,27 +29,17 @@
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
*
*
* \addtogroup zoul-examples
* @{
*
* \file
* Example demonstrating the Zoul module on the RE-Mote & VAC sensor
*/
#include "contiki.h"
#include "cpu.h"
#include "sys/etimer.h"
#include "sys/rtimer.h"
#include "dev/leds.h"
#include "dev/uart.h"
#include "dev/button-sensor.h"
#include "dev/zoul-sensors.h"
#include "dev/watchdog.h"
#include "dev/serial-line.h"
#include "dev/sys-ctrl.h"
#include "net/rime/broadcast.h"
#include "dev/adc-sensors.h"
#include <stdio.h>
#include <stdint.h>
/*---------------------------------------------------------------------------*/
@ -64,24 +53,16 @@ static struct etimer et;
static uint16_t counter;
/*---------------------------------------------------------------------------*/
PROCESS(zoul_demo_process, "Zoul demo process");
AUTOSTART_PROCESSES(&zoul_demo_process);
PROCESS(test_vac_sensor_process, "test VAC sensor process");
AUTOSTART_PROCESSES(&test_vac_sensor_process);
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(zoul_demo_process, ev, data)
PROCESS_THREAD(test_vac_sensor_process, ev, data)
{
PROCESS_BEGIN();
counter = 0;
/* Configure the user button */
button_sensor.configure(BUTTON_SENSOR_CONFIG_TYPE_INTERVAL,
BUTTON_PRESS_EVENT_INTERVAL);
/* Configure the ADC ports */
/* Use pin number not mask, for example if using the PA5 pin then use 5 */
printf("return configure, %d \n", adc_sensors.configure(ANALOG_VAC_SENSOR, ADC_PIN));
@ -100,10 +81,8 @@ PROCESS_THREAD(zoul_demo_process, ev, data)
printf("-----------------------------------------\n"
"Counter = 0x%08x\n", counter);
//Value in raw after voltage divisor
printf("ADC3 = %d V\n", (adc_sensors.value(ANALOG_VAC_SENSOR)/0.0088));
//AC voltage value, with applied corresponding sensor algorithm
printf("AC voltage = %d V\n", adc_sensors.value(VAC_VAL));
/*AC voltage value, with applied corresponding sensor algorithm*/
printf("AC voltage = %d V\n", adc_sensors.value(ANALOG_VAC_SENSOR));
etimer_set(&et, LOOP_INTERVAL);
counter++;
@ -114,7 +93,6 @@ PROCESS_THREAD(zoul_demo_process, ev, data)
}
/*---------------------------------------------------------------------------*/
/**
* @}
* @}
* @}
*/

View File

@ -45,7 +45,6 @@
#include "adc-sensors.h"
#include "adc-zoul.h"
#include "zoul-sensors.h"
#include <stdio.h>
#include <stdint.h>
/*---------------------------------------------------------------------------*/
@ -108,6 +107,7 @@ convert_to_value(uint8_t index)
value /= 100000;
return (uint16_t)value;
/* VDD+5 sensors */
case ANALOG_VAC_SENSOR:
/* Linear sensor from 0 to 5 V; 0.0088 resolution*/
value *= 88;
@ -116,13 +116,10 @@ convert_to_value(uint8_t index)
case ANALOG_AAC_SENSOR:
/* Linear sensor from 0 to 5 V;*/
value *= 1.2;
return (uint16_t)value;
case ANALOG_PM10_SENSOR:
/* PM10 sensor from 0 to 5 V; 0.0088 resolution*/
value *= 88;
value /= 10000;
/* PM10 sensor from 0 to 3.9 V;*/
return (uint16_t)value;
default:
@ -205,6 +202,7 @@ configure(int type, int value)
sensors.sensor[sensors.sensors_num].vdd3 = 1;
break;
/*V+5 sensors*/
case ANALOG_VAC_SENSOR:
case ANALOG_AAC_SENSOR:
case ANALOG_PM10_SENSOR:

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Zolertia <http://www.zolertia.com>
* Copyright (c) 2016, Zolertia <http://www.zolertia.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -31,7 +31,7 @@
*/
/*---------------------------------------------------------------------------*/
/**
*
* \addtogroup zoul-pm10-sensor
* @{
*
* \file
@ -44,26 +44,58 @@
#include "contiki.h"
#include "adc-sensors.h"
#include "dev/pm10-sensor.h"
#include "dev/sys-ctrl.h"
#include "lib/sensors.h"
#include "dev/gpio.h"
#include "dev/ioc.h"
/*---------------------------------------------------------------------------*/
static uint8_t enabled;
/*---------------------------------------------------------------------------*/
#ifdef PM10_SENSOR_CONF_CTRL_PIN
#define PM10_SENSOR_CTRL_PIN PM10_SENSOR_CONF_CTRL_PIN
#else
#define PM10_SENSOR_CTRL_PIN 0x07
#endif
#define PM10_SENSOR_PORT GPIO_A_BASE
static int
configure(int value)
configure(int type, int value)
{
int error;
if(type != SENSORS_ACTIVE) {
return PM10_ERROR;
}
/*Set PA7 as output, used as pulse-driven wave*/
ioc_set_over(PM10_SENSOR_PORT, PM10_SENSOR_CTRL_PIN, IOC_OVERRIDE_DIS);
GPIO_SOFTWARE_CONTROL(PM10_SENSOR_PORT, GPIO_PIN_MASK(PM10_SENSOR_CTRL_PIN));
GPIO_SET_OUTPUT(PM10_SENSOR_PORT, GPIO_PIN_MASK(PM10_SENSOR_CTRL_PIN));
GPIO_CLR_PIN(PM10_SENSOR_PORT, GPIO_PIN_MASK(PM10_SENSOR_CTRL_PIN));
/* Use pin number not mask, for example if using the PA5 pin then use 5 */
error = adc_sensors.configure(ANALOG_PM10_SENSORS, value);
error = adc_sensors.configure(ANALOG_PM10_SENSOR, value);
return error;
}
/*---------------------------------------------------------------------------*/
static int
value(void)
value(int type)
{
uint16_t val;
//TODO: Add here GPIO pulses before measuring
/*Set Pulse Wave pin before measure*/
GPIO_SET_PIN(PM10_SENSOR_PORT, GPIO_PIN_MASK(PM10_SENSOR_CTRL_PIN));
/*Pulse wave delay*/
clock_delay_usec(280);
/*Data acquisition*/
val = adc_sensors.value(ANALOG_PM10_SENSOR);
/*Clear pulse wave pin*/
GPIO_CLR_PIN(PM10_SENSOR_PORT, GPIO_PIN_MASK(PM10_SENSOR_CTRL_PIN));
/*Applied constant conversion from UAir project*/
/*to obtain value in ppm (value in mV * 0.28)*/
val *= 28;
val /= 1000;
return val;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Zolertia <http://www.zolertia.com>
* Copyright (c) 2016, Zolertia <http://www.zolertia.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -31,11 +31,8 @@
*/
/*---------------------------------------------------------------------------*/
/**
*
*
*
* \file
* GP2Y1010AU0F PM-10 sensor driver
* GP2Y1010AU0F PM10 sensor driver
* \author
* Toni Lozano <tlozano@zolertia.com>
*/
@ -47,11 +44,9 @@
/* -------------------------------------------------------------------------- */
#define PM10_ERROR -1
#define PM10_PORT ZOUL_SENSORS_ADC3
#define PM10_VAL 0x00
#define PM10_SENSOR "PM10 Sensor"
/* -------------------------------------------------------------------------- */
extern const struct sensors_sensor vac;
extern const struct sensors_sensor pm10;
/* -------------------------------------------------------------------------- */
#endif /* ifndef VAC_SENSOR_H_ */
/**