From 1fca3e810a4c4e1d83cc0a2f82f2c3f74f01c8c8 Mon Sep 17 00:00:00 2001 From: Toni Lozano Date: Wed, 20 Jan 2016 15:50:56 +0100 Subject: [PATCH 1/6] Added PM10 and VAC parameters to adc_sensors driver --- examples/zolertia/zoul/Makefile | 2 +- examples/zolertia/zoul/test-pm10.c | 92 +++++++++++++++++ examples/zolertia/zoul/test-vac-sensor.c | 120 +++++++++++++++++++++++ platform/zoul/dev/adc-sensors.c | 16 ++- platform/zoul/dev/adc-sensors.h | 2 + platform/zoul/dev/pm10-sensor.c | 73 ++++++++++++++ platform/zoul/dev/pm10-sensot.h | 60 ++++++++++++ 7 files changed, 363 insertions(+), 2 deletions(-) create mode 100644 examples/zolertia/zoul/test-pm10.c create mode 100644 examples/zolertia/zoul/test-vac-sensor.c create mode 100644 platform/zoul/dev/pm10-sensor.c create mode 100644 platform/zoul/dev/pm10-sensot.h diff --git a/examples/zolertia/zoul/Makefile b/examples/zolertia/zoul/Makefile index 0b9eef673..b60cf8ccf 100644 --- a/examples/zolertia/zoul/Makefile +++ b/examples/zolertia/zoul/Makefile @@ -4,7 +4,7 @@ CONTIKI_PROJECT = zoul-demo test-tsl2563 test-sht25 test-pwm test-power-mgmt CONTIKI_PROJECT += test-bmp085-bmp180 test-motion test-rotation-sensor CONTIKI_PROJECT += test-grove-light-sensor test-grove-loudness-sensor CONTIKI_PROJECT += test-weather-meter test-grove-gyro test-lcd - +CONTIKI_PROJECT += test-pm10 test-vac-sensor CONTIKI_TARGET_SOURCEFILES += tsl2563.c sht25.c bmpx8x.c motion-sensor.c CONTIKI_TARGET_SOURCEFILES += adc-sensors.c weather-meter.c grove-gyro.c CONTIKI_TARGET_SOURCEFILES += rgb-bl-lcd.c diff --git a/examples/zolertia/zoul/test-pm10.c b/examples/zolertia/zoul/test-pm10.c new file mode 100644 index 000000000..d8e64067a --- /dev/null +++ b/examples/zolertia/zoul/test-pm10.c @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2016, Zolertia - http://www.zolertia.com + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ +/*---------------------------------------------------------------------------*/ +/** + * \addtogroup zoul-examples + * @{ + * + * Demonstrates the operation of the Sharp PM10 analog sensor + * @{ + * + * \file + * GP2Y1010AU0F PM10 sensor example using the ADC sensors wrapper + * + * \author + * Toni Lozano + */ +/*---------------------------------------------------------------------------*/ +#include +#include "contiki.h" +#include "dev/leds.h" +#include "dev/adc-sensors.h" +/*---------------------------------------------------------------------------*/ +#define ADC_PIN 2 +#define SENSOR_READ_INTERVAL (CLOCK_SECOND / 8) +/*---------------------------------------------------------------------------*/ +PROCESS(remote_pm10_sensor_process, "PM10 sensor test process"); +AUTOSTART_PROCESSES(&remote_grove_loudness_process); +/*---------------------------------------------------------------------------*/ +static struct etimer et; +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(remote_pm10_sensor_process, ev, data) +{ + PROCESS_BEGIN(); + + uint16_t pm10_value; + + /* Use pin number not mask, for example if using the PA5 pin then use 2 */ + adc_sensors.configure(ANALOG_PM10_SENSOR, ADC_PIN); + + /* And periodically poll the sensor */ + + while(1) { + etimer_set(&et, SENSOR_READ_INTERVAL); + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); + + leds_toggle(LEDS_GREEN); + + pm10_value = adc_sensors.value(ANALOG_PM10_SENSOR); + + if(pm10_value != ADC_WRAPPER_ERROR) { + printf("%u\n", pm10_value); + } else { + printf("Error, enable the DEBUG flag in adc-wrapper.c for info\n"); + PROCESS_EXIT(); + } + + } + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ + diff --git a/examples/zolertia/zoul/test-vac-sensor.c b/examples/zolertia/zoul/test-vac-sensor.c new file mode 100644 index 000000000..4ecfcf9a6 --- /dev/null +++ b/examples/zolertia/zoul/test-vac-sensor.c @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/ + * Copyright (c) 2015, Zolertia - http://www.zolertia.com + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* + * + * + * @{ + * + * \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 +#include +/*---------------------------------------------------------------------------*/ +#define ADC_PIN 2 +#define LOOP_PERIOD 2 +#define LOOP_INTERVAL (CLOCK_SECOND * LOOP_PERIOD) +#define LEDS_PERIODIC LEDS_GREEN +#define BUTTON_PRESS_EVENT_INTERVAL (CLOCK_SECOND) +/*---------------------------------------------------------------------------*/ +static struct etimer et; + +static uint16_t counter; +/*---------------------------------------------------------------------------*/ +PROCESS(zoul_demo_process, "Zoul demo process"); +AUTOSTART_PROCESSES(&zoul_demo_process); +/*---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(zoul_demo_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)); + + printf("VAC test application\n"); + leds_on(LEDS_PERIODIC); + etimer_set(&et, LOOP_INTERVAL); + + while(1) { + + PROCESS_YIELD(); + + if(ev == PROCESS_EVENT_TIMER) { + leds_toggle(LEDS_PERIODIC); + + printf("-----------------------------------------\n" + "Counter = 0x%08x\n", counter); + + printf("ADC3 = %d V\n", adc_sensors.value(ANALOG_VAC_SENSOR)); + uint32_t as = (adc_sensors.value(ANALOG_VAC_SENSOR) * 0.176); + printf("ADC5V = %ld V\n", as); + //printf("AC voltage = %d V\n", vac.value(VAC_VAL)); + + etimer_set(&et, LOOP_INTERVAL); + counter++; + } + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + * @} + */ diff --git a/platform/zoul/dev/adc-sensors.c b/platform/zoul/dev/adc-sensors.c index 11d727dbc..a77958bdd 100644 --- a/platform/zoul/dev/adc-sensors.c +++ b/platform/zoul/dev/adc-sensors.c @@ -108,6 +108,18 @@ convert_to_value(uint8_t index) value /= 100000; return (uint16_t)value; + case ANALOG_VAC_SENSOR: + /* Linear sensor from 0 to 5 V; 0.0088 resolution*/ + value *= 88; + value /= 10000; + return (uint16_t)value; + + case ANALOG_PM10_SENSOR: + /* PM10 sensor from 0 to 5 V; 0.0088 resolution*/ + value *= 88; + value /= 10000; + return (uint16_t)value; + default: return ADC_WRAPPER_ERROR; } @@ -154,7 +166,8 @@ configure(int type, int value) uint8_t pin_mask = GPIO_PIN_MASK(value); if((type != ANALOG_GROVE_LIGHT) && (type != ANALOG_PHIDGET_ROTATION_1109) && - (type != ANALOG_GROVE_LOUDNESS)) { + (type != ANALOG_GROVE_LOUDNESS) && (type != ANALOG_PM10_SENSOR) && + (type != ANALOG_VAC_SENSOR) ) { PRINTF("ADC sensors: sensor not supported, check adc_wrapper.h header\n"); return ADC_WRAPPER_ERROR; } @@ -179,6 +192,7 @@ configure(int type, int value) case ANALOG_GROVE_LIGHT: case ANALOG_GROVE_LOUDNESS: case ANALOG_PHIDGET_ROTATION_1109: + case ANALOG_VAC_SENSOR: if(adc_zoul.configure(SENSORS_HW_INIT, pin_mask) == ZOUL_SENSORS_ERROR) { return ADC_WRAPPER_ERROR; } diff --git a/platform/zoul/dev/adc-sensors.h b/platform/zoul/dev/adc-sensors.h index 8d29a9134..44c859b22 100644 --- a/platform/zoul/dev/adc-sensors.h +++ b/platform/zoul/dev/adc-sensors.h @@ -71,6 +71,8 @@ #define ANALOG_GROVE_LIGHT 0x01 #define ANALOG_PHIDGET_ROTATION_1109 0x02 #define ANALOG_GROVE_LOUDNESS 0x03 +#define ANALOG_VAC_SENSOR 0x04 +#define ANALOG_PM10_SENSOR 0x05 /* -------------------------------------------------------------------------- */ #define ADC_SENSORS "ADC sensors API" /* -------------------------------------------------------------------------- */ diff --git a/platform/zoul/dev/pm10-sensor.c b/platform/zoul/dev/pm10-sensor.c new file mode 100644 index 000000000..6c3d2c994 --- /dev/null +++ b/platform/zoul/dev/pm10-sensor.c @@ -0,0 +1,73 @@ + /* + * Copyright (c) 2015, Zolertia + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + */ +/*---------------------------------------------------------------------------*/ +/** + * + * @{ + * + * \file + * GP2Y1010AU0F PM10 sensor example using the ADC sensors wrapper + * \author + * Toni Lozano + */ +/*---------------------------------------------------------------------------*/ +#include +#include "contiki.h" +#include "adc-sensors.h" +#include "dev/pm10-sensor.h" +#include "lib/sensors.h" +/*---------------------------------------------------------------------------*/ +static uint8_t enabled; +/*---------------------------------------------------------------------------*/ +static int +configure(int value) +{ + int error; + /* Use pin number not mask, for example if using the PA5 pin then use 5 */ + error = adc_sensors.configure(ANALOG_PM10_SENSORS, value); + + return error; +} +/*---------------------------------------------------------------------------*/ +static int +value(void) +{ + uint16_t val; + //TODO: Add here GPIO pulses before measuring + val = adc_sensors.value(ANALOG_PM10_SENSOR); + + return val; +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(pm10, PM10_SENSOR, value, configure, NULL); +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/platform/zoul/dev/pm10-sensot.h b/platform/zoul/dev/pm10-sensot.h new file mode 100644 index 000000000..22a89856a --- /dev/null +++ b/platform/zoul/dev/pm10-sensot.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2015, Zolertia + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + * + */ +/*---------------------------------------------------------------------------*/ +/** + * + * + * + * \file + * GP2Y1010AU0F PM-10 sensor driver + * \author + * Toni Lozano + */ +/*---------------------------------------------------------------------------*/ +#include "lib/sensors.h" + +#ifndef PM10_SENSOR_H_ +#define PM10_SENSOR_H_ + +/* -------------------------------------------------------------------------- */ +#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; +/* -------------------------------------------------------------------------- */ +#endif /* ifndef VAC_SENSOR_H_ */ +/** + * @} + * @} + */ From 490784282133f4327ecfbcc5b96d52dbf073ee01 Mon Sep 17 00:00:00 2001 From: Toni Lozano Date: Thu, 21 Jan 2016 15:24:47 +0100 Subject: [PATCH 2/6] Added parameters of aac-sensor on adc-sensors file and adapted AAC and VAC test files for correct results --- examples/zolertia/zoul/Makefile | 1 + examples/zolertia/zoul/test-aac-sensor.c | 120 ++++++++++++++++++ examples/zolertia/zoul/test-vac-sensor.c | 8 +- platform/zoul/dev/adc-sensors.c | 20 ++- platform/zoul/dev/adc-sensors.h | 3 +- .../zoul/dev/{pm10-sensot.h => pm10-sensor.h} | 0 6 files changed, 145 insertions(+), 7 deletions(-) create mode 100644 examples/zolertia/zoul/test-aac-sensor.c rename platform/zoul/dev/{pm10-sensot.h => pm10-sensor.h} (100%) diff --git a/examples/zolertia/zoul/Makefile b/examples/zolertia/zoul/Makefile index b60cf8ccf..fd9ca7b86 100644 --- a/examples/zolertia/zoul/Makefile +++ b/examples/zolertia/zoul/Makefile @@ -5,6 +5,7 @@ CONTIKI_PROJECT += test-bmp085-bmp180 test-motion test-rotation-sensor CONTIKI_PROJECT += test-grove-light-sensor test-grove-loudness-sensor CONTIKI_PROJECT += test-weather-meter test-grove-gyro test-lcd CONTIKI_PROJECT += test-pm10 test-vac-sensor + CONTIKI_TARGET_SOURCEFILES += tsl2563.c sht25.c bmpx8x.c motion-sensor.c CONTIKI_TARGET_SOURCEFILES += adc-sensors.c weather-meter.c grove-gyro.c CONTIKI_TARGET_SOURCEFILES += rgb-bl-lcd.c diff --git a/examples/zolertia/zoul/test-aac-sensor.c b/examples/zolertia/zoul/test-aac-sensor.c new file mode 100644 index 000000000..243a835f8 --- /dev/null +++ b/examples/zolertia/zoul/test-aac-sensor.c @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/ + * Copyright (c) 2015, Zolertia - http://www.zolertia.com + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* + * + * + * @{ + * + * \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 +#include +/*---------------------------------------------------------------------------*/ +#define ADC_PIN 2 +#define LOOP_PERIOD 2 +#define LOOP_INTERVAL (CLOCK_SECOND * LOOP_PERIOD) +#define LEDS_PERIODIC LEDS_GREEN +#define BUTTON_PRESS_EVENT_INTERVAL (CLOCK_SECOND) +/*---------------------------------------------------------------------------*/ +static struct etimer et; + +static uint16_t counter; +/*---------------------------------------------------------------------------*/ +PROCESS(zoul_demo_process, "Zoul demo process"); +AUTOSTART_PROCESSES(&zoul_demo_process); +/*---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(zoul_demo_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)); + + printf("AAC test application\n"); + leds_on(LEDS_PERIODIC); + etimer_set(&et, LOOP_INTERVAL); + + while(1) { + + PROCESS_YIELD(); + + if(ev == PROCESS_EVENT_TIMER) { + leds_toggle(LEDS_PERIODIC); + + 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); + counter++; + } + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + * @} + */ diff --git a/examples/zolertia/zoul/test-vac-sensor.c b/examples/zolertia/zoul/test-vac-sensor.c index 4ecfcf9a6..aa02fd83a 100644 --- a/examples/zolertia/zoul/test-vac-sensor.c +++ b/examples/zolertia/zoul/test-vac-sensor.c @@ -100,10 +100,10 @@ PROCESS_THREAD(zoul_demo_process, ev, data) printf("-----------------------------------------\n" "Counter = 0x%08x\n", counter); - printf("ADC3 = %d V\n", adc_sensors.value(ANALOG_VAC_SENSOR)); - uint32_t as = (adc_sensors.value(ANALOG_VAC_SENSOR) * 0.176); - printf("ADC5V = %ld V\n", as); - //printf("AC voltage = %d V\n", vac.value(VAC_VAL)); + //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)); etimer_set(&et, LOOP_INTERVAL); counter++; diff --git a/platform/zoul/dev/adc-sensors.c b/platform/zoul/dev/adc-sensors.c index a77958bdd..ecefbcff5 100644 --- a/platform/zoul/dev/adc-sensors.c +++ b/platform/zoul/dev/adc-sensors.c @@ -114,6 +114,11 @@ convert_to_value(uint8_t index) value /= 10000; return (uint16_t)value; + 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; @@ -167,7 +172,7 @@ configure(int type, int value) if((type != ANALOG_GROVE_LIGHT) && (type != ANALOG_PHIDGET_ROTATION_1109) && (type != ANALOG_GROVE_LOUDNESS) && (type != ANALOG_PM10_SENSOR) && - (type != ANALOG_VAC_SENSOR) ) { + (type != ANALOG_VAC_SENSOR) && (type != ANALOG_AAC_SENSOR) ) { PRINTF("ADC sensors: sensor not supported, check adc_wrapper.h header\n"); return ADC_WRAPPER_ERROR; } @@ -192,7 +197,6 @@ configure(int type, int value) case ANALOG_GROVE_LIGHT: case ANALOG_GROVE_LOUDNESS: case ANALOG_PHIDGET_ROTATION_1109: - case ANALOG_VAC_SENSOR: if(adc_zoul.configure(SENSORS_HW_INIT, pin_mask) == ZOUL_SENSORS_ERROR) { return ADC_WRAPPER_ERROR; } @@ -201,6 +205,18 @@ configure(int type, int value) sensors.sensor[sensors.sensors_num].vdd3 = 1; break; + case ANALOG_VAC_SENSOR: + case ANALOG_AAC_SENSOR: + case ANALOG_PM10_SENSOR: + if(adc_zoul.configure(SENSORS_HW_INIT, pin_mask) == ZOUL_SENSORS_ERROR) { + return ADC_WRAPPER_ERROR; + } + sensors.sensor[sensors.sensors_num].type = type; + sensors.sensor[sensors.sensors_num].pin_mask = pin_mask; + sensors.sensor[sensors.sensors_num].vdd3 = 0; + break; + + default: return ADC_WRAPPER_ERROR; } diff --git a/platform/zoul/dev/adc-sensors.h b/platform/zoul/dev/adc-sensors.h index 44c859b22..8a3eb4047 100644 --- a/platform/zoul/dev/adc-sensors.h +++ b/platform/zoul/dev/adc-sensors.h @@ -72,7 +72,8 @@ #define ANALOG_PHIDGET_ROTATION_1109 0x02 #define ANALOG_GROVE_LOUDNESS 0x03 #define ANALOG_VAC_SENSOR 0x04 -#define ANALOG_PM10_SENSOR 0x05 +#define ANALOG_AAC_SENSOR 0x05 +#define ANALOG_PM10_SENSOR 0x06 /* -------------------------------------------------------------------------- */ #define ADC_SENSORS "ADC sensors API" /* -------------------------------------------------------------------------- */ diff --git a/platform/zoul/dev/pm10-sensot.h b/platform/zoul/dev/pm10-sensor.h similarity index 100% rename from platform/zoul/dev/pm10-sensot.h rename to platform/zoul/dev/pm10-sensor.h From 42e1beb93167e7aa67777e7454f844f3bb03672f Mon Sep 17 00:00:00 2001 From: Toni Lozano Date: Fri, 22 Jan 2016 12:15:33 +0100 Subject: [PATCH 3/6] Added PM10 GP2Y1010AU0F sensor driver and demo test --- examples/zolertia/zoul/test-aac-sensor.c | 33 ++----------- .../zoul/{test-pm10.c => test-pm10-sensor.c} | 23 ++++++---- examples/zolertia/zoul/test-vac-sensor.c | 36 +++------------ platform/zoul/dev/adc-sensors.c | 8 ++-- platform/zoul/dev/pm10-sensor.c | 46 ++++++++++++++++--- platform/zoul/dev/pm10-sensor.h | 11 ++--- 6 files changed, 71 insertions(+), 86 deletions(-) rename examples/zolertia/zoul/{test-pm10.c => test-pm10-sensor.c} (82%) diff --git a/examples/zolertia/zoul/test-aac-sensor.c b/examples/zolertia/zoul/test-aac-sensor.c index 243a835f8..661eadf69 100644 --- a/examples/zolertia/zoul/test-aac-sensor.c +++ b/examples/zolertia/zoul/test-aac-sensor.c @@ -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 #include /*---------------------------------------------------------------------------*/ @@ -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)); @@ -100,8 +80,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)); @@ -114,7 +92,6 @@ PROCESS_THREAD(zoul_demo_process, ev, data) } /*---------------------------------------------------------------------------*/ /** - * @} * @} * @} */ diff --git a/examples/zolertia/zoul/test-pm10.c b/examples/zolertia/zoul/test-pm10-sensor.c similarity index 82% rename from examples/zolertia/zoul/test-pm10.c rename to examples/zolertia/zoul/test-pm10-sensor.c index d8e64067a..d72ae51b4 100644 --- a/examples/zolertia/zoul/test-pm10.c +++ b/examples/zolertia/zoul/test-pm10-sensor.c @@ -36,7 +36,7 @@ * @{ * * \file - * GP2Y1010AU0F PM10 sensor example using the ADC sensors wrapper + * GP2Y1010AU0F PM10 sensor example using the ADC sensors wrapper * * \author * Toni Lozano @@ -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(); diff --git a/examples/zolertia/zoul/test-vac-sensor.c b/examples/zolertia/zoul/test-vac-sensor.c index aa02fd83a..0f1f9a4eb 100644 --- a/examples/zolertia/zoul/test-vac-sensor.c +++ b/examples/zolertia/zoul/test-vac-sensor.c @@ -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 #include /*---------------------------------------------------------------------------*/ @@ -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) } /*---------------------------------------------------------------------------*/ /** - * @} * @} * @} */ diff --git a/platform/zoul/dev/adc-sensors.c b/platform/zoul/dev/adc-sensors.c index ecefbcff5..220a8dc88 100644 --- a/platform/zoul/dev/adc-sensors.c +++ b/platform/zoul/dev/adc-sensors.c @@ -45,7 +45,6 @@ #include "adc-sensors.h" #include "adc-zoul.h" #include "zoul-sensors.h" - #include #include /*---------------------------------------------------------------------------*/ @@ -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: diff --git a/platform/zoul/dev/pm10-sensor.c b/platform/zoul/dev/pm10-sensor.c index 6c3d2c994..aa8704c50 100644 --- a/platform/zoul/dev/pm10-sensor.c +++ b/platform/zoul/dev/pm10-sensor.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Zolertia + * Copyright (c) 2016, Zolertia * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,11 +31,11 @@ */ /*---------------------------------------------------------------------------*/ /** - * + * \addtogroup zoul-pm10-sensor * @{ * * \file - * GP2Y1010AU0F PM10 sensor example using the ADC sensors wrapper + * GP2Y1010AU0F PM10 sensor example using the ADC sensors wrapper * \author * Toni Lozano */ @@ -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; } diff --git a/platform/zoul/dev/pm10-sensor.h b/platform/zoul/dev/pm10-sensor.h index 22a89856a..c411428b5 100644 --- a/platform/zoul/dev/pm10-sensor.h +++ b/platform/zoul/dev/pm10-sensor.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Zolertia + * Copyright (c) 2016, Zolertia * 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 */ @@ -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_ */ /** From 31e6cc48ca0bb37aa7d900d08fd7d987bb4890f5 Mon Sep 17 00:00:00 2001 From: Toni Lozano Date: Mon, 25 Jan 2016 12:20:36 +0100 Subject: [PATCH 4/6] Solved doxygen comments information from VAC, AAC and PM10 sensor files --- examples/zolertia/zoul/Makefile | 7 ++++--- examples/zolertia/zoul/test-aac-sensor.c | 10 ++++++++-- examples/zolertia/zoul/test-pm10-sensor.c | 12 ++++++------ examples/zolertia/zoul/test-vac-sensor.c | 10 ++++++++-- platform/zoul/dev/pm10-sensor.c | 1 + platform/zoul/dev/pm10-sensor.h | 5 +++++ 6 files changed, 32 insertions(+), 13 deletions(-) diff --git a/examples/zolertia/zoul/Makefile b/examples/zolertia/zoul/Makefile index fd9ca7b86..95e4a4e1f 100644 --- a/examples/zolertia/zoul/Makefile +++ b/examples/zolertia/zoul/Makefile @@ -1,14 +1,15 @@ DEFINES+=PROJECT_CONF_H=\"project-conf.h\" CONTIKI_PROJECT = zoul-demo test-tsl2563 test-sht25 test-pwm test-power-mgmt -CONTIKI_PROJECT += test-bmp085-bmp180 test-motion test-rotation-sensor +ONTIKI_PROJECT += test-bmp085-bmp180 test-motion test-rotation-sensor CONTIKI_PROJECT += test-grove-light-sensor test-grove-loudness-sensor CONTIKI_PROJECT += test-weather-meter test-grove-gyro test-lcd -CONTIKI_PROJECT += test-pm10 test-vac-sensor +CONTIKI_PROJECT += test-pm10-sensor test-vac-sensor test-aac-sensor + CONTIKI_TARGET_SOURCEFILES += tsl2563.c sht25.c bmpx8x.c motion-sensor.c CONTIKI_TARGET_SOURCEFILES += adc-sensors.c weather-meter.c grove-gyro.c -CONTIKI_TARGET_SOURCEFILES += rgb-bl-lcd.c +CONTIKI_TARGET_SOURCEFILES += rgb-bl-lcd.c pm10-sensor.c all: $(CONTIKI_PROJECT) diff --git a/examples/zolertia/zoul/test-aac-sensor.c b/examples/zolertia/zoul/test-aac-sensor.c index 661eadf69..0884f9200 100644 --- a/examples/zolertia/zoul/test-aac-sensor.c +++ b/examples/zolertia/zoul/test-aac-sensor.c @@ -31,9 +31,16 @@ /* * \addtogroup zoul-examples * @{ + * \defgroup zoul-aac-sensor-test Test AAC sensor + * + * Demonstrates the operation of the current AAC analog sensor + * @{ * * \file - * Example demonstrating the Zoul module on the RE-Mote & AAC sensor 0-5V 50Amps AC + * Example demonstrating the Zoul module on the RE-Mote & AAC sensor 0-5V 50Amps AC + * + * \author + * Javier Sánchez */ #include "contiki.h" #include "sys/etimer.h" @@ -87,7 +94,6 @@ PROCESS_THREAD(test_aac_sensor_process, ev, data) counter++; } } - PROCESS_END(); } /*---------------------------------------------------------------------------*/ diff --git a/examples/zolertia/zoul/test-pm10-sensor.c b/examples/zolertia/zoul/test-pm10-sensor.c index d72ae51b4..7aedbf60c 100644 --- a/examples/zolertia/zoul/test-pm10-sensor.c +++ b/examples/zolertia/zoul/test-pm10-sensor.c @@ -31,23 +31,26 @@ /** * \addtogroup zoul-examples * @{ + * \defgroup zoul-pm10-sensor-test Test PM10 sensor * * Demonstrates the operation of the Sharp PM10 analog sensor * @{ * * \file - * GP2Y1010AU0F PM10 sensor example using the ADC sensors wrapper + * GP2Y1010AU0F PM10 sensor example using the ADC sensors wrapper * * \author * Toni Lozano */ /*---------------------------------------------------------------------------*/ #include +#include "cpu.h" #include "contiki.h" #include "dev/leds.h" #include "dev/adc-sensors.h" #include "dev/zoul-sensors.h" #include "lib/sensors.h" +#include "dev/sys-ctrl.h" #include "dev/pm10-sensor.h" /*---------------------------------------------------------------------------*/ #define ADC_PIN 2 @@ -76,16 +79,14 @@ PROCESS_THREAD(test_pm10_sensor_process, ev, data) PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); leds_toggle(LEDS_GREEN); - - pm10_value = pm10.value(NULL); - + printf("PM10 value\n"); + pm10_value = pm10.value(1); if(pm10_value != ADC_WRAPPER_ERROR) { printf("PM10 value = %u ppm\n", pm10_value); } else { printf("Error, enable the DEBUG flag in adc-wrapper.c for info\n"); PROCESS_EXIT(); } - } PROCESS_END(); } @@ -94,4 +95,3 @@ PROCESS_THREAD(test_pm10_sensor_process, ev, data) * @} * @} */ - diff --git a/examples/zolertia/zoul/test-vac-sensor.c b/examples/zolertia/zoul/test-vac-sensor.c index 0f1f9a4eb..289a0e839 100644 --- a/examples/zolertia/zoul/test-vac-sensor.c +++ b/examples/zolertia/zoul/test-vac-sensor.c @@ -31,9 +31,16 @@ /* * \addtogroup zoul-examples * @{ + * \defgroup zoul-vac-sensor-test Test VAC sensor + * + * Demonstrates the operation of the voltage VAC analog sensor + * @{ * * \file - * Example demonstrating the Zoul module on the RE-Mote & VAC sensor + * Example demonstrating the Zoul module on the RE-Mote & VAC sensor 0-5V 250V AC + * + * \author + * Javier Sánchez */ #include "contiki.h" #include "sys/etimer.h" @@ -88,7 +95,6 @@ PROCESS_THREAD(test_vac_sensor_process, ev, data) counter++; } } - PROCESS_END(); } /*---------------------------------------------------------------------------*/ diff --git a/platform/zoul/dev/pm10-sensor.c b/platform/zoul/dev/pm10-sensor.c index aa8704c50..015852c93 100644 --- a/platform/zoul/dev/pm10-sensor.c +++ b/platform/zoul/dev/pm10-sensor.c @@ -66,6 +66,7 @@ configure(int type, int value) 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)); diff --git a/platform/zoul/dev/pm10-sensor.h b/platform/zoul/dev/pm10-sensor.h index c411428b5..e090f8202 100644 --- a/platform/zoul/dev/pm10-sensor.h +++ b/platform/zoul/dev/pm10-sensor.h @@ -31,6 +31,11 @@ */ /*---------------------------------------------------------------------------*/ /** + * \addtogroup zoul-sensors + * @{ + * + * \defgroup zoul-pm10-sensor Analog PM10 sensor + * @{ * \file * GP2Y1010AU0F PM10 sensor driver * \author From 8337843d691ec9e7fefc60d457024c31059d21b9 Mon Sep 17 00:00:00 2001 From: Antonio Lignan Date: Mon, 25 Jan 2016 22:58:06 +0100 Subject: [PATCH 5/6] Minor fixes --- examples/zolertia/zoul/test-pm10-sensor.c | 6 +-- platform/zoul/dev/pm10-sensor.c | 56 ++++++++++++----------- platform/zoul/dev/pm10-sensor.h | 22 +++++++-- 3 files changed, 48 insertions(+), 36 deletions(-) diff --git a/examples/zolertia/zoul/test-pm10-sensor.c b/examples/zolertia/zoul/test-pm10-sensor.c index 7aedbf60c..d307f9050 100644 --- a/examples/zolertia/zoul/test-pm10-sensor.c +++ b/examples/zolertia/zoul/test-pm10-sensor.c @@ -64,13 +64,11 @@ static struct etimer et; PROCESS_THREAD(test_pm10_sensor_process, ev, data) { PROCESS_BEGIN(); - SENSORS_ACTIVATE(pm10); static uint16_t pm10_value; - /* Configure the ADC ports */ /* Use pin number not mask, for example if using the PA5 pin then use 2 */ - printf("return configure, %d \n", pm10.configure(SENSORS_ACTIVE, ADC_PIN)); + pm10.configure(SENSORS_ACTIVE, ADC_PIN); /* And periodically poll the sensor */ @@ -79,8 +77,8 @@ PROCESS_THREAD(test_pm10_sensor_process, ev, data) PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); leds_toggle(LEDS_GREEN); - printf("PM10 value\n"); pm10_value = pm10.value(1); + if(pm10_value != ADC_WRAPPER_ERROR) { printf("PM10 value = %u ppm\n", pm10_value); } else { diff --git a/platform/zoul/dev/pm10-sensor.c b/platform/zoul/dev/pm10-sensor.c index 015852c93..8f94eb04f 100644 --- a/platform/zoul/dev/pm10-sensor.c +++ b/platform/zoul/dev/pm10-sensor.c @@ -49,52 +49,54 @@ #include "dev/gpio.h" #include "dev/ioc.h" /*---------------------------------------------------------------------------*/ +#define PM10_SENSOR_PORT_BASE GPIO_PORT_TO_BASE(PM10_SENSOR_CTRL_PORT) +#define PM10_SENSOR_PIN_MASK GPIO_PIN_MASK(PM10_SENSOR_CTRL_PIN) +/*---------------------------------------------------------------------------*/ 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 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)); + if(value) { + /* Set as output, used as pulse-driven wave */ + GPIO_SOFTWARE_CONTROL(PM10_SENSOR_PORT_BASE, PM10_SENSOR_PIN_MASK); + ioc_set_over(PM10_SENSOR_CTRL_PORT, PM10_SENSOR_CTRL_PIN, IOC_OVERRIDE_DIS); + GPIO_SET_OUTPUT(PM10_SENSOR_PORT_BASE, PM10_SENSOR_PIN_MASK); + GPIO_CLR_PIN(PM10_SENSOR_PORT_BASE, PM10_SENSOR_PIN_MASK); - GPIO_CLR_PIN(PM10_SENSOR_PORT, GPIO_PIN_MASK(PM10_SENSOR_CTRL_PIN)); + enabled = 1; + return adc_sensors.configure(ANALOG_PM10_SENSOR, value); + } - /* Use pin number not mask, for example if using the PA5 pin then use 5 */ - error = adc_sensors.configure(ANALOG_PM10_SENSOR, value); - - return error; + enabled = 0; + return PM10_SUCCESS; } /*---------------------------------------------------------------------------*/ static int value(int type) { uint16_t val; - /*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*/ + + if(!enabled) { + return PM10_ERROR; + } + + /* Set Pulse Wave pin before measure */ + GPIO_SET_PIN(PM10_SENSOR_PORT_BASE, PM10_SENSOR_PIN_MASK); + /* Pulse wave delay */ + clock_delay_usec(PM10_SENSOR_PULSE_DELAY); + /* 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)); + /* Clear pulse wave pin */ + GPIO_CLR_PIN(PM10_SENSOR_PORT_BASE, PM10_SENSOR_PIN_MASK); - /*Applied constant conversion from UAir project*/ - /*to obtain value in ppm (value in mV * 0.28)*/ + /* Applied constant conversion from UAir project + * to obtain value in ppm (value in mV * 0.28) + */ val *= 28; val /= 1000; diff --git a/platform/zoul/dev/pm10-sensor.h b/platform/zoul/dev/pm10-sensor.h index e090f8202..61057e0d1 100644 --- a/platform/zoul/dev/pm10-sensor.h +++ b/platform/zoul/dev/pm10-sensor.h @@ -43,17 +43,29 @@ */ /*---------------------------------------------------------------------------*/ #include "lib/sensors.h" - +/*---------------------------------------------------------------------------*/ #ifndef PM10_SENSOR_H_ #define PM10_SENSOR_H_ - /* -------------------------------------------------------------------------- */ -#define PM10_ERROR -1 -#define PM10_SENSOR "PM10 Sensor" +#define PM10_ERROR (-1) +#define PM10_SUCCESS 0 +#define PM10_SENSOR "PM10 Sensor" +#define PM10_SENSOR_PULSE_DELAY 280 +/* -------------------------------------------------------------------------- */ +#ifdef PM10_SENSOR_CONF_CTRL_PIN +#define PM10_SENSOR_CTRL_PIN PM10_SENSOR_CONF_CTRL_PIN +#else +#define PM10_SENSOR_CTRL_PIN 7 +#endif +#ifdef PM10_SENSOR_CONF_CTRL_PORT +#define PM10_SENSOR_CTRL_PORT PM10_SENSOR_CONF_CTRL_PORT +#else +#define PM10_SENSOR_CTRL_PORT GPIO_A_NUM +#endif /* -------------------------------------------------------------------------- */ extern const struct sensors_sensor pm10; /* -------------------------------------------------------------------------- */ -#endif /* ifndef VAC_SENSOR_H_ */ +#endif /* ifndef PM10_SENSOR_H_ */ /** * @} * @} From 1f6dafecb097b73c367036df30901259abfaa85f Mon Sep 17 00:00:00 2001 From: Toni Lozano Date: Tue, 26 Jan 2016 14:08:17 +0100 Subject: [PATCH 6/6] Modified ADC measurement of PM10 driver to include adc-zoul direct access --- examples/zolertia/zoul/Makefile | 3 +- examples/zolertia/zoul/test-aac-sensor.c | 3 +- examples/zolertia/zoul/test-vac-sensor.c | 2 +- platform/zoul/dev/pm10-sensor.c | 39 ++++++++++++++++-------- platform/zoul/dev/pm10-sensor.h | 2 ++ 5 files changed, 32 insertions(+), 17 deletions(-) diff --git a/examples/zolertia/zoul/Makefile b/examples/zolertia/zoul/Makefile index 95e4a4e1f..a0a8dee0d 100644 --- a/examples/zolertia/zoul/Makefile +++ b/examples/zolertia/zoul/Makefile @@ -1,12 +1,11 @@ DEFINES+=PROJECT_CONF_H=\"project-conf.h\" CONTIKI_PROJECT = zoul-demo test-tsl2563 test-sht25 test-pwm test-power-mgmt -ONTIKI_PROJECT += test-bmp085-bmp180 test-motion test-rotation-sensor +CONTIKI_PROJECT += test-bmp085-bmp180 test-motion test-rotation-sensor CONTIKI_PROJECT += test-grove-light-sensor test-grove-loudness-sensor CONTIKI_PROJECT += test-weather-meter test-grove-gyro test-lcd CONTIKI_PROJECT += test-pm10-sensor test-vac-sensor test-aac-sensor - CONTIKI_TARGET_SOURCEFILES += tsl2563.c sht25.c bmpx8x.c motion-sensor.c CONTIKI_TARGET_SOURCEFILES += adc-sensors.c weather-meter.c grove-gyro.c CONTIKI_TARGET_SOURCEFILES += rgb-bl-lcd.c pm10-sensor.c diff --git a/examples/zolertia/zoul/test-aac-sensor.c b/examples/zolertia/zoul/test-aac-sensor.c index 0884f9200..bbda23955 100644 --- a/examples/zolertia/zoul/test-aac-sensor.c +++ b/examples/zolertia/zoul/test-aac-sensor.c @@ -54,7 +54,6 @@ #define LOOP_PERIOD 2 #define LOOP_INTERVAL (CLOCK_SECOND * LOOP_PERIOD) #define LEDS_PERIODIC LEDS_GREEN -#define BUTTON_PRESS_EVENT_INTERVAL (CLOCK_SECOND) /*---------------------------------------------------------------------------*/ static struct etimer et; @@ -72,7 +71,7 @@ PROCESS_THREAD(test_aac_sensor_process, ev, data) /* 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)); + adc_sensors.configure(ANALOG_AAC_SENSOR, ADC_PIN); printf("AAC test application\n"); leds_on(LEDS_PERIODIC); diff --git a/examples/zolertia/zoul/test-vac-sensor.c b/examples/zolertia/zoul/test-vac-sensor.c index 289a0e839..37db59edf 100644 --- a/examples/zolertia/zoul/test-vac-sensor.c +++ b/examples/zolertia/zoul/test-vac-sensor.c @@ -72,7 +72,7 @@ PROCESS_THREAD(test_vac_sensor_process, ev, data) /* 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)); + adc_sensors.configure(ANALOG_VAC_SENSOR, ADC_PIN); printf("VAC test application\n"); leds_on(LEDS_PERIODIC); diff --git a/platform/zoul/dev/pm10-sensor.c b/platform/zoul/dev/pm10-sensor.c index 8f94eb04f..3ec10de62 100644 --- a/platform/zoul/dev/pm10-sensor.c +++ b/platform/zoul/dev/pm10-sensor.c @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 2016, Zolertia * All rights reserved. * @@ -43,6 +43,8 @@ #include #include "contiki.h" #include "adc-sensors.h" +#include "adc-zoul.h" +#include "zoul-sensors.h" #include "dev/pm10-sensor.h" #include "dev/sys-ctrl.h" #include "lib/sensors.h" @@ -52,7 +54,7 @@ #define PM10_SENSOR_PORT_BASE GPIO_PORT_TO_BASE(PM10_SENSOR_CTRL_PORT) #define PM10_SENSOR_PIN_MASK GPIO_PIN_MASK(PM10_SENSOR_CTRL_PIN) /*---------------------------------------------------------------------------*/ -static uint8_t enabled; +static int pm10_channel; /*---------------------------------------------------------------------------*/ static int configure(int type, int value) @@ -68,20 +70,20 @@ configure(int type, int value) GPIO_SET_OUTPUT(PM10_SENSOR_PORT_BASE, PM10_SENSOR_PIN_MASK); GPIO_CLR_PIN(PM10_SENSOR_PORT_BASE, PM10_SENSOR_PIN_MASK); - enabled = 1; - return adc_sensors.configure(ANALOG_PM10_SENSOR, value); + pm10_channel = (1 << value); + return adc_zoul.configure(SENSORS_HW_INIT, pm10_channel); } - enabled = 0; + pm10_channel = 0; return PM10_SUCCESS; } /*---------------------------------------------------------------------------*/ static int value(int type) { - uint16_t val; + uint32_t val; - if(!enabled) { + if(!pm10_channel) { return PM10_ERROR; } @@ -90,17 +92,30 @@ value(int type) /* Pulse wave delay */ clock_delay_usec(PM10_SENSOR_PULSE_DELAY); /* Data acquisition */ - val = adc_sensors.value(ANALOG_PM10_SENSOR); - /* Clear pulse wave pin */ - GPIO_CLR_PIN(PM10_SENSOR_PORT_BASE, PM10_SENSOR_PIN_MASK); - + val = (uint32_t)adc_zoul.value(pm10_channel); + + if(val == ZOUL_SENSORS_ERROR) { + printf("PM10 sensor: failed retrieving data\n"); + return PM10_ERROR; + } + + /* Default voltage divisor relation is 5/3 aprox, change at adc_wrapper.h, + * calculations below assume a decimation rate of 512 (12 bits ENOB) and + * AVVD5 voltage reference of 3.3V + */ + val *= PM10_EXTERNAL_VREF; + val /= PM10_EXTERNAL_VREF_CROSSVAL; + /* Applied constant conversion from UAir project * to obtain value in ppm (value in mV * 0.28) */ val *= 28; val /= 1000; - return val; + /* Clear pulse wave pin */ + GPIO_CLR_PIN(PM10_SENSOR_PORT_BASE, PM10_SENSOR_PIN_MASK); + + return (uint16_t)val; } /*---------------------------------------------------------------------------*/ SENSORS_SENSOR(pm10, PM10_SENSOR, value, configure, NULL); diff --git a/platform/zoul/dev/pm10-sensor.h b/platform/zoul/dev/pm10-sensor.h index 61057e0d1..d43256e44 100644 --- a/platform/zoul/dev/pm10-sensor.h +++ b/platform/zoul/dev/pm10-sensor.h @@ -51,6 +51,8 @@ #define PM10_SUCCESS 0 #define PM10_SENSOR "PM10 Sensor" #define PM10_SENSOR_PULSE_DELAY 280 +#define PM10_EXTERNAL_VREF 5000 +#define PM10_EXTERNAL_VREF_CROSSVAL 3300 /* -------------------------------------------------------------------------- */ #ifdef PM10_SENSOR_CONF_CTRL_PIN #define PM10_SENSOR_CTRL_PIN PM10_SENSOR_CONF_CTRL_PIN