-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
H res mode2 #46
H res mode2 #46
Conversation
Hi, I've finally had some time to look into this project again. I have some questions about this merge request. I began by installing the updated BH1750 library into my Arduino environment and then compiled and ran the simplest example, examples/BH1750test.ino. This seemed to work and I assumed was returning a int32_t even though the example creates a I then attempted to test the new float functionality by uncommented the pre-processor section at the top of the example script. This should remove the readLightLevel function that returns a int32_t and replace it with a readLightLevel function that returns a float. I observed compilation errors. It appears that the pre-processor flags are not quite working as expected. Compiling /path/to/BH1750/examples/BH1750test/BH1750test.ino
/var/folders/_y/fb30sc1x5l54n3cymwws4rdc0000gn/T//ccIyCBjg.ltrans0.ltrans.o: In function `loop':
/path/to/BH1750/examples/BH1750test/BH1750test.ino:51: undefined reference to `BH1750::readLightLevel(bool)'
collect2: error: ld returned 1 exit status
exit status 1 With regard to the implementation proposed, I observe you have added the function to return a float and the needed internals to support that. In addition to that you have added another function which returns an integer value. The library now appears to return either an int32_t or a float. To switch between the alternative return types you have wrapped the function implementations with the pre-processor BH1750_FLOAT flag. What is the reason for adding the integer functionality? Why not just the float function and remove all the complexity of the pre-processor code? Alternatively, if there is a real need for the integer function why not provide it as an explicit public function name and discard the pre-processor checks. Then leave it to a user to decide which functionality they want. Personally I think just having the float function is sufficient. When I attempt to compile the new example script that demonstrates adjusting the measurement time I observe compile errors. I see the same when I use the simple compilation check script (build-examples.bash). $ ARDUINO_IDE_PATH=/Applications/Arduino.app/Contents/Java ./build-examples.bash
Compiling /path/to/BH1750/examples/BH1750advanced/BH1750advanced.ino
Sketch uses 5844 bytes (18%) of program storage space. Maximum is 32256 bytes.
Global variables use 427 bytes (20%) of dynamic memory, leaving 1621 bytes for local variables. Maximum is 2048 bytes.
Compiling /path/to/BH1750/examples/BH1750onetime/BH1750onetime.ino
Sketch uses 5812 bytes (18%) of program storage space. Maximum is 32256 bytes.
Global variables use 427 bytes (20%) of dynamic memory, leaving 1621 bytes for local variables. Maximum is 2048 bytes.
Compiling /path/to/BH1750/examples/BH1750test/BH1750test.ino
Sketch uses 5810 bytes (18%) of program storage space. Maximum is 32256 bytes.
Global variables use 427 bytes (20%) of dynamic memory, leaving 1621 bytes for local variables. Maximum is 2048 bytes.
Compiling /path/to/BH1750/examples/BH1750autoadjust/BH1750autoadjust.ino
/path/to/BH1750/examples/BH1750autoadjust/BH1750autoadjust.ino: In function 'void setup()':
/path/to/BH1750/examples/BH1750autoadjust/BH1750autoadjust.ino:33:14: error: 'D2' was not declared in this scope
Wire.begin(D2, D1);
^
/path/to/BH1750/examples/BH1750autoadjust/BH1750autoadjust.ino:33:18: error: 'D1' was not declared in this scope
Wire.begin(D2, D1);
^
exit status 1 I think you need to remove the references to the pins similar to the other examples. It looks like this change would also close out #34 and #35 and #51. Is that correct? |
Hi, I had some trouble with my local sync daemon and the git repo. Therefore I need time to get back into this merge request.
|
examples/BH1750test/BH1750test.ino
Outdated
@@ -20,6 +20,11 @@ | |||
|
|||
*/ | |||
|
|||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment block should be removed as it only seems possible to modify the BH1750_FLOAT setting in the BH1750.h
file not in user code.
@@ -10,6 +10,10 @@ | |||
preparation for the next measurement. | |||
|
|||
*/ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment block should be removed as it only seems possible to modify the BH1750_FLOAT setting in the BH1750.h file not in user code.
@@ -23,7 +23,11 @@ | |||
#include <BH1750.h> | |||
|
|||
/* | |||
Remove the following if you want to use float |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment block should be removed as it only seems possible to modify the BH1750_FLOAT setting in the BH1750.h file not in user code.
BH1750.cpp
Outdated
#ifdef BH1750_FLOAT | ||
/** | ||
* Read light level from sensor | ||
* @return Light level in lux (0.0 ~ 54612,5 [121556,85]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are there two return value ranges specified in this comment? Does this comment need to be cleaned up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the value within the square brackets is the maximum value if you change the MTReg value. Otherwise you will get the value within the normal brackets.
Thanks for your updates that add improved functionality and better refine the return values in error conditions. I have some more review comments:
|
Thank you for the hints, unfortunately I haven't finished yet.
|
Should be completed |
README.md
Outdated
|
||
The sensor returns a 16 bit unsigned integer. Therefore the maximum value is limited in general. | ||
The standard conversion between the so called 'counts' to lux is 1/1.2, that means you get a smaller value. | ||
As we use signed integer or float, if an error occurs you will get a negative value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On this line the signed integer reference is no longer needed. In fact you could probably remove the first part and just say "If an error occurs...".
|
||
void loop() { | ||
//we use here the maxWait option due fail save and we want reduced information loss due missing decimal part | ||
float lux = lightMeter.readLightLevel(true, true)/100.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The readLightLevel arguments here don't match the .h definition. There are two args when only one is expected.
Also, it s there a reason for dividing by 100? If so it would be useful for user to see a comment about why it is here.
//reduce time slot - needed in direct sun light | ||
if(lightMeter.setMTreg(32)) { | ||
Serial.println(F("[DEBUG]: MTReg low")); | ||
lux = lightMeter.readLightLevel(true, true)/100.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above.
else { | ||
if(lux > 10.0 && lightMeter.setMTreg(69)) { | ||
Serial.println(F("[DEBUG]: MTReg default")); | ||
lux = lightMeter.readLightLevel(true, true)/100.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above.
//very low light environment | ||
if(lightMeter.setMTreg(254)) { | ||
Serial.println(F("[DEBUG]: MTReg high")); | ||
lux = lightMeter.readLightLevel(true, true)/100.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above.
sorry, I forget the example. The Readme should be clear now, the user should be aware that the sensor return only a unsigned 16 bit integer and therefore the user will get a smaller value. The datasheet announce a higher value which is only available after selecting MTreg. |
Some more review comments, hopefully these are the last ones. I think it is pretty close to being good to go. These comments are all related to the
void loop() {
//we use here the maxWait option due fail save
float lux = lightMeter.readLightLevel(true);
Serial.print(F("Light: "));
Serial.print(lux);
Serial.println(F(" lx"));
if (lux < 0) {
Serial.println(F("[DEBUG]: Error condition detected"));
}
else {
if (lux > 40000.0) {
// reduce measurement time - needed in direct sun light
if (lightMeter.setMTreg(32)) {
Serial.println(F("Setting MTReg to low value for high light environment"));
}
else {
Serial.println(F("Error setting MTReg to default value for normal light environment"));
}
}
else {
if (lux > 10.0) {
// typical light environment
if (lightMeter.setMTreg(69)) {
Serial.println(F("Setting MTReg to default value for normal light environment"));
}
else {
Serial.println(F("Error setting MTReg to default value for normal light environment"));
}
}
else {
if (lux <= 10.0) {
//very low light environment
if (lightMeter.setMTreg(176)) {
Serial.println(F("Setting MTReg to high value for low light environment"));
}
else {
Serial.println(F("Error setting MTReg to high value for low light environment"));
}
}
}
}
}
Serial.println(F("--------------------------------------"));
delay(5000);
} |
|
to sum it up: