dantudose / max44009 Goto Github PK
View Code? Open in Web Editor NEWArduino library for the MAX44009 luxmeter chip
License: GNU General Public License v3.0
Arduino library for the MAX44009 luxmeter chip
License: GNU General Public License v3.0
In MAX44009.cpp It appears that the exponent is being applied to the value 1 (x00000001). The data sheet says it should be applied to value 2 which would be (x00000010).
Changing it to 2 results in a much wider range of lux values being returned.
Steve Rimbey
Hi,
There has already been an issue concerning the configuration of the MAX44009 in the begin() method. This issue was solved (you changed the manual integration time of 800ms to auto mode). However, it looks like the reading method get_lux() is still not 100% correct.
Wire.beginTransmission(MAX_ADDR);
Wire.write(0x03); //here you request data from 0x03 (the Lux High-Byte Register)
Wire.endTransmission();
// You request two bytes of data (the register will only hold one byte)
Wire.requestFrom(MAX_ADDR, 2);
// and read this same byte into two variables
if (Wire.available() == 2)
{
data[0] = Wire.read();
data[1] = Wire.read();
}
According to the datasheet (Source), Register 0x03 contains the four bits of the exponent followed by the four most significant bits of the mantisa.
If you only want to use this data, the formula for lux calculation should be:
Lux = 2^(exponent) x mantissa x 0.72
The code would look like this:
float MAX44009::get_lux(void)
{
unsigned int data;
Wire.beginTransmission(MAX_ADDR);
Wire.write(0x03);
Wire.endTransmission();
// Request 1 byte of data
Wire.requestFrom(MAX_ADDR, 1);
// Read 1 byte of data
if (Wire.available() == 1)
{
data = Wire.read();
}
// Convert the data to lux
int exponent = (data & 0xF0) >> 4;
int mantissa = (data & 0x0F) << 4);
float luminance = pow(2, exponent) * mantissa * 0.72;
return luminance;
}
If you now want to achieve more precision, you can also read Register 0x04 (the Lux Low-Byte Register). This one contains the four least significant bits of the mantissa. If you put those two together, you can use the already implemented formula. The code could look similar to this:
float MAX44009::get_lux(void)
{
unsigned int data[2];
Wire.beginTransmission(MAX_ADDR);
Wire.write(0x03); //request high-byte register data
Wire.endTransmission();
// Request 1 byte of data
Wire.requestFrom(MAX_ADDR, 1);
// Read first byte of data
if (Wire.available() == 1)
{
data[0] = Wire.read();
}
Wire.beginTransmission(MAX_ADDR);
Wire.write(0x04); //request low-byte register data
Wire.endTransmission();
// Request 1 byte of data
Wire.requestFrom(MAX_ADDR, 1);
// Read second byte of data
if (Wire.available() == 1)
{
data[1] = Wire.read();
}
// Convert the data to lux
int exponent = (data & 0xF0) >> 4;
int mantissa = ((data[0] & 0x0F) << 4) | (data[1] & 0x0F);
float luminance = pow(2, exponent) * mantissa * 0.045;
return luminance;
}
I hope there are no mistakes in my sample code but I think this sould be the right way according to the datasheet.
Hi,
I got this sensor from Aliexpress, but the maximum reading I can get on your library is 2937.60 lux, even though I am pointing a flashlight directly on the sensor. The same issue is happening on other libraries. The datasheet of this sensor says it can read up to 180k lux. Do you know why I can get only 2937lux read?
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.