adafruit / adafruit_tsl2561 Goto Github PK
View Code? Open in Web Editor NEWUnified sensor driver for Adafruit's TSL2561 breakouts
Unified sensor driver for Adafruit's TSL2561 breakouts
Using Arduino IDE 1.8.4 with Teensyduino 1.39 beta1 (happens with other versions as well). Compiling for Teensy 3.5. When compiling receiving warnings on pgmspace macros being redefined. Example sketch does run no problem even with the warnings.
Recommend changing line 25 in the .cpp file to:
#elif !defined(TEENSYDUINO)
to avoid the unnecessary warnings. There maybe a better way but this worked for me.
Respectfully
Mike
In the fix for #11, c913785#diff-fb32052893c4375234c2bcd52e31e8edR110 if (x & 0xF0 != 0x10) {
was added to ::Init()
This is equivalent to if (x & 1) {
I believe the desired code is to add more parenthesis, e.g. `if ((x & 0xF0) != 0x10) {
I tested with this simple program:
#include<iostream>
using namespace std;
int main() {
for (int x = 0; x < 128; x++) {
bool current = (x & 0xF0 != 0x10);
bool test = ((x & 0xF0) != 0x10);
cout << x << " " << current << " " << test << endl;
}
}
I'm not sure this actually fixes the problem because my TSL2561 (ordered in 2016) returns 0x0A similiar to @beegee-tokyo.
Product is discontinued:
https://www.adafruit.com/product/439
Hi,
I'm updating my TSL2561 library on arduino IDE and notice the many changes and have some questions:
(1) - Is it still possible to get Channel 0 and channel 1 (Full light and IR light) datas instead of getting only the result (global Lux)? If yes, how to do that?
-Edit- I tried to adapt the example like this:
void loop(void)
{
uint16_t broadband, infrared;
/* Get a new sensor event */
sensors_event_t event;
tsl.getEvent(&event);
/* Display the results (light is measured in lux) */
if (event.light)
{
Serial.print(event.light); Serial.print(" lux\t");
tsl.getLuminosity(&broadband, &infrared);
Serial.print(broadband); Serial.print(" full\t");
Serial.print(infrared); Serial.println(" Ir");
}
else
{
/* If event.light = 0 lux the sensor is probably saturated
and no reliable data could be generated! */
Serial.println("Sensor overload");
}
delay(250);
}
Is It a right way? I'm not familiar with this event call. Will getluminosity() results corresponding to the event time? Or will it return before/after measurements?
(2) - How is the events part working? when I set the sensor integration time to 402ms, the event shouldn't comes before at least 402ms, but the results are coming right after the tsl.getEvent(&event); call
(3) - The disable() function that powering off the sensor is call without waiting the sensor event ?
(PS: In cpp enable() / disable() functions shouldn't be after "private" comment ? )
-Edit- OKay, there is a delay in getData function. So isn't it a "real" event work? (with timeout for example?)
(4) - Why is the I2C address set at declaration of the object and not at the begin() call like many other sensors library's? I would like to do some multiple sensors detection by scanning I2C bus and then begin each of them with their own address. But if the declaration already set the address I can't set it in the setup() section.
PS : Sorry for my poor English level.
Hi,
I've tried U8GILB with TSL2561 unified library with Arduino due and oled 0.96". It seems that after the first output ok it is not possible to refresh the screen and the output is ever 65536.
Removing U8GLIB instructions the sketch works well.
May someone help me about this issue ?
Adafruit_TSL2561_Unified::init()
checks the value read from TSL2561_REGISTER_ID
against !(x & 0x0A)
.
This is always true if there is no sensor is attached, because then the returned value is 0xFF.
According to the TSL2561 datasheet, the high 4 bits of TSL2561_REGISTER_ID
should be
0000
0001
0100
0101
So there is always at least two 0's in it. An additional check of the returned value agains 0xFF could detect if there is no sensor attached.
e.g.:
boolean Adafruit_TSL2561_Unified::init()
{
/* Make sure we're actually connected */
uint8_t x = read8(TSL2561_REGISTER_ID);
if (x == 0xFF) {
return false;
}
if (!(x & 0x0A))
{
return false;
}
_tsl2561Initialised = true;
/* Set default integration time and gain */
setIntegrationTime(_tsl2561IntegrationTime);
setGain(_tsl2561Gain);
/* Note: by default, the device is in power down mode on bootup */
disable();
return true;
}
I'm building a room sensor with DHT22, a TSL2561, and an Adafruit PIR sensor (not yet hooked up). These are being plugged into a wemos d1 mini with wifiManager and MQTT libs included.
When I run the simple sensorapi application, unadjusted, I get a reasonable value for the lux reading.
When I run it with my fairly complicated code, I get 65536.
lux: 65536.00
broadband: 65535
infrared: 65535
I added the getLuminosity()
call to see what they were showing. Here's the code that does the reading.
/* Get a new sensor event */
sensors_event_t event;
tsl.getEvent(&event);
tsl.getLuminosity(&broadband, &infrared);
/* Display the results (light is measured in lux) */
if (event.light)
{
Serial.print(event.light);
Serial.print(" lux\t");
Serial.print("broadband:\t");
Serial.print(broadband);
Serial.print("\tinfrared:\t");
Serial.println(infrared);
}
else
{
/* If event.light = 0 lux the sensor is probably saturated
and no reliable data could be generated! */
Serial.println("Sensor overload");
}
delay(250);
At the top of the sketch, I'm loading the following libs:
#include <FS.h> //this needs to be first, or it all crashes and burns...
#include <Wire.h>
#include <Adafruit_Sensor.h> // Adafruit Unified Sensor Driver - https://github.com/adafruit/Adafruit_Sensor
#include <ESP8266WiFi.h> // https://github.com/esp8266/Arduino
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
#include <ESP8266WebServer.h> //Local WebServer used to serve the configuration portal
#include <ArduinoJson.h> //https://github.com/bblanchon/ArduinoJson
#include <PubSubClient.h>
#ifdef ESP32
#include <SPIFFS.h>
#endif
#include <Adafruit_TSL2561_U.h>
#include <DHT.h>
The compile results:
Sketch uses 385052 bytes (36%) of program storage space. Maximum is 1044464 bytes.
Global variables use 33352 bytes (40%) of dynamic memory, leaving 48568 bytes for local variables.
Maximum is 81920 bytes.
It seems to compile just fine. Perhaps there are some conflicts within these libs?
Thanks for any advice,
Chris.
Hi,
there is compatibility issue with Adafruit TSL2561 library on latest ESP32 platform [email protected]. ESP will freeze on boot on TSL2561 setup regardless if sensor is connected. There is no such problem on older [email protected]. Tested on ESP-WROOM-32 and Wemos LoLin32 Lite. Thank you.
Peter
Hi,
I have Adafruit Lux sensor TSL2561 3 pcs and would like to read the light intensity (Lux) simultaneously from them. Can anyone guide for Arduino sketch to perform this task?
Thank you.
B.Bundit
Hello,
I don't know why, but the sensor stops working (i.e. no more event.light == true) after a while.
Here is my sketch: https://gist.github.com/xseignard/2d4e00fd3a762d393606
The sketch still runs, but no more lux measures,
Any idea?
Regards,
Xavier
I just noticed that Adafruit has a second library for using the TSL2561:
https://github.com/adafruit/TSL2561-Arduino-Library
The other library is clearly older (when you look at the commits), but neither library's readme mentions the other library, so I'm not sure which library I should use... The older library was the first Google hit for me, so other people might find that one first, too.
If the older library is no longer being developed, maybe a note should be added to its readme? I think I remember seeing "archived" repositories on GitHub, so that's a possibility, if the older library should no longer be used.
Is the older library deprecated? What are the differences between the libraries, is there some reason why I might want to use the older library instead of this one?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.