kopia lustrzana https://github.com/gshau/SQM_TSL2591
Added LU and LE emulation examples
rodzic
6192f67a40
commit
58fad01ead
|
@ -0,0 +1,2 @@
|
||||||
|
.DS_Store
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
Forked from original Adafruit TSL2591 libraries
|
Forked from original Adafruit TSL2591 libraries
|
||||||
@author KT0WN (adafruit.com)
|
@author KT0WN (adafruit.com)
|
||||||
@author wbphelps (wm@usa.net)
|
@author wbphelps (wm@usa.net)
|
||||||
|
|
||||||
This is a library for the Adafruit TSL2591 breakout board
|
This is a library for the Adafruit TSL2591 breakout board
|
||||||
This library works with the Adafruit TSL2591 breakout
|
This library works with the Adafruit TSL2591 breakout
|
||||||
|
@ -44,14 +44,14 @@
|
||||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
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
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
#include <pgmspace.h>
|
#include <pgmspace.h>
|
||||||
#else
|
#else
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__AVR__)
|
#if defined(__AVR__)
|
||||||
|
@ -61,24 +61,22 @@
|
||||||
|
|
||||||
#include "SQM_TSL2591.h"
|
#include "SQM_TSL2591.h"
|
||||||
|
|
||||||
SQM_TSL2591::SQM_TSL2591(int32_t sensorID)
|
SQM_TSL2591::SQM_TSL2591(int32_t sensorID) {
|
||||||
{
|
_initialized = false;
|
||||||
_initialized = false;
|
_integration = TSL2591_INTEGRATIONTIME_400MS;
|
||||||
_integration = TSL2591_INTEGRATIONTIME_400MS;
|
_gain = TSL2591_GAIN_LOW;
|
||||||
_gain = TSL2591_GAIN_LOW;
|
_sensorID = sensorID;
|
||||||
_sensorID = sensorID;
|
|
||||||
_calibrationOffset = 0.;
|
_calibrationOffset = 0.;
|
||||||
|
|
||||||
// we cant do wire initialization till later, because we havent loaded Wire yet
|
// we cant do wire initialization till later, because we havent loaded Wire
|
||||||
|
// yet
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean SQM_TSL2591::begin(void)
|
boolean SQM_TSL2591::begin(void) {
|
||||||
{
|
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
|
|
||||||
uint8_t id = read8(0x12);
|
uint8_t id = read8(0x12);
|
||||||
if (id != 0x50 )
|
if (id != 0x50) {
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,43 +90,38 @@ boolean SQM_TSL2591::begin(void)
|
||||||
// Note: by default, the device is in power down mode on bootup
|
// Note: by default, the device is in power down mode on bootup
|
||||||
disable();
|
disable();
|
||||||
|
|
||||||
|
verbose = true;
|
||||||
|
|
||||||
return _initialized;
|
return _initialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQM_TSL2591::enable(void)
|
void SQM_TSL2591::enable(void) {
|
||||||
{
|
if (!_initialized) {
|
||||||
if (!_initialized)
|
if (!begin()) {
|
||||||
{
|
|
||||||
if (!begin())
|
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable the device by setting the control bit to 0x01
|
// Enable the device by setting the control bit to 0x01
|
||||||
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_ENABLE, TSL2591_ENABLE_POWERON | TSL2591_ENABLE_AEN | TSL2591_ENABLE_AIEN);
|
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_ENABLE,
|
||||||
|
TSL2591_ENABLE_POWERON | TSL2591_ENABLE_AEN | TSL2591_ENABLE_AIEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQM_TSL2591::disable(void)
|
void SQM_TSL2591::disable(void) {
|
||||||
{
|
if (!_initialized) {
|
||||||
if (!_initialized)
|
if (!begin()) {
|
||||||
{
|
|
||||||
if (!begin())
|
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable the device by setting the control bit to 0x00
|
// Disable the device by setting the control bit to 0x00
|
||||||
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_ENABLE, TSL2591_ENABLE_POWEROFF);
|
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_ENABLE,
|
||||||
|
TSL2591_ENABLE_POWEROFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQM_TSL2591::setGain(tsl2591Gain_t gain)
|
void SQM_TSL2591::setGain(tsl2591Gain_t gain) {
|
||||||
{
|
if (!_initialized) {
|
||||||
if (!_initialized)
|
if (!begin()) {
|
||||||
{
|
|
||||||
if (!begin())
|
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,43 +131,36 @@ void SQM_TSL2591::setGain(tsl2591Gain_t gain)
|
||||||
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_CONTROL, _integration | _gain);
|
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_CONTROL, _integration | _gain);
|
||||||
disable();
|
disable();
|
||||||
|
|
||||||
switch (_gain)
|
switch (_gain) {
|
||||||
{
|
case TSL2591_GAIN_LOW:
|
||||||
case TSL2591_GAIN_LOW :
|
gainValue = 1.0F;
|
||||||
gainValue = 1.0F;
|
break;
|
||||||
break;
|
case TSL2591_GAIN_MED:
|
||||||
case TSL2591_GAIN_MED :
|
gainValue = 25.0F;
|
||||||
gainValue = 25.0F;
|
break;
|
||||||
break;
|
case TSL2591_GAIN_HIGH:
|
||||||
case TSL2591_GAIN_HIGH :
|
gainValue = 425.0F;
|
||||||
gainValue = 425.0F;
|
break;
|
||||||
break;
|
case TSL2591_GAIN_MAX:
|
||||||
case TSL2591_GAIN_MAX :
|
gainValue = 9876.0F;
|
||||||
gainValue = 9876.0F;
|
break;
|
||||||
break;
|
default:
|
||||||
default:
|
if (verbose) {
|
||||||
Serial.println("Gain not found!");
|
Serial.println("Gain not found!");
|
||||||
break;
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQM_TSL2591::setCalibrationOffset(float calibrationOffset){
|
void SQM_TSL2591::setCalibrationOffset(float calibrationOffset) {
|
||||||
_calibrationOffset = calibrationOffset;
|
_calibrationOffset = calibrationOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
tsl2591Gain_t SQM_TSL2591::getGain()
|
tsl2591Gain_t SQM_TSL2591::getGain() { return _gain; }
|
||||||
{
|
|
||||||
return _gain;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SQM_TSL2591::setTiming(tsl2591IntegrationTime_t integration)
|
void SQM_TSL2591::setTiming(tsl2591IntegrationTime_t integration) {
|
||||||
{
|
if (!_initialized) {
|
||||||
if (!_initialized)
|
if (!begin()) {
|
||||||
{
|
|
||||||
if (!begin())
|
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -184,62 +170,54 @@ void SQM_TSL2591::setTiming(tsl2591IntegrationTime_t integration)
|
||||||
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_CONTROL, _integration | _gain);
|
write8(TSL2591_COMMAND_BIT | TSL2591_REGISTER_CONTROL, _integration | _gain);
|
||||||
disable();
|
disable();
|
||||||
|
|
||||||
switch (_integration)
|
switch (_integration) {
|
||||||
{
|
case TSL2591_INTEGRATIONTIME_100MS:
|
||||||
case TSL2591_INTEGRATIONTIME_100MS :
|
integrationValue = 100.F;
|
||||||
integrationValue = 100.F;
|
break;
|
||||||
break;
|
case TSL2591_INTEGRATIONTIME_200MS:
|
||||||
case TSL2591_INTEGRATIONTIME_200MS :
|
integrationValue = 200.F;
|
||||||
integrationValue = 200.F;
|
break;
|
||||||
break;
|
case TSL2591_INTEGRATIONTIME_300MS:
|
||||||
case TSL2591_INTEGRATIONTIME_300MS :
|
integrationValue = 300.F;
|
||||||
integrationValue = 300.F;
|
break;
|
||||||
break;
|
case TSL2591_INTEGRATIONTIME_400MS:
|
||||||
case TSL2591_INTEGRATIONTIME_400MS :
|
integrationValue = 400.F;
|
||||||
integrationValue = 400.F;
|
break;
|
||||||
break;
|
case TSL2591_INTEGRATIONTIME_500MS:
|
||||||
case TSL2591_INTEGRATIONTIME_500MS :
|
integrationValue = 500.F;
|
||||||
integrationValue = 500.F;
|
break;
|
||||||
break;
|
case TSL2591_INTEGRATIONTIME_600MS:
|
||||||
case TSL2591_INTEGRATIONTIME_600MS :
|
integrationValue = 600.F;
|
||||||
integrationValue = 600.F;
|
break;
|
||||||
break;
|
default: // 100ms
|
||||||
default: // 100ms
|
integrationValue = 999.F;
|
||||||
integrationValue=999.F;
|
if (verbose) {
|
||||||
Serial.println("Integration not found!");
|
Serial.println("Integration not found!");
|
||||||
Serial.println(_integration);
|
Serial.println(_integration);
|
||||||
break;
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tsl2591IntegrationTime_t SQM_TSL2591::getTiming()
|
tsl2591IntegrationTime_t SQM_TSL2591::getTiming() { return _integration; }
|
||||||
{
|
|
||||||
return _integration;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SQM_TSL2591::configSensor()
|
void SQM_TSL2591::configSensor() {
|
||||||
{
|
|
||||||
setGain(config.gain);
|
setGain(config.gain);
|
||||||
setTiming(config.time);
|
setTiming(config.time);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQM_TSL2591::showConfig(){
|
void SQM_TSL2591::showConfig() {
|
||||||
Serial.print("Integration: "); Serial.print(integrationValue); Serial.println(" ms");
|
Serial.print("Integration: ");
|
||||||
Serial.print("Gain: "); Serial.print(gainValue); Serial.println("x");
|
Serial.print(integrationValue);
|
||||||
|
Serial.println(" ms");
|
||||||
|
Serial.print("Gain: ");
|
||||||
|
Serial.print(gainValue);
|
||||||
|
Serial.println("x");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t SQM_TSL2591::getFullLuminosity(void) {
|
||||||
|
if (!_initialized) {
|
||||||
uint32_t SQM_TSL2591::getFullLuminosity (void)
|
if (!begin()) {
|
||||||
{
|
|
||||||
if (!_initialized)
|
|
||||||
{
|
|
||||||
if (!begin())
|
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -248,8 +226,7 @@ uint32_t SQM_TSL2591::getFullLuminosity (void)
|
||||||
enable();
|
enable();
|
||||||
|
|
||||||
// Wait x ms for ADC to complete
|
// Wait x ms for ADC to complete
|
||||||
for (uint8_t d=0; d<=_integration; d++)
|
for (uint8_t d = 0; d <= _integration; d++) {
|
||||||
{
|
|
||||||
delay(120);
|
delay(120);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,108 +240,108 @@ uint32_t SQM_TSL2591::getFullLuminosity (void)
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQM_TSL2591::bumpGain(int bumpDirection){
|
void SQM_TSL2591::bumpGain(int bumpDirection) {
|
||||||
switch (config.gain)
|
switch (config.gain) {
|
||||||
{
|
case TSL2591_GAIN_LOW:
|
||||||
case TSL2591_GAIN_LOW :
|
if (bumpDirection > 0) {
|
||||||
if (bumpDirection>0){
|
config.gain = TSL2591_GAIN_MED;
|
||||||
config.gain = TSL2591_GAIN_MED;
|
} else {
|
||||||
} else {
|
config.gain = TSL2591_GAIN_LOW;
|
||||||
config.gain = TSL2591_GAIN_LOW;
|
}
|
||||||
}
|
break;
|
||||||
break;
|
case TSL2591_GAIN_MED:
|
||||||
case TSL2591_GAIN_MED :
|
if (bumpDirection > 0) {
|
||||||
if (bumpDirection>0){
|
config.gain = TSL2591_GAIN_HIGH;
|
||||||
config.gain = TSL2591_GAIN_HIGH;
|
} else {
|
||||||
} else {
|
config.gain = TSL2591_GAIN_LOW;
|
||||||
config.gain = TSL2591_GAIN_LOW;
|
}
|
||||||
}
|
break;
|
||||||
break;
|
case TSL2591_GAIN_HIGH:
|
||||||
case TSL2591_GAIN_HIGH :
|
if (bumpDirection > 0) {
|
||||||
if (bumpDirection>0){
|
config.gain = TSL2591_GAIN_MAX;
|
||||||
config.gain = TSL2591_GAIN_MAX;
|
} else {
|
||||||
} else {
|
config.gain = TSL2591_GAIN_MED;
|
||||||
config.gain = TSL2591_GAIN_MED;
|
}
|
||||||
}
|
break;
|
||||||
break;
|
case TSL2591_GAIN_MAX:
|
||||||
case TSL2591_GAIN_MAX :
|
if (bumpDirection > 0) {
|
||||||
if (bumpDirection>0){
|
config.gain = TSL2591_GAIN_MAX;
|
||||||
config.gain = TSL2591_GAIN_MAX;
|
} else {
|
||||||
} else {
|
config.gain = TSL2591_GAIN_HIGH;
|
||||||
config.gain = TSL2591_GAIN_HIGH;
|
}
|
||||||
}
|
break;
|
||||||
break;
|
default:
|
||||||
default:
|
break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
setGain(config.gain);
|
setGain(config.gain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SQM_TSL2591::bumpTime(int bumpDirection) {
|
||||||
void SQM_TSL2591::bumpTime(int bumpDirection){
|
switch (config.time) {
|
||||||
switch (config.time)
|
case TSL2591_INTEGRATIONTIME_200MS:
|
||||||
{
|
if (bumpDirection > 0) {
|
||||||
case TSL2591_INTEGRATIONTIME_200MS :
|
config.time = TSL2591_INTEGRATIONTIME_400MS;
|
||||||
if (bumpDirection>0){
|
} else {
|
||||||
config.time = TSL2591_INTEGRATIONTIME_400MS;
|
config.time = TSL2591_INTEGRATIONTIME_200MS;
|
||||||
} else {
|
}
|
||||||
config.time = TSL2591_INTEGRATIONTIME_200MS;
|
break;
|
||||||
}
|
case TSL2591_INTEGRATIONTIME_400MS:
|
||||||
break;
|
if (bumpDirection > 0) {
|
||||||
case TSL2591_INTEGRATIONTIME_400MS :
|
config.time = TSL2591_INTEGRATIONTIME_600MS;
|
||||||
if (bumpDirection>0){
|
} else {
|
||||||
config.time = TSL2591_INTEGRATIONTIME_600MS;
|
config.time = TSL2591_INTEGRATIONTIME_200MS;
|
||||||
} else {
|
}
|
||||||
config.time = TSL2591_INTEGRATIONTIME_200MS;
|
break;
|
||||||
}
|
case TSL2591_INTEGRATIONTIME_600MS:
|
||||||
break;
|
if (bumpDirection > 0) {
|
||||||
case TSL2591_INTEGRATIONTIME_600MS :
|
config.time = TSL2591_INTEGRATIONTIME_600MS;
|
||||||
if (bumpDirection>0){
|
} else {
|
||||||
config.time = TSL2591_INTEGRATIONTIME_600MS;
|
config.time = TSL2591_INTEGRATIONTIME_400MS;
|
||||||
} else {
|
}
|
||||||
config.time = TSL2591_INTEGRATIONTIME_400MS;
|
break;
|
||||||
}
|
default:
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
setTiming(config.time);
|
setTiming(config.time);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SQM_TSL2591::takeReading(void) {
|
||||||
void SQM_TSL2591::takeReading (void){
|
|
||||||
uint32_t lum;
|
uint32_t lum;
|
||||||
niter=1;
|
niter = 1;
|
||||||
configSensor();
|
configSensor();
|
||||||
lum = getFullLuminosity();
|
lum = getFullLuminosity();
|
||||||
ir = lum >> 16;
|
ir = lum >> 16;
|
||||||
full = lum & 0xFFFF;
|
full = lum & 0xFFFF;
|
||||||
vis = full - ir;
|
vis = full - ir;
|
||||||
if ((float)full < (float)ir){
|
if ((float)full < (float)ir) {
|
||||||
Serial.println("Odd, full less than ir! Rechecking...");
|
if (verbose) {
|
||||||
|
Serial.println("Odd, full less than ir! Rechecking...");
|
||||||
|
}
|
||||||
takeReading();
|
takeReading();
|
||||||
}
|
}
|
||||||
// When intensity is faint at current gain setting
|
// When intensity is faint at current gain setting
|
||||||
if ((float)vis < 128.){
|
if ((float)vis < 128.) {
|
||||||
if (_gain == TSL2591_GAIN_MAX){
|
if (_gain == TSL2591_GAIN_MAX) {
|
||||||
if (_integration != TSL2591_INTEGRATIONTIME_600MS){
|
if (_integration != TSL2591_INTEGRATIONTIME_600MS) {
|
||||||
Serial.println("Bumping integration up");
|
if (verbose) {
|
||||||
|
Serial.println("Bumping integration up");
|
||||||
|
}
|
||||||
bumpTime(1);
|
bumpTime(1);
|
||||||
showConfig();
|
if (verbose)
|
||||||
|
showConfig();
|
||||||
configSensor();
|
configSensor();
|
||||||
lum = getFullLuminosity();
|
lum = getFullLuminosity();
|
||||||
delay(50);
|
delay(50);
|
||||||
takeReading();
|
takeReading();
|
||||||
} else {
|
} else {
|
||||||
uint32_t fullCumulative;
|
uint32_t fullCumulative;
|
||||||
uint16_t visCumulative,irCumulative;
|
uint16_t visCumulative, irCumulative;
|
||||||
|
|
||||||
fullCumulative = full;
|
fullCumulative = full;
|
||||||
irCumulative = ir;
|
irCumulative = ir;
|
||||||
visCumulative = vis;
|
visCumulative = vis;
|
||||||
// Do iterative sampling to gain statistical certainty
|
// Do iterative sampling to gain statistical certainty
|
||||||
while ((float)visCumulative < 128.){
|
while ((float)visCumulative < 128.) {
|
||||||
niter++;
|
niter++;
|
||||||
delay(50);
|
delay(50);
|
||||||
lum = getFullLuminosity();
|
lum = getFullLuminosity();
|
||||||
|
@ -377,20 +354,24 @@ void SQM_TSL2591::takeReading (void){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((float)fullCumulative > (float)irCumulative){
|
if ((float)fullCumulative > (float)irCumulative) {
|
||||||
full = fullCumulative;
|
full = fullCumulative;
|
||||||
ir = irCumulative;
|
ir = irCumulative;
|
||||||
vis = visCumulative;
|
vis = visCumulative;
|
||||||
} else {
|
} else {
|
||||||
Serial.println("Odd, full less than ir! Rechecking...");
|
if (verbose) {
|
||||||
|
Serial.println("Odd, full less than ir! Rechecking...");
|
||||||
|
}
|
||||||
takeReading();
|
takeReading();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Serial.println("Bumping gain up");
|
if (verbose) {
|
||||||
|
Serial.println("Bumping gain up");
|
||||||
|
}
|
||||||
bumpGain(1);
|
bumpGain(1);
|
||||||
showConfig();
|
if (verbose)
|
||||||
|
showConfig();
|
||||||
configSensor();
|
configSensor();
|
||||||
lum = getFullLuminosity();
|
lum = getFullLuminosity();
|
||||||
delay(50);
|
delay(50);
|
||||||
|
@ -398,46 +379,51 @@ void SQM_TSL2591::takeReading (void){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If saturated, bump down integration or gain
|
// If saturated, bump down integration or gain
|
||||||
else if (full == 0xFFFF || ir == 0xFFFF){
|
else if (full == 0xFFFF || ir == 0xFFFF) {
|
||||||
if ((_gain == TSL2591_GAIN_MAX) & (_integration != TSL2591_INTEGRATIONTIME_200MS)){
|
if ((_gain == TSL2591_GAIN_MAX) &
|
||||||
Serial.println("Bumping integration down");
|
(_integration != TSL2591_INTEGRATIONTIME_200MS)) {
|
||||||
|
if (verbose) {
|
||||||
|
Serial.println("Bumping integration down");
|
||||||
|
}
|
||||||
bumpTime(-1);
|
bumpTime(-1);
|
||||||
showConfig();
|
if (verbose)
|
||||||
|
showConfig();
|
||||||
configSensor();
|
configSensor();
|
||||||
lum = getFullLuminosity();
|
lum = getFullLuminosity();
|
||||||
delay(50);
|
delay(50);
|
||||||
takeReading();
|
takeReading();
|
||||||
} else {
|
} else {
|
||||||
Serial.println("Bumping gain down");
|
if (verbose) {
|
||||||
|
Serial.println("Bumping gain down");
|
||||||
|
}
|
||||||
bumpGain(-1);
|
bumpGain(-1);
|
||||||
showConfig();
|
if (verbose)
|
||||||
|
showConfig();
|
||||||
configSensor();
|
configSensor();
|
||||||
lum = getFullLuminosity();
|
lum = getFullLuminosity();
|
||||||
delay(50);
|
delay(50);
|
||||||
takeReading();
|
takeReading();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
float IR = (float)ir / ( gainValue * integrationValue/200.F * niter );
|
float IR = (float)ir / (gainValue * integrationValue / 200.F * niter);
|
||||||
float VIS = (float)vis / ( gainValue * integrationValue/200.F * niter );
|
float VIS = (float)vis / (gainValue * integrationValue / 200.F * niter);
|
||||||
mpsas = 12.6 - 1.086 * log(VIS) + _calibrationOffset;
|
mpsas = 12.6 - 1.086 * log(VIS) + _calibrationOffset;
|
||||||
dmpsas = 1.086 / sqrt((float)vis);
|
dmpsas = 1.086 / sqrt((float)vis);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t SQM_TSL2591::read8(uint8_t reg) {
|
||||||
uint8_t SQM_TSL2591::read8(uint8_t reg)
|
|
||||||
{
|
|
||||||
Wire.beginTransmission(TSL2591_ADDR);
|
Wire.beginTransmission(TSL2591_ADDR);
|
||||||
Wire.write(0x80 | 0x20 | reg); // command bit, normal mode
|
Wire.write(0x80 | 0x20 | reg); // command bit, normal mode
|
||||||
Wire.endTransmission();
|
Wire.endTransmission();
|
||||||
|
|
||||||
Wire.requestFrom(TSL2591_ADDR, 1);
|
Wire.requestFrom(TSL2591_ADDR, 1);
|
||||||
while (! Wire.available());
|
while (!Wire.available())
|
||||||
|
;
|
||||||
return Wire.read();
|
return Wire.read();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t SQM_TSL2591::read16(uint8_t reg)
|
uint16_t SQM_TSL2591::read16(uint8_t reg) {
|
||||||
{
|
|
||||||
uint16_t x;
|
uint16_t x;
|
||||||
uint16_t t;
|
uint16_t t;
|
||||||
|
|
||||||
|
@ -462,8 +448,7 @@ uint16_t SQM_TSL2591::read16(uint8_t reg)
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQM_TSL2591::write8 (uint8_t reg, uint8_t value)
|
void SQM_TSL2591::write8(uint8_t reg, uint8_t value) {
|
||||||
{
|
|
||||||
Wire.beginTransmission(TSL2591_ADDR);
|
Wire.beginTransmission(TSL2591_ADDR);
|
||||||
#if ARDUINO >= 100
|
#if ARDUINO >= 100
|
||||||
Wire.write(reg);
|
Wire.write(reg);
|
||||||
|
@ -475,17 +460,14 @@ void SQM_TSL2591::write8 (uint8_t reg, uint8_t value)
|
||||||
Wire.endTransmission();
|
Wire.endTransmission();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
float SQM_TSL2591::calculateLux(uint16_t ch0, uint16_t ch1) /*wbp*/
|
float SQM_TSL2591::calculateLux(uint16_t ch0, uint16_t ch1) /*wbp*/
|
||||||
{
|
{
|
||||||
float atime, again; /*wbp*/
|
float atime, again; /*wbp*/
|
||||||
float cpl, lux1, lux2, lux;
|
float cpl, lux1, lux2, lux;
|
||||||
// uint32_t chan0, chan1; /*wbp*/
|
// uint32_t chan0, chan1; /*wbp*/
|
||||||
|
|
||||||
// Check for overflow conditions first
|
// Check for overflow conditions first
|
||||||
if ((ch0 == 0xFFFF) | (ch1 == 0xFFFF))
|
if ((ch0 == 0xFFFF) | (ch1 == 0xFFFF)) {
|
||||||
{
|
|
||||||
// Signal an overflow
|
// Signal an overflow
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
@ -493,65 +475,64 @@ float SQM_TSL2591::calculateLux(uint16_t ch0, uint16_t ch1) /*wbp*/
|
||||||
// Note: This algorithm is based on preliminary coefficients
|
// Note: This algorithm is based on preliminary coefficients
|
||||||
// provided by AMS and may need to be updated in the future
|
// provided by AMS and may need to be updated in the future
|
||||||
|
|
||||||
switch (_integration)
|
switch (_integration) {
|
||||||
{
|
case TSL2591_INTEGRATIONTIME_100MS:
|
||||||
case TSL2591_INTEGRATIONTIME_100MS :
|
atime = 100.0F;
|
||||||
atime = 100.0F;
|
break;
|
||||||
break;
|
case TSL2591_INTEGRATIONTIME_200MS:
|
||||||
case TSL2591_INTEGRATIONTIME_200MS :
|
atime = 200.0F;
|
||||||
atime = 200.0F;
|
break;
|
||||||
break;
|
case TSL2591_INTEGRATIONTIME_300MS:
|
||||||
case TSL2591_INTEGRATIONTIME_300MS :
|
atime = 300.0F;
|
||||||
atime = 300.0F;
|
break;
|
||||||
break;
|
case TSL2591_INTEGRATIONTIME_400MS:
|
||||||
case TSL2591_INTEGRATIONTIME_400MS :
|
atime = 400.0F;
|
||||||
atime = 400.0F;
|
break;
|
||||||
break;
|
case TSL2591_INTEGRATIONTIME_500MS:
|
||||||
case TSL2591_INTEGRATIONTIME_500MS :
|
atime = 500.0F;
|
||||||
atime = 500.0F;
|
break;
|
||||||
break;
|
case TSL2591_INTEGRATIONTIME_600MS:
|
||||||
case TSL2591_INTEGRATIONTIME_600MS :
|
atime = 600.0F;
|
||||||
atime = 600.0F;
|
break;
|
||||||
break;
|
default: // 200ms
|
||||||
default: // 200ms
|
atime = 200.0F;
|
||||||
atime = 200.0F;
|
break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (_gain)
|
switch (_gain) {
|
||||||
{
|
case TSL2591_GAIN_LOW:
|
||||||
case TSL2591_GAIN_LOW :
|
// again = 1.0F;
|
||||||
// again = 1.0F;
|
again = 1.03F; /*wbp*/
|
||||||
again = 1.03F; /*wbp*/
|
break;
|
||||||
break;
|
case TSL2591_GAIN_MED:
|
||||||
case TSL2591_GAIN_MED :
|
again = 25.0F;
|
||||||
again = 25.0F;
|
break;
|
||||||
break;
|
case TSL2591_GAIN_HIGH:
|
||||||
case TSL2591_GAIN_HIGH :
|
// again = 428.0F;
|
||||||
// again = 428.0F;
|
again = 425.0F; /*wbp*/
|
||||||
again = 425.0F; /*wbp*/
|
break;
|
||||||
break;
|
case TSL2591_GAIN_MAX:
|
||||||
case TSL2591_GAIN_MAX :
|
// again = 9876.0F;
|
||||||
// again = 9876.0F;
|
again = 7850.0F; /*wbp*/
|
||||||
again = 7850.0F; /*wbp*/
|
break;
|
||||||
break;
|
default:
|
||||||
default:
|
again = 1.0F;
|
||||||
again = 1.0F;
|
break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cpl = (ATIME * AGAIN) / DF
|
// cpl = (ATIME * AGAIN) / DF
|
||||||
cpl = (atime * again) / TSL2591_LUX_DF;
|
cpl = (atime * again) / TSL2591_LUX_DF;
|
||||||
|
|
||||||
lux1 = ( (float)ch0 - (TSL2591_LUX_COEFB * (float)ch1) ) / cpl;
|
lux1 = ((float)ch0 - (TSL2591_LUX_COEFB * (float)ch1)) / cpl;
|
||||||
lux2 = ( ( TSL2591_LUX_COEFC * (float)ch0 ) - ( TSL2591_LUX_COEFD * (float)ch1 ) ) / cpl;
|
lux2 = ((TSL2591_LUX_COEFC * (float)ch0) - (TSL2591_LUX_COEFD * (float)ch1)) /
|
||||||
|
cpl;
|
||||||
|
|
||||||
// The highest value is the approximate lux equivalent
|
// The highest value is the approximate lux equivalent
|
||||||
lux = lux1 > lux2 ? lux1 : lux2;
|
lux = lux1 > lux2 ? lux1 : lux2;
|
||||||
|
|
||||||
// Signal I2C had no errors
|
// Signal I2C had no errors
|
||||||
// return (uint32_t)lux;return (uint32_t)lux;
|
// return (uint32_t)lux;return (uint32_t)lux;
|
||||||
return lux; /*wbp*/
|
return lux; /*wbp*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
@ -559,8 +540,7 @@ float SQM_TSL2591::calculateLux(uint16_t ch0, uint16_t ch1) /*wbp*/
|
||||||
@brief Gets the most recent sensor event
|
@brief Gets the most recent sensor event
|
||||||
*/
|
*/
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
bool SQM_TSL2591::getEvent(sensors_event_t *event)
|
bool SQM_TSL2591::getEvent(sensors_event_t *event) {
|
||||||
{
|
|
||||||
uint16_t ir, full;
|
uint16_t ir, full;
|
||||||
uint32_t lum = getFullLuminosity();
|
uint32_t lum = getFullLuminosity();
|
||||||
/* Early silicon seems to have issues when there is a sudden jump in */
|
/* Early silicon seems to have issues when there is a sudden jump in */
|
||||||
|
@ -572,9 +552,9 @@ bool SQM_TSL2591::getEvent(sensors_event_t *event)
|
||||||
/* Clear the event */
|
/* Clear the event */
|
||||||
memset(event, 0, sizeof(sensors_event_t));
|
memset(event, 0, sizeof(sensors_event_t));
|
||||||
|
|
||||||
event->version = sizeof(sensors_event_t);
|
event->version = sizeof(sensors_event_t);
|
||||||
event->sensor_id = _sensorID;
|
event->sensor_id = _sensorID;
|
||||||
event->type = SENSOR_TYPE_LIGHT;
|
event->type = SENSOR_TYPE_LIGHT;
|
||||||
event->timestamp = millis();
|
event->timestamp = millis();
|
||||||
|
|
||||||
/* Calculate the actual lux value */
|
/* Calculate the actual lux value */
|
||||||
|
@ -588,19 +568,18 @@ bool SQM_TSL2591::getEvent(sensors_event_t *event)
|
||||||
@brief Gets the sensor_t data
|
@brief Gets the sensor_t data
|
||||||
*/
|
*/
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
void SQM_TSL2591::getSensor(sensor_t *sensor)
|
void SQM_TSL2591::getSensor(sensor_t *sensor) {
|
||||||
{
|
|
||||||
/* Clear the sensor_t object */
|
/* Clear the sensor_t object */
|
||||||
memset(sensor, 0, sizeof(sensor_t));
|
memset(sensor, 0, sizeof(sensor_t));
|
||||||
|
|
||||||
/* Insert the sensor name in the fixed length char array */
|
/* Insert the sensor name in the fixed length char array */
|
||||||
strncpy (sensor->name, "TSL2591", sizeof(sensor->name) - 1);
|
strncpy(sensor->name, "TSL2591", sizeof(sensor->name) - 1);
|
||||||
sensor->name[sizeof(sensor->name)- 1] = 0;
|
sensor->name[sizeof(sensor->name) - 1] = 0;
|
||||||
sensor->version = 1;
|
sensor->version = 1;
|
||||||
sensor->sensor_id = _sensorID;
|
sensor->sensor_id = _sensorID;
|
||||||
sensor->type = SENSOR_TYPE_LIGHT;
|
sensor->type = SENSOR_TYPE_LIGHT;
|
||||||
sensor->min_delay = 0;
|
sensor->min_delay = 0;
|
||||||
sensor->max_value = 88000.0;
|
sensor->max_value = 88000.0;
|
||||||
sensor->min_value = 0.001;
|
sensor->min_value = 0.001;
|
||||||
sensor->resolution = 0.001;
|
sensor->resolution = 0.001;
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,6 +158,7 @@ class SQM_TSL2591 : public Adafruit_Sensor
|
||||||
sensorConfig config;
|
sensorConfig config;
|
||||||
float integrationValue, gainValue;
|
float integrationValue, gainValue;
|
||||||
double mpsas, dmpsas;
|
double mpsas, dmpsas;
|
||||||
|
bool verbose;
|
||||||
|
|
||||||
void bumpGain(int bumpDirection);
|
void bumpGain(int bumpDirection);
|
||||||
void bumpTime(int bumpDirection);
|
void bumpTime(int bumpDirection);
|
||||||
|
|
|
@ -0,0 +1,155 @@
|
||||||
|
#include "ESP8266WiFi.h"
|
||||||
|
#include "SQM_TSL2591.h"
|
||||||
|
#include <Adafruit_BME280.h>
|
||||||
|
#include <Adafruit_Sensor.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
|
#define SEALEVELPRESSURE_HPA (1013.25)
|
||||||
|
|
||||||
|
SQM_TSL2591 sqm = SQM_TSL2591(2591);
|
||||||
|
|
||||||
|
void readSQM(void);
|
||||||
|
|
||||||
|
String PROTOCOL_NUMBER = "00000002";
|
||||||
|
String MODEL_NUMBER = "00000003";
|
||||||
|
String FEATURE_NUMBER = "00000001";
|
||||||
|
String SERIAL_NUMBER = "00000000";
|
||||||
|
|
||||||
|
// ESP8266 has polarity switched
|
||||||
|
bool LED_ON = LOW;
|
||||||
|
bool LED_OFF = HIGH;
|
||||||
|
|
||||||
|
const char *ssid = "WIFI_SSID";
|
||||||
|
const char *password = "WIFI_PASSWORD";
|
||||||
|
|
||||||
|
WiFiServer wifiServer(10001);
|
||||||
|
|
||||||
|
void setup_tsl() {
|
||||||
|
pinMode(13, OUTPUT);
|
||||||
|
if (sqm.begin()) {
|
||||||
|
|
||||||
|
Serial.println("Found SQM (TSL) sensor");
|
||||||
|
sqm.config.gain = TSL2591_GAIN_LOW;
|
||||||
|
sqm.config.time = TSL2591_INTEGRATIONTIME_200MS;
|
||||||
|
sqm.configSensor();
|
||||||
|
sqm.showConfig();
|
||||||
|
sqm.setCalibrationOffset(0.0);
|
||||||
|
} else {
|
||||||
|
Serial.println("SQM sensor not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup temperature sensor. This example uses the BME280 sensor.
|
||||||
|
Adafruit_BME280 bme; // I2C
|
||||||
|
void setup_temperature() {
|
||||||
|
bool status;
|
||||||
|
// default settings
|
||||||
|
status = bme.begin();
|
||||||
|
if (!status) {
|
||||||
|
Serial.println("Could not find a valid BME280 sensor, check wiring!");
|
||||||
|
while (1)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
float get_temperature() { return bme.readTemperature(); }
|
||||||
|
|
||||||
|
void setup_wifi() {
|
||||||
|
WiFi.begin(ssid, password);
|
||||||
|
|
||||||
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
|
delay(1000);
|
||||||
|
Serial.println("Connecting..");
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.print("Connected to WiFi. IP:");
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
|
wifiServer.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
String IpAddress2String(const IPAddress &ipAddress) {
|
||||||
|
return String(ipAddress[0]) + String(".") + String(ipAddress[1]) +
|
||||||
|
String(".") + String(ipAddress[2]) + String(".") +
|
||||||
|
String(ipAddress[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
Serial.begin(115200);
|
||||||
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
|
digitalWrite(LED_BUILTIN, LED_OFF);
|
||||||
|
|
||||||
|
// Start watchdog setup
|
||||||
|
wdt_enable(WDTO_8S);
|
||||||
|
|
||||||
|
setup_temperature();
|
||||||
|
|
||||||
|
setup_wifi();
|
||||||
|
|
||||||
|
setup_tsl();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
String temp_string;
|
||||||
|
float temp;
|
||||||
|
|
||||||
|
wdt_reset();
|
||||||
|
WiFiClient client = wifiServer.available();
|
||||||
|
|
||||||
|
if (client) {
|
||||||
|
|
||||||
|
while (client.connected()) {
|
||||||
|
String response = "";
|
||||||
|
|
||||||
|
while (client.available() > 0) {
|
||||||
|
temp = get_temperature();
|
||||||
|
sqm.takeReading();
|
||||||
|
delay(10);
|
||||||
|
digitalWrite(LED_BUILTIN, LED_ON);
|
||||||
|
char c = client.read();
|
||||||
|
|
||||||
|
String remote_ip = String(IpAddress2String(client.remoteIP()));
|
||||||
|
Serial.println(String("Request received from ") + remote_ip);
|
||||||
|
|
||||||
|
if (c == 'i') {
|
||||||
|
client.println(String(response + "i," + PROTOCOL_NUMBER + "," +
|
||||||
|
MODEL_NUMBER + "," + FEATURE_NUMBER + "," +
|
||||||
|
SERIAL_NUMBER));
|
||||||
|
}
|
||||||
|
if (c == 'r') {
|
||||||
|
Serial.println(String("Sending data: ") + String(sqm.mpsas, 3));
|
||||||
|
if (sqm.mpsas < 10.) {
|
||||||
|
response = "r, ";
|
||||||
|
} else if (sqm.mpsas < 0) {
|
||||||
|
response = "r,";
|
||||||
|
} else {
|
||||||
|
response = "r, ";
|
||||||
|
}
|
||||||
|
if (temp < 0.) {
|
||||||
|
temp_string = ", ";
|
||||||
|
} else if (temp < 10.) {
|
||||||
|
temp_string = ", ";
|
||||||
|
} else {
|
||||||
|
temp_string = ", ";
|
||||||
|
}
|
||||||
|
temp_string = String(temp_string + String(temp, 1) + "C");
|
||||||
|
|
||||||
|
response =
|
||||||
|
String(response + String(sqm.mpsas, 2) +
|
||||||
|
"m,0000005915Hz,0000000000c,0000000.000s" + temp_string);
|
||||||
|
client.println(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
client.stop();
|
||||||
|
Serial.println("Client disconnected");
|
||||||
|
digitalWrite(LED_BUILTIN, LED_OFF);
|
||||||
|
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,117 @@
|
||||||
|
#include "SQM_TSL2591.h"
|
||||||
|
#include <Adafruit_BME280.h>
|
||||||
|
#include <Adafruit_Sensor.h>
|
||||||
|
#include <avr/wdt.h>
|
||||||
|
|
||||||
|
#define SEALEVELPRESSURE_HPA (1013.25)
|
||||||
|
|
||||||
|
SQM_TSL2591 sqm = SQM_TSL2591(2591);
|
||||||
|
|
||||||
|
void readSQM(void);
|
||||||
|
|
||||||
|
String PROTOCOL_NUMBER = "00000002";
|
||||||
|
String MODEL_NUMBER = "00000003";
|
||||||
|
String FEATURE_NUMBER = "00000001";
|
||||||
|
String SERIAL_NUMBER = "00000000";
|
||||||
|
|
||||||
|
bool LED_ON = HIGH;
|
||||||
|
bool LED_OFF = LOW;
|
||||||
|
|
||||||
|
void setup_tsl() {
|
||||||
|
pinMode(13, OUTPUT);
|
||||||
|
if (sqm.begin()) {
|
||||||
|
sqm.config.gain = TSL2591_GAIN_LOW;
|
||||||
|
sqm.config.time = TSL2591_INTEGRATIONTIME_200MS;
|
||||||
|
sqm.configSensor();
|
||||||
|
sqm.setCalibrationOffset(0.0);
|
||||||
|
sqm.verbose = false;
|
||||||
|
} else {
|
||||||
|
Serial.println("SQM sensor not found");
|
||||||
|
}
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup temperature sensor. This example uses the BME280 sensor.
|
||||||
|
Adafruit_BME280 bme; // I2C
|
||||||
|
void setup_temperature() {
|
||||||
|
bool status;
|
||||||
|
// default settings
|
||||||
|
status = bme.begin();
|
||||||
|
if (!status) {
|
||||||
|
Serial.println("Could not find a valid BME280 sensor, check wiring!");
|
||||||
|
while (1)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
float get_temperature() { return bme.readTemperature(); }
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
Serial.begin(115200);
|
||||||
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
|
digitalWrite(LED_BUILTIN, LED_OFF);
|
||||||
|
|
||||||
|
// Start watchdog setup
|
||||||
|
wdt_enable(WDTO_8S);
|
||||||
|
|
||||||
|
setup_temperature();
|
||||||
|
|
||||||
|
setup_tsl();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
String temp_string;
|
||||||
|
float temp;
|
||||||
|
|
||||||
|
wdt_reset();
|
||||||
|
|
||||||
|
String response = "";
|
||||||
|
bool new_data = false;
|
||||||
|
|
||||||
|
while (Serial.available() > 0) {
|
||||||
|
|
||||||
|
temp = get_temperature();
|
||||||
|
sqm.takeReading();
|
||||||
|
digitalWrite(LED_BUILTIN, LED_ON);
|
||||||
|
char c = Serial.read();
|
||||||
|
|
||||||
|
if (c == 'i') {
|
||||||
|
response = String(response + "i," + PROTOCOL_NUMBER + "," + MODEL_NUMBER +
|
||||||
|
"," + FEATURE_NUMBER + "," + SERIAL_NUMBER);
|
||||||
|
new_data = true;
|
||||||
|
}
|
||||||
|
if (c == 'r') {
|
||||||
|
if (sqm.mpsas < 10.) {
|
||||||
|
response = "r, ";
|
||||||
|
} else if (sqm.mpsas < 0) {
|
||||||
|
response = "r,";
|
||||||
|
} else {
|
||||||
|
response = "r, ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (temp < 0.) {
|
||||||
|
temp_string = ", ";
|
||||||
|
} else if (temp < 10.) {
|
||||||
|
temp_string = ", ";
|
||||||
|
} else {
|
||||||
|
temp_string = ", ";
|
||||||
|
}
|
||||||
|
|
||||||
|
temp_string = String(temp_string + String(temp, 1) + "C");
|
||||||
|
|
||||||
|
response =
|
||||||
|
String(response + String(sqm.mpsas, 2) +
|
||||||
|
"m,0000005915Hz,0000000000c,0000000.000s" + temp_string);
|
||||||
|
new_data = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (new_data) {
|
||||||
|
Serial.println(response);
|
||||||
|
new_data = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
digitalWrite(LED_BUILTIN, LED_OFF);
|
||||||
|
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
}
|
Ładowanie…
Reference in New Issue