From 537f14dc03c4b182ab85f52f04f40dc6ec129d97 Mon Sep 17 00:00:00 2001 From: Timm Bogner <64260873+timmbogner@users.noreply.github.com> Date: Tue, 30 Aug 2022 19:30:36 -0500 Subject: [PATCH] added support for TSL2561 --- examples/Sensor_Examples/TSL2561/TSL2561.ino | 67 +++++++++++++++++++ .../TSL2561/fdrs_sensor_config.h | 33 +++++++++ 2 files changed, 100 insertions(+) create mode 100644 examples/Sensor_Examples/TSL2561/TSL2561.ino create mode 100644 examples/Sensor_Examples/TSL2561/fdrs_sensor_config.h diff --git a/examples/Sensor_Examples/TSL2561/TSL2561.ino b/examples/Sensor_Examples/TSL2561/TSL2561.ino new file mode 100644 index 0000000..4e87a68 --- /dev/null +++ b/examples/Sensor_Examples/TSL2561/TSL2561.ino @@ -0,0 +1,67 @@ +#include +#include +#include + +#include "fdrs_sensor_config.h" +#include + +Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345); + + +/**************************************************************************/ +/* + Configures the gain and integration time for the TSL2561 +*/ +/**************************************************************************/ +void configureSensor(void) +{ + /* You can also manually set the gain or enable auto-gain support */ + // tsl.setGain(TSL2561_GAIN_1X); /* No gain ... use in bright light to avoid sensor saturation */ + // tsl.setGain(TSL2561_GAIN_16X); /* 16x gain ... use in low light to boost sensitivity */ + tsl.enableAutoRange(true); /* Auto-gain ... switches automatically between 1x and 16x */ + + /* Changing the integration time gives you better sensor resolution (402ms = 16-bit data) */ + tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS); /* fast but low resolution */ + // tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_101MS); /* medium resolution and speed */ + // tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_402MS); /* 16-bit data but slowest conversions */ + +} + +/**************************************************************************/ +/* + Arduino setup function (automatically called at startup) +*/ +/**************************************************************************/ +void setup(void) +{ + beginFDRS(); + /* Initialise the sensor */ + //use tsl.begin() to default to Wire, + //tsl.begin(&Wire2) directs api to use Wire2, etc. + if(!tsl.begin()) + { + DBG("Ooops, no TSL2561 detected ... Check your wiring or I2C ADDR!"); + while(1); + } + configureSensor(); +} + +void loop(void) +{ + sensors_event_t event; + tsl.getEvent(&event); + if (event.light) + { + DBG(String(event.light) + " lux"); + loadFDRS(float(event.light), LIGHT_T); + sendFDRS(); + sleepFDRS(10); //Sleep time in seconds + } + else + { + /* If event.light = 0 lux the sensor is probably saturated + and no reliable data could be generated! */ + Serial.println("Sensor overload"); + } + delay(250); +} diff --git a/examples/Sensor_Examples/TSL2561/fdrs_sensor_config.h b/examples/Sensor_Examples/TSL2561/fdrs_sensor_config.h new file mode 100644 index 0000000..deef3b9 --- /dev/null +++ b/examples/Sensor_Examples/TSL2561/fdrs_sensor_config.h @@ -0,0 +1,33 @@ +// FARM DATA RELAY SYSTEM +// +// Sensor Configuration + +#include + +#define READING_ID 1 //Unique ID for this sensor +#define GTWY_MAC 0x01 //Address of the nearest gateway + +#define USE_ESPNOW +//#define USE_LORA +#define DEEP_SLEEP +//#define POWER_CTRL 14 +#define FDRS_DEBUG + +//SPI Configuration -- Needed only on chipsets with multiple SPI interfaces (ESP32) +#define SPI_SCK 5 +#define SPI_MISO 19 +#define SPI_MOSI 27 + +//LoRa Configuration +#define LORA_SS 18 +#define LORA_RST 14 +#define LORA_DIO0 26 +//433E6 for Asia +//866E6 for Europe +//915E6 for North America +//#define LORA_BAND 915E6 // LoRa Frequency Band +//#define LORA_SF 7 // LoRa Spreading Factor +//#define LORA_TXPWR 17 // LoRa TX power in dBm (+2dBm - +20dBm), default is +17dBm. Lower power = less battery use +//#define LORA_ACK // Uncomment to enable request for LoRa ACKs at cost of increased battery usage +//#define LORA_ACK_TIMEOUT 400 // ms timeout waiting for LoRa ACKs (if enabled). Wouldn't go less than 200ms +//#define LORA_RETRIES 2 // [0 - 3] When ACK enabled, number of sensor node tx retries when ACK not received or invalid CRC