diff --git a/lib/Joba_Tsl2561-2.0.10/.gitignore b/lib/Joba_Tsl2561-2.0.10/.gitignore new file mode 100644 index 000000000..2f4f2baeb --- /dev/null +++ b/lib/Joba_Tsl2561-2.0.10/.gitignore @@ -0,0 +1,8 @@ +.pioenvs +.piolibdeps +.clang_complete +.gcc-flags.json +examples/*/platformio.ini +examples/*/lib +examples/*/.gitignore +examples/*/.travis.yml diff --git a/lib/Joba_Tsl2561-2.0.10/.hgignore b/lib/Joba_Tsl2561-2.0.10/.hgignore new file mode 100644 index 000000000..5dac9f52f --- /dev/null +++ b/lib/Joba_Tsl2561-2.0.10/.hgignore @@ -0,0 +1,4 @@ +.pioenvs +.piolibdeps +.clang_complete +.gcc-flags.json diff --git a/lib/Joba_Tsl2561-2.0.10/.travis.yml b/lib/Joba_Tsl2561-2.0.10/.travis.yml new file mode 100644 index 000000000..52072efd6 --- /dev/null +++ b/lib/Joba_Tsl2561-2.0.10/.travis.yml @@ -0,0 +1,55 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < http://docs.platformio.org/page/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < http://docs.platformio.org/page/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < http://docs.platformio.org/page/userguide/cmd_ci.html > +# +# +# Please choice one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# install: +# - pip install -U platformio +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to by used as a library with examples +# + +# language: python +# python: +# - "2.7" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/lib/Joba_Tsl2561-2.0.7/COPYING b/lib/Joba_Tsl2561-2.0.10/COPYING similarity index 100% rename from lib/Joba_Tsl2561-2.0.7/COPYING rename to lib/Joba_Tsl2561-2.0.10/COPYING diff --git a/lib/Joba_Tsl2561-2.0.7/COPYING.LESSER b/lib/Joba_Tsl2561-2.0.10/COPYING.LESSER similarity index 100% rename from lib/Joba_Tsl2561-2.0.7/COPYING.LESSER rename to lib/Joba_Tsl2561-2.0.10/COPYING.LESSER diff --git a/lib/Joba_Tsl2561-2.0.7/README b/lib/Joba_Tsl2561-2.0.10/README similarity index 87% rename from lib/Joba_Tsl2561-2.0.7/README rename to lib/Joba_Tsl2561-2.0.10/README index 86c1f1a0b..d95e731d5 100644 --- a/lib/Joba_Tsl2561-2.0.7/README +++ b/lib/Joba_Tsl2561-2.0.10/README @@ -1,4 +1,4 @@ -This is a library for the TSL2561 digital luminosity sensors from Ams (Taos). +This is an Arduino library for the TSL2561 digital luminosity sensors from Ams (Taos). Design goals: * It is modularized so you can use only what you need if space/ram is constrained. @@ -18,3 +18,5 @@ The library has 3 classes: Tsl2561 All register access as described in the datasheet, except for interrupts Tsl2561Util Convenience functions like lux calculation or automatic gain Tsl2561Int TODO, Interrupt related stuff (not needed if int pin unconnected) + +Tested with boards Nano, ESP8266 and ESP32 diff --git a/lib/Joba_Tsl2561-2.0.7/examples/Autogain/Autogain.ino b/lib/Joba_Tsl2561-2.0.10/examples/Autogain/Autogain.ino similarity index 96% rename from lib/Joba_Tsl2561-2.0.7/examples/Autogain/Autogain.ino rename to lib/Joba_Tsl2561-2.0.10/examples/Autogain/Autogain.ino index 169d2b6e3..9547af45b 100644 --- a/lib/Joba_Tsl2561-2.0.7/examples/Autogain/Autogain.ino +++ b/lib/Joba_Tsl2561-2.0.10/examples/Autogain/Autogain.ino @@ -21,7 +21,7 @@ This file is part of the Joba_Tsl2561 Library. #include -// to mimic Serial.printf() of esp8266 core for other platforms +// to mimic Serial.printf() of esp cores for other platforms char *format( const char *fmt, ... ) { static char buf[128]; va_list arg; @@ -37,7 +37,7 @@ uint8_t id; void setup() { Serial.begin(115200); - Wire.begin(); + Wire.begin(TSL2561_SDA, TSL2561_SCL); while( !Tsl.begin() ) ; // wait until chip detected or wdt reset Serial.println("\nStarting Tsl2561Util autogain loop"); diff --git a/lib/Joba_Tsl2561-2.0.7/examples/Simple/Simple.ino b/lib/Joba_Tsl2561-2.0.10/examples/Simple/Simple.ino similarity index 88% rename from lib/Joba_Tsl2561-2.0.7/examples/Simple/Simple.ino rename to lib/Joba_Tsl2561-2.0.10/examples/Simple/Simple.ino index 5bebb7e50..b63f71b94 100644 --- a/lib/Joba_Tsl2561-2.0.7/examples/Simple/Simple.ino +++ b/lib/Joba_Tsl2561-2.0.10/examples/Simple/Simple.ino @@ -21,7 +21,7 @@ This file is part of the Joba_Tsl2561 Library. #include -// to mimic Serial.printf() of esp8266 core for other platforms +// to mimic Serial.printf() of esp cores for other platforms char *format( const char *fmt, ... ) { static char buf[128]; va_list arg; @@ -36,7 +36,7 @@ Tsl2561 Tsl(Wire); void setup() { Serial.begin(115200); - Wire.begin(); + Wire.begin(TSL2561_SDA, TSL2561_SCL); Serial.println("\nStarting Tsl2561 simple loop"); } @@ -60,7 +60,7 @@ void loop() { Tsl.off(); } else { - Serial.println("No Tsl2561 found. Check wiring."); + Serial.print(format("No Tsl2561 found. Check wiring: SCL=%u, SDA=%u\n", TSL2561_SCL, TSL2561_SDA)); } delay(5000); diff --git a/lib/Joba_Tsl2561-2.0.7/examples/Testing/Testing.ino b/lib/Joba_Tsl2561-2.0.10/examples/Testing/Testing.ino similarity index 97% rename from lib/Joba_Tsl2561-2.0.7/examples/Testing/Testing.ino rename to lib/Joba_Tsl2561-2.0.10/examples/Testing/Testing.ino index 0dbeb09be..861891666 100644 --- a/lib/Joba_Tsl2561-2.0.7/examples/Testing/Testing.ino +++ b/lib/Joba_Tsl2561-2.0.10/examples/Testing/Testing.ino @@ -22,7 +22,7 @@ This file is part of the Joba_Tsl2561 Library. #include -// to mimic Serial.printf() of esp8266 core for other platforms +// to mimic Serial.printf() of esp cores for other platforms char *format( const char *fmt, ... ) { static char buf[128]; va_list arg; @@ -158,7 +158,7 @@ void test( Tsl2561 &tsl ) { void setup() { Serial.begin(115200); - Wire.begin(); + Wire.begin(TSL2561_SDA, TSL2561_SCL); Serial.println("\nStarting Tsl2561 testing loop"); } diff --git a/lib/Joba_Tsl2561-2.0.7/examples/Utility/Utility.ino b/lib/Joba_Tsl2561-2.0.10/examples/Utility/Utility.ino similarity index 93% rename from lib/Joba_Tsl2561-2.0.7/examples/Utility/Utility.ino rename to lib/Joba_Tsl2561-2.0.10/examples/Utility/Utility.ino index d05549616..14ba320d0 100644 --- a/lib/Joba_Tsl2561-2.0.7/examples/Utility/Utility.ino +++ b/lib/Joba_Tsl2561-2.0.10/examples/Utility/Utility.ino @@ -21,7 +21,7 @@ This file is part of the Joba_Tsl2561 Library. #include -// to mimic Serial.printf() of esp8266 core for other platforms +// to mimic Serial.printf() of esp cores for other platforms char *format( const char *fmt, ... ) { static char buf[128]; va_list arg; @@ -37,7 +37,7 @@ Tsl2561 Tsl(Wire); void setup() { Serial.begin(115200); - Wire.begin(); + Wire.begin(TSL2561_SDA, TSL2561_SCL); Serial.println("\nStarting Tsl2561Util loop"); } @@ -91,7 +91,7 @@ void loop() { } if( !found ) { - Serial.println("No Tsl2561 found. Check wiring."); + Serial.print(format("No Tsl2561 found. Check wiring: SCL=%u, SDA=%u\n", TSL2561_SCL, TSL2561_SDA)); } delay(5000); diff --git a/lib/Joba_Tsl2561-2.0.7/platformio.ini b/lib/Joba_Tsl2561-2.0.10/examples/platformio.ini similarity index 67% rename from lib/Joba_Tsl2561-2.0.7/platformio.ini rename to lib/Joba_Tsl2561-2.0.10/examples/platformio.ini index ea6847aaa..07efee0d2 100644 --- a/lib/Joba_Tsl2561-2.0.7/platformio.ini +++ b/lib/Joba_Tsl2561-2.0.10/examples/platformio.ini @@ -18,9 +18,13 @@ [platformio] +src_dir = . +lib_dir = ../.. + ; uncomment one, if you want to build only one ; env_default = nodemcuv2 ; env_default = nano328 +; env_default = espressif32 [env:nodemcuv2] @@ -28,12 +32,12 @@ ; ------------ ; GND <-> GND ; VCC <-> 3V -; SCL <-> D1 -; SDA <-> D2 +; SCL <-> D1 (other pin can be defined below) +; SDA <-> D2 (other pin can be defined below) platform = espressif8266 board = nodemcuv2 framework = arduino -build_flags = -Wall +build_flags = -Wall -DTSL2561_SCL=D1 -DTSL2561_SDA=D2 monitor_speed = 115200 @@ -53,6 +57,25 @@ upload_resetmethod = nodemcu platform = atmelavr board = nanoatmega328 framework = arduino -build_flags = -Wall +build_flags = -Wall -DTSL2561_SCL=A5 -DTSL2561_SDA=A4 monitor_speed = 115200 +;upload_port = /dev/ttyUSB[1-9] + + +[env:espressif32] +; TSL <-> ESP32 +; ------------ +; GND <-> GND +; VCC <-> 3V +; SCL <-> IO22 (other pin can be defined below) +; SDA <-> IO21 (other pin can be defined below) +platform = espressif32 +board = mhetesp32minikit +framework = arduino +build_flags = -Wall -DTSL2561_SCL=22 -DTSL2561_SDA=21 + +monitor_speed = 115200 + +upload_speed = 921600 +;upload_port = /dev/ttyUSB[1-9] diff --git a/lib/Joba_Tsl2561-2.0.7/examples/platformio.sh b/lib/Joba_Tsl2561-2.0.10/examples/platformio.sh similarity index 100% rename from lib/Joba_Tsl2561-2.0.7/examples/platformio.sh rename to lib/Joba_Tsl2561-2.0.10/examples/platformio.sh diff --git a/lib/Joba_Tsl2561-2.0.7/lib/readme.txt b/lib/Joba_Tsl2561-2.0.10/lib/readme.txt similarity index 100% rename from lib/Joba_Tsl2561-2.0.7/lib/readme.txt rename to lib/Joba_Tsl2561-2.0.10/lib/readme.txt diff --git a/lib/Joba_Tsl2561-2.0.7/library.json b/lib/Joba_Tsl2561-2.0.10/library.json similarity index 62% rename from lib/Joba_Tsl2561-2.0.7/library.json rename to lib/Joba_Tsl2561-2.0.10/library.json index 94585c488..86545a6a0 100644 --- a/lib/Joba_Tsl2561-2.0.7/library.json +++ b/lib/Joba_Tsl2561-2.0.10/library.json @@ -1,8 +1,8 @@ { "name": "Joba_Tsl2561", - "version": "2.0.7", + "version": "2.0.10", "keywords": "twowire, i2c, bus, sensor, luminosity, illuminance, lux", - "description": "Arduino Library for ams (taos) luminance chip Tsl2561 with autogain", + "description": "Arduino library for ams (taos) luminance chip Tsl2561 with autogain. Tested with Nano, Esp8266 and Esp32.", "repository": { "type": "git", diff --git a/lib/Joba_Tsl2561-2.0.7/library.properties b/lib/Joba_Tsl2561-2.0.10/library.properties similarity index 67% rename from lib/Joba_Tsl2561-2.0.7/library.properties rename to lib/Joba_Tsl2561-2.0.10/library.properties index ba1840764..5d83edb31 100644 --- a/lib/Joba_Tsl2561-2.0.7/library.properties +++ b/lib/Joba_Tsl2561-2.0.10/library.properties @@ -1,9 +1,9 @@ name=Joba Tsl2561 Library -version=2.0.7 +version=2.0.10 author=joba-1 maintainer=joba-1 sentence=IoT library for using the Tsl2561 luminosity sensor -paragraph=Luminosity measurement in lux with autogain +paragraph=Luminosity measurement in lux with autogain. Tested with Nano, Esp8266 and Esp32. category=Sensors url=https://github.com/joba-1/Joba_Tsl2561 architectures=* diff --git a/lib/Joba_Tsl2561-2.0.7/examples/platformio.ini b/lib/Joba_Tsl2561-2.0.10/platformio.ini similarity index 75% rename from lib/Joba_Tsl2561-2.0.7/examples/platformio.ini rename to lib/Joba_Tsl2561-2.0.10/platformio.ini index ef71e03ae..87d88e183 100644 --- a/lib/Joba_Tsl2561-2.0.7/examples/platformio.ini +++ b/lib/Joba_Tsl2561-2.0.10/platformio.ini @@ -18,20 +18,19 @@ [platformio] -src_dir = . -lib_dir = ../.. - ; uncomment one, if you want to build only one ; env_default = nodemcuv2 ; env_default = nano328 +; env_default = espressif32 + [env:nodemcuv2] ; TSL <-> ESP8266 ; ------------ ; GND <-> GND ; VCC <-> 3V -; SCL <-> D1 -; SDA <-> D2 +; SCL <-> D1 (other pin can be defined below) +; SDA <-> D2 (other pin can be defined below) platform = espressif8266 board = nodemcuv2 framework = arduino @@ -58,4 +57,21 @@ framework = arduino build_flags = -Wall monitor_speed = 115200 + + +[env:espressif32] +; TSL <-> ESP32 +; ------------ +; GND <-> GND +; VCC <-> 3V +; SCL <-> IO22 (other pin can be defined below) +; SDA <-> IO21 (other pin can be defined below) +platform = espressif32 +board = mhetesp32minikit +framework = arduino +build_flags = -Wall -DTSL2561_SCL=22 -DTSL2561_SDA=21 + +monitor_speed = 115200 + +upload_speed = 921600 ;upload_port = /dev/ttyUSB[1-9] diff --git a/lib/Joba_Tsl2561-2.0.7/src/Tsl2561.cpp b/lib/Joba_Tsl2561-2.0.10/src/Tsl2561.cpp similarity index 100% rename from lib/Joba_Tsl2561-2.0.7/src/Tsl2561.cpp rename to lib/Joba_Tsl2561-2.0.10/src/Tsl2561.cpp diff --git a/lib/Joba_Tsl2561-2.0.7/src/Tsl2561.h b/lib/Joba_Tsl2561-2.0.10/src/Tsl2561.h similarity index 94% rename from lib/Joba_Tsl2561-2.0.7/src/Tsl2561.h rename to lib/Joba_Tsl2561-2.0.10/src/Tsl2561.h index 75056f912..147db2a77 100644 --- a/lib/Joba_Tsl2561-2.0.7/src/Tsl2561.h +++ b/lib/Joba_Tsl2561-2.0.10/src/Tsl2561.h @@ -23,6 +23,14 @@ This file is part of the Joba_Tsl2561 Library. #include #include +// To be able to override pin definitions in build flags (used in examples) +#ifndef TSL2561_SDA + #define TSL2561_SDA SDA +#endif +#ifndef TSL2561_SCL + #define TSL2561_SCL SCL +#endif + class Tsl2561 { public: diff --git a/lib/Joba_Tsl2561-2.0.7/src/Tsl2561Util.cpp b/lib/Joba_Tsl2561-2.0.10/src/Tsl2561Util.cpp similarity index 83% rename from lib/Joba_Tsl2561-2.0.7/src/Tsl2561Util.cpp rename to lib/Joba_Tsl2561-2.0.10/src/Tsl2561Util.cpp index ae811f743..aa738bb9f 100644 --- a/lib/Joba_Tsl2561-2.0.7/src/Tsl2561Util.cpp +++ b/lib/Joba_Tsl2561-2.0.10/src/Tsl2561Util.cpp @@ -22,9 +22,10 @@ This file is part of the Joba_Tsl2561 Library. namespace Tsl2561Util { // Tsl2561Util::normalizedLuminosity returncode false can mean: -// - saturation: full and/or ir have value ~0 (aka -1) +// - saturation: full and/or ir have value ~0 (aka -1) and not shortest exposure // - manual exposure time: full and ir are corrected only for gain -// If true, full and ir have values as if exposure was 402 and gain 16. +// If true, full and ir have values as if exposure was 402 and gain 16 +// or ~0 if saturated even at shortest exposure bool normalizedLuminosity( bool gain, Tsl2561::exposure_t exposure, uint32_t &full, uint32_t &ir ) { uint16_t scaledFull = (uint16_t)full; @@ -39,8 +40,8 @@ bool normalizedLuminosity( bool gain, Tsl2561::exposure_t exposure, uint32_t &fu switch( exposure ) { case Tsl2561::EXP_14: - full = (scaledFull >= 5047/4*3) ? 0xffffffff : ((full + 5) * 322) / 11; - ir = (scaledIr >= 5047/4*3) ? 0xffffffff : ((ir + 5) * 322) / 11; + full = (scaledFull == 5047) ? 0xffffffff : ((full + 5) * 322) / 11; + ir = (scaledIr == 5047) ? 0xffffffff : ((ir + 5) * 322) / 11; break; case Tsl2561::EXP_101: full = (scaledFull >= 37177/4*3) ? 0xffffffff : ((full + 40) * 322) / 81; @@ -54,7 +55,7 @@ bool normalizedLuminosity( bool gain, Tsl2561::exposure_t exposure, uint32_t &fu return false; } - return full != 0xffffffff && ir != 0xffffffff; + return exposure == Tsl2561::EXP_14 || (full != 0xffffffff && ir != 0xffffffff); } return false; @@ -93,6 +94,8 @@ bool autoGain( Tsl2561 &tsl, bool &gain, Tsl2561::exposure_t &exposure, uint16_t { true, Tsl2561::EXP_402 } // max }; + // Serial.printf("autoGain start: gain=%u, expo=%u\n", gain, exposure); + // get current sensitivity if( !tsl.getSensitivity(gain, exposure) ) { return false; // I2C error @@ -110,9 +113,10 @@ bool autoGain( Tsl2561 &tsl, bool &gain, Tsl2561::exposure_t &exposure, uint16_t return false; // should not happen... } - // in a loop wait for next sample, get values and adjust sensitivity if needed + // sometimes sensor reports high brightness although it is darker. uint8_t retryOnSaturated = 10; + // in a loop wait for next sample, get values and adjust sensitivity if needed while( true ) { waitNext(exposure); @@ -122,11 +126,14 @@ bool autoGain( Tsl2561 &tsl, bool &gain, Tsl2561::exposure_t &exposure, uint16_t uint16_t limit = getLimit(exposure); if( full >= 1000 && full <= limit ) { - return true; // new value within limits + // Serial.printf("autoGain normal full=%u, limits=1000-%u, curr=%u\n", full, limit, curr); + return true; // new value within limits of good accuracy } + // adjust sensitivity, if possible if( (full < 1000 && ++curr < sizeof(sensitivity)/sizeof(sensitivity[0])) || (full > limit && curr-- > 0) ) { + // Serial.printf("autoGain adjust full=%u, limits=1000-%u, curr=%u\n", full, limit, curr); if( !tsl.setSensitivity(sensitivity[curr].gain, sensitivity[curr].exposure) ) { return false; // I2C error } @@ -134,7 +141,10 @@ bool autoGain( Tsl2561 &tsl, bool &gain, Tsl2561::exposure_t &exposure, uint16_t exposure = sensitivity[curr].exposure; } else { - if( ++curr > 0 && retryOnSaturated-- == 0 ) { + // sensitivity already is at minimum or maximum + if( ++curr > 0 || retryOnSaturated-- == 0 ) { + // Serial.printf("autoGain limit full=%u, ir=%u, limits=1000-%u, curr=%u, retry=%u\n", full, ir, limit, curr, retryOnSaturated); + // dark, or repeatedly confirmed high brightness return true; // saturated, but best we can do } } @@ -176,6 +186,11 @@ bool milliLux( uint32_t full, uint32_t ir, uint32_t &mLux, bool csType, uint8_t return true; } + if( full == 0xffffffff || ir == 0xffffffff ) { + mLux = 99999999; // indicates saturation at shortest exposure + return true; + } + uint32_t milliRatio = ir * 1000 / full; if( csType ) { diff --git a/lib/Joba_Tsl2561-2.0.7/src/Tsl2561Util.h b/lib/Joba_Tsl2561-2.0.10/src/Tsl2561Util.h similarity index 100% rename from lib/Joba_Tsl2561-2.0.7/src/Tsl2561Util.h rename to lib/Joba_Tsl2561-2.0.10/src/Tsl2561Util.h