Test application for UV, IR, Light and Temperature sensors
authorNathael Pajani <nathael.pajani@ed3l.fr>
Tue, 13 Sep 2016 23:25:07 +0000 (01:25 +0200)
committerNathael Pajani <nathael.pajani@ed3l.fr>
Sat, 11 Feb 2023 04:09:54 +0000 (05:09 +0100)
sensors/Makefile [new file with mode: 0644]
sensors/README [new file with mode: 0644]
sensors/main.c [new file with mode: 0644]

diff --git a/sensors/Makefile b/sensors/Makefile
new file mode 100644 (file)
index 0000000..a944f0f
--- /dev/null
@@ -0,0 +1,12 @@
+# Makefile for exanh apps
+
+MODULE = $(shell basename $(shell cd .. && pwd && cd -))
+NAME = $(shell basename $(CURDIR))
+
+.PHONY: $(NAME).bin
+$(NAME).bin:
+       @make -C ../../.. --no-print-directory NAME=$(NAME) MODULE=$(MODULE) apps/$(MODULE)/$(NAME)/$@
+
+clean mrproper:
+       @make -C ../../.. --no-print-directory $@
+
diff --git a/sensors/README b/sensors/README
new file mode 100644 (file)
index 0000000..bda13c0
--- /dev/null
@@ -0,0 +1,27 @@
+Test of all three sensors found on exanh sensor board in version 0.1 :
+ - TMP101 I2C temperature sensor
+ - TSL256x I2C luminosity and IR sensor
+ - VEML6070 I2C UV sensor
+
+Copyright 2016 Nathael Pajani <nathael.pajani@ed3l.fr>
+
+
+/* ****************************************************************************
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *************************************************************************** */
+
+
+Periodic conversions are sent on UART0 using the following frame format :
+
diff --git a/sensors/main.c b/sensors/main.c
new file mode 100644 (file)
index 0000000..36a3dc7
--- /dev/null
@@ -0,0 +1,205 @@
+/****************************************************************************
+ *   sensors/main.c
+ *
+ * TMP101, TSL2661 and VEML6070 I2C sensors example
+ *
+ * Copyright 2016 Nathael Pajani <nathael.pajani@ed3l.fr>
+ *
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *************************************************************************** */
+
+
+#include "lib/stdint.h"
+#include "core/system.h"
+#include "core/systick.h"
+#include "core/watchdog.h"
+#include "core/pio.h"
+#include "lib/stdio.h"
+#include "drivers/i2c.h"
+#include "drivers/serial.h"
+#include "drivers/gpio.h"
+
+#include "extdrv/tmp101_temp_sensor.h"
+#include "extdrv/tsl256x_light_sensor.h"
+#include "extdrv/veml6070_uv_sensor.h"
+
+
+#define MODULE_VERSION    0x01
+#define MODULE_NAME "E-Xanh Gardener"
+
+#define SELECTED_FREQ  FREQ_SEL_36MHz
+
+
+
+/***************************************************************************** */
+/* Pins configuration */
+/* Pins blocks are passed to set_pins() for pins configuration.
+ * Unused pin blocks can be removed safely with the corresponding set_pins() call
+ * All pins blocks may be safelly merged in a single block for single set_pins() call..
+ */
+const struct pio_config common_pins[] = {
+       /* UART 0 */
+       { LPC_GPIO_0_0, LPC_UART0_RX, 0 },
+       { LPC_GPIO_0_4, LPC_UART0_TX, 0 },
+       /* I2C 0 */
+       { LPC_I2C0_SCL_PIO_0_10, LPC_FIXED, 0 },
+       { LPC_I2C0_SDA_PIO_0_11, LPC_FIXED, 0 },
+       ARRAY_LAST_PIO,
+};
+
+
+
+/***************************************************************************** */
+/* Luminosity */
+
+/* Note : These are 8bits address */
+#define TSL256x_ADDR   0x52 /* Pin Addr Sel (pin2 of tsl256x) connected to GND */
+struct tsl256x_sensor_config tsl256x_sensor = {
+       .bus_num = I2C0,
+       .addr = TSL256x_ADDR,
+       .gain = TSL256x_LOW_GAIN,
+       .integration_time = TSL256x_INTEGRATION_100ms,
+       .package = TSL256x_PACKAGE_T,
+};
+
+
+
+
+/***************************************************************************** */
+/* UV */
+
+/* The I2C UV light sensor is at addresses 0x70, 0x71 and 0x73 */
+/* Note : These are 8bits address */
+#define VEML6070_ADDR        0x70
+struct veml6070_sensor_config veml6070_sensor = {
+       .bus_num = I2C0,
+       .addr = VEML6070_ADDR,
+};
+
+
+
+/***************************************************************************** */
+/* Temperature */
+
+#define TMP101_ADDR  0x94 /* Pin Addr0 (pin5 of tmp101) connected to VCC */
+struct tmp101_sensor_config tmp101_sensor = {
+       .bus_num = I2C0,
+       .addr = TMP101_ADDR,
+       .resolution = TMP_RES_ELEVEN_BITS,
+};
+
+
+
+
+/***************************************************************************** */
+void system_init()
+{
+       system_set_default_power_state();
+       clock_config(SELECTED_FREQ);
+       set_pins(common_pins);
+       gpio_on();
+       /* System tick timer MUST be configured and running in order to use the sleeping
+        * functions */
+       systick_timer_on(1); /* 1ms */
+       systick_start();
+}
+
+/* Define our fault handler. This one is not mandatory, the dummy fault handler
+ * will be used when it's not overridden here.
+ * Note : The default one does a simple infinite loop. If the watchdog is deactivated
+ * the system will hang.
+ */
+void fault_info(const char* name, uint32_t len)
+{
+       uprintf(UART0, name);
+       while (1);
+}
+
+
+
+/***************************************************************************** */
+int main(void)
+{
+       uint16_t uv = 0, ir = 0;
+       uint32_t lux = 0;
+       int deci_degrees = 0;
+       int ret = 0;
+
+       system_init();
+       uart_on(UART0, 115200, NULL);
+
+       while (1) {
+               i2c_on(I2C0, I2C_CLK_100KHz, I2C_MASTER);
+
+               msleep(10);
+
+               /* Configure temp sensor */
+               ret = tmp101_sensor_config(&tmp101_sensor);
+               if (ret != 0) {
+                       uprintf(UART0, "Temp config error: %d\n", ret);
+               }
+               msleep(10);
+               /* Configure lux sensor */
+               ret = tsl256x_configure(&tsl256x_sensor);
+               if (ret != 0) {
+                       uprintf(UART0, "Lux config error: %d\n", ret);
+               }
+               msleep(10);
+
+               /* Configure uv sensor */
+               ret = veml6070_configure(&veml6070_sensor);
+               if (ret != 0) {
+                       uprintf(UART0, "UV config error: %d\n", ret);
+               }
+               msleep(10);
+
+               while (1) {
+                       ret = tmp101_sensor_start_conversion(&tmp101_sensor);
+                       if (ret != 0) {
+                               uprintf(UART0, "Temp start conversion error: %d\n", ret);
+                               break;
+                       }
+                       msleep(460); /* Wait for the end of the conversion : 40ms min */
+                       ret = tmp101_sensor_read(&tmp101_sensor, NULL, &deci_degrees);
+                       if (ret != 0) {
+                               uprintf(UART0, "Temp read error: %d\n", ret);
+                               break;
+                       }
+                       msleep(10);
+                       ret = tsl256x_sensor_read(&tsl256x_sensor, NULL, &ir, &lux);
+                       if (ret != 0) {
+                               uprintf(UART0, "Lux read error: %d\n", ret);
+                               break;
+                       }
+                       msleep(10);
+                       ret = veml6070_sensor_read(&veml6070_sensor, &uv);
+                       if (ret != 0) {
+                               uprintf(UART0, "UV read error: %d\n", ret);
+                               break;
+                       }
+
+                       /* Display all */
+                       uprintf(UART0, "Lux: %d, IR: %d, UV: %d, Temp: %d,%d\n", lux, ir, uv,
+                                       (deci_degrees/10), (deci_degrees%10));
+               }
+
+               i2c_off(I2C0);
+               msleep(500);
+       }
+
+       return 0;
+}
+