mirror of
https://github.com/timmbogner/Farm-Data-Relay-System
synced 2024-11-08 13:10:29 +00:00
added support for TSL2561
This commit is contained in:
parent
02a478484c
commit
537f14dc03
67
examples/Sensor_Examples/TSL2561/TSL2561.ino
Normal file
67
examples/Sensor_Examples/TSL2561/TSL2561.ino
Normal file
@ -0,0 +1,67 @@
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <Adafruit_TSL2561_U.h>
|
||||
|
||||
#include "fdrs_sensor_config.h"
|
||||
#include <fdrs_node.h>
|
||||
|
||||
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);
|
||||
}
|
33
examples/Sensor_Examples/TSL2561/fdrs_sensor_config.h
Normal file
33
examples/Sensor_Examples/TSL2561/fdrs_sensor_config.h
Normal file
@ -0,0 +1,33 @@
|
||||
// FARM DATA RELAY SYSTEM
|
||||
//
|
||||
// Sensor Configuration
|
||||
|
||||
#include <fdrs_globals.h>
|
||||
|
||||
#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
|
Loading…
Reference in New Issue
Block a user