GithubHelp home page GithubHelp logo

Comments (5)

bjarnebuchmann avatar bjarnebuchmann commented on July 16, 2024

The readLightLevel function also returns an inconsistent number right after switching between the two CONTINUOUS HIGH_RES modes, as there are no delay (to allow a new measurement) in configure(). In this case, the return 2-byte measurement value is based on the previous-mode measurement, but the interpretation (int 2 float) in readLightLevel is based on the new mode.

Example code:

BH1750 lightMeter((byte) 0x5C);
void setup() {
...
  lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE);
  lightMeter.configure(BH1750::CONTINUOUS_HIGH_RES_MODE);
  lightMeter.setMTreg(BH1750_DEFAULT_MTREG );
  delay(180);
  plotlight();
  lightMeter.configure(BH1750::CONTINUOUS_HIGH_RES_MODE_2);
  plotlight();
  delay(180);
  plotlight();
}

void plotlight(){
  Serial.print(millis());
  Serial.print(" Light: ");
  Serial.print(lightMeter.readLightLevel());
  Serial.println(" lx");
}

Result (@~800lx light) - my comments after the hash marks

1536 Light: 800.00 lx # Correct HRES_MODE measurement
1547 Light: 400.00 lx # False. HRES_MODE interpreted as HRES_MODE_2
1728 Light: 799.17 lx # Correct HRES_MODE_2 measurement

Maybe configure() should add a delay also for CONTINUOUS modes (and not just for ONE_TIME modes)?

/Bjarne

from bh1750.

claws avatar claws commented on July 16, 2024

I'm happy to receive pull requests if you would like to propose a fix? With so many other things on the go it's hard for me to find the time.

from bh1750.

bjarnebuchmann avatar bjarnebuchmann commented on July 16, 2024

I understand.
Unfortunately, I do not presently have a git pull (nor a way to actually expose that to you).

In order to do this "right" I would suggest to keep a "reset_time" with the object, so that a new/updated measurement can be taken only whenever the module is ready to deliver it. This would impact the delay() (or _delay_ms) in setMTreg() and readLightLevel(). The advantage would be that "hard" delays would not be necessary, ie the module/code could be non-blocking.
In addition, it might be an advantage to store the latest (read and compute) light measurement (as a float), so that could be returned until a new measurement is ready and could be read.

I would not actually implement changes on this magnitude without consulting with the original author (you) in order to assert that it is a way, which you would approve for the module.

from bh1750.

coelner avatar coelner commented on July 16, 2024
  1. Maybe we could do this like the BSEC library from bosch where they return a timestamp where the next measurement is ready. (It is somehow a little bit different from our case, because the bosch sensors contains a microcontroller, whereas we do not have this)
  • store the millis() timestamp in the library instance -OR-
  • return this value to the user for further processing -OR-
  • boolean for the status 'new value possible' ?
  1. an internal storage for the last value is not straight forward, as the sensor can deliver it. I think the user should be aware of holding the right value, as the user needs to set this specific value into a context. If we would use a thread based concept, I would understand that

from bh1750.

coelner avatar coelner commented on July 16, 2024

a call of setMTReg should touch lastReadTimestamp because of the direct mode I2C call:

__wire_write(BH1750_MODE);

But maybe I missed something?

from bh1750.

Related Issues (20)

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.