Coder Social home page Coder Social logo

max44009's People

Contributors

dantudose avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

max44009's Issues

Lux calculation

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

Reading method is probably incorrect according to datasheet.

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.

Maximum reading is 2937.60 lux

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.