by Static on Sun Feb 03, 2013 10:38 pm

I'm gonna bet that fixes it for you. I did get some spurious values (Decreases in values when I think they should have increased), but they may have to do with the pauses between the readings (Ambient versus IR). I'm not looking for fast response, so I didn't delve into it too much.
Static
 
Posts: 178
Joined: Thu Dec 23, 2010 5:21 pm

by scortier on Mon Feb 11, 2013 10:45 am

I have now tried the code and it works in a sense that I don't get anymore zeros. But when I place a lux meter right beside the sensors, I'm not getting the same values. I am shining a very bright LED that should be reading in the tens of thousands of lux on the sensor and the output is reading 1171 lux. In only ambient light, the sensors read about 120 lux while the meter reads about 300.
scortier
 
Posts: 13
Joined: Mon Jan 14, 2013 1:47 pm

by Static on Fri Feb 15, 2013 9:57 pm

I've got some aberrant values as well. The system works for what I'm doing, but it's not precise. I need to get some additional test gear to check the measurements.
Static
 
Posts: 178
Joined: Thu Dec 23, 2010 5:21 pm

by Static on Sat Feb 16, 2013 10:14 am

A quick update, in case anyone has any ideas:

I just did a datalog, every second or so, for about 30,000 records. With the TSL2561 and the code above I'm getting strange results. I'd say more than 99% of the time I'm getting consistent results, but I am getting strange spikes (to zero and to high values) that I can't explain.
I'm measuring the light outside of my window. Last night (very dark) it's very consistent, with no spikes. However, as more light falls on the sensor, there are more spikes. Also, it looks like there are periods where the light drops to moderate levels, with occasional spikes to the expected levels.

I'm going to work on building a new sensor pod for monitoring in the house with a very consistent light source. I'll post up with any findings.
Static
 
Posts: 178
Joined: Thu Dec 23, 2010 5:21 pm

by scortier on Fri Feb 22, 2013 2:36 pm

Any progress? I have been testing as well but with four sensors at a time. I continually run them to see if I can get consistent results and am getting the odd zero, but not sure how to fix this - might just be a random small glitch. I still haven't found out why I'm getting about 100 lux in a room that's supposed to be 400-500 lux.

Accuracy is important for a school project I'm working on so I'm testing with an accurate lux meter. I'll keep posting.
scortier
 
Posts: 13
Joined: Mon Jan 14, 2013 1:47 pm

by Static on Sat Feb 23, 2013 10:44 am

I spent the morning working on getting both I2C buses running at the same time (I know, not important for what you're looking at ). However, it is going to let me look at this problem while dealing with some of my own problems.
I'll try to get everything set up tonight to run a sensor pod in my office and log information regarding all of the inputs (the data from the two light sensors and the ratio the system decides to assign in order to calculate the values).
Static
 
Posts: 178
Joined: Thu Dec 23, 2010 5:21 pm

by scortier on Sat Feb 23, 2013 3:15 pm

If you are using the last code you had previously posted, there is a slight error in the calculation:
elif (ratio <= 0.80):
lux = (0.0157 * ambient) - (0.018 + IR)

Should be 0.018 * IR

And if you are using Python 2 (I have to), I had to change how ratio was calculated:
From ratio = (float) (IR / ambient)
To ratio = IR/ (float) ambient

I tested what the sensors were grabbing for values and did the math (ratio and lux value) manually with a calculator, and it gives the expected value compared to print(lux). At this point, I'm a little weary of the set up of the device - if parameters such as the gain and conversion time are set up correctly. I am also unsure of why we have to reverse the byte order of what is read on a channel, but I haven't looked into that on the Datasheet yet.
scortier
 
Posts: 13
Joined: Mon Jan 14, 2013 1:47 pm

by Static on Sun Feb 24, 2013 12:44 am

How did I miss that?

I'm going to run 24 hours of code, and see how it looks. I'm having an issue with my second data bus. It's an inconsistent error, so I'm having trouble figuring out where the issue is. I'm going to try to run the code fix that you provided and generate a test run. I can compare that against the previous data.
Static
 
Posts: 178
Joined: Thu Dec 23, 2010 5:21 pm

by Static on Mon Feb 25, 2013 1:00 am

Amigo, I forgot to check the data before I left for work tonight. I'll check when I get home (around 0830 East Coast) and post up about how consistent the data looks.

Sorry about that.
Static
 
Posts: 178
Joined: Thu Dec 23, 2010 5:21 pm

by scortier on Mon Feb 25, 2013 9:43 am

That's okay. I look forward to hearing about your results, though.

I'm beginning to wonder if this sensor is even fit for measuring light in our applications. I mean... it's not like we're actually measuring the ambient light directly through the calculation. It's an approximation based on two channels that capture IR and one of these channels has a filter that blocks visible light. As well, the data sheet has a parameter on page 4: (Sensor Lux) / (actual Lux) being about 0.6 - 1.4.
scortier
 
Posts: 13
Joined: Mon Jan 14, 2013 1:47 pm

by Static on Mon Feb 25, 2013 9:49 am

I don't have a good answer for that. I'm not completely sure what you are doing.

I was hoping to use this sensor in multiple roles. I'm partially interested in graphing the light versus temperature. I'd be really interested in using the sensor as a light sensitive trigger in an alarm system.

I just graphed 1900 records. When the light is low, it stays low. However, as the light creeps up (which it seems to do pretty quickly), it gets min/max spikes through-out the period where it is measuring significant light (more than ~450).
It would partially work for my alarm system. If someone lights a flashlight up in my house while the system is acting, it will reliably detect the spike. If someone walks across the sensor casting a shadow on it, the signal will be lost in the noise.
Static
 
Posts: 178
Joined: Thu Dec 23, 2010 5:21 pm

by scortier on Mon Feb 25, 2013 1:58 pm

Okay, good to hear the sensor is working for your application in setting off alarms. So you are getting ~400 lux for broad daylight? Have you tried the sensor for regular room lighting? I assume you are not looking in particular for accurate values?

My application is using the sensor to output accurate lux values according to a bright LED being shone on the sensor. That is the simple version. My more in-depth application involves using ten sensors to grab values and graph the output as a contour map. But getting one sensor to output accurate lux values is the issue in my case.

I am only getting ~100 lux in a lit room when it should really be 400 lux.
scortier
 
Posts: 13
Joined: Mon Jan 14, 2013 1:47 pm

by scortier on Tue Feb 26, 2013 11:13 am

I seem to be getting closer values now that I have set register 0x81 to value 0x1A instead of 0x11, thus making the integration time 402ms and the gain 16x. Now it's about 100 lux off the real value (I'm reading 450 lux when my lux meter says ~550 lux).
scortier
 
Posts: 13
Joined: Mon Jan 14, 2013 1:47 pm

by csalty on Wed Feb 27, 2013 12:03 pm

I wanted to say thanks for your efforts on getting the python code for this sensor. I've been using your code for the past week or so with great results. I've made a few mods to the code so that I can send my data to COSM; added a data buffer for each IR, ambient, and lux readings; and a few other misc. tweaks. I also noted the calculation error. Again thanks!

- CSalty
csalty
 
Posts: 27
Joined: Sat Feb 23, 2013 7:32 pm

by Static on Thu Feb 28, 2013 7:52 am

PLEASE if you found some good mods, share 'em. This is definitely a team effort. I'm an amateur, so seeing other people's work is always adding to my techniques.

scortier, what time interval are you polling your sensors? I'm going to code up and wire up a test on the sensor. I want to match the polling interval to yours so that I can easily compare data.
Static
 
Posts: 178
Joined: Thu Dec 23, 2010 5:21 pm