droid41 / NodeMCU

Sketches for NodeMCU using ArduinoIDE
0 stars 0 forks source link

No Wire.beginTransmission() and no Wire.endTransmission() needed for Wire.requestFrom(). #1

Closed Koepel closed 6 years ago

Koepel commented 6 years ago

The Wire.beginTransmission() and Wire.endTransmission() are only used when writing data.

In the files: "NodeMCU/NodeMCU-WIFIClient--GY30/NodeMCU-WIFIClient--GY30.ino" "NodeMCU/NodeMCU-WIFI-HTTPServer-GY30/NodeMCU-WIFI-HTTPServer-GY30.ino" "NodeMCU/NodeMCU-WIFIClient--GY30-influxdb/NodeMCU-WIFIClient--GY30-influxdb.ino" in the function "BH1750_Read", the Wire.beginTransmission() and Wire.endTransmission() can be removed.

The BH1750 does not have selectable registers inside. Only two bytes can be read from it. Because of that, you could make one function of "BH1750_Read()" and "BH1750_ReadLX()".

In the function BH1750_ReadLX(), a byte is shifted 8 bits to the left. That is not nice programming.

droid41 commented 6 years ago

Thank you for your comment!

The parts of the sketches that are reading the values from the sensors are mostly copied from tutorials like https://arduino-hannover.de/2014/05/19/mein-paket-ein-bh1750fvi-lichtintensitaetssensormodul-gy-30-das-luxmeter/, you will find a lot of places where identical (incorrect) code is used.

But of course you are right. I will fix this - maybe I should just use the library I found and get rid of the internal workings of ready the sensor: https://github.com/claws/BH1750

Koepel commented 6 years ago

I have added comment at arduino-hannover.de . However, I don't know if it will be published because: "Dein Kommentar wartet auf Freischaltung".

The claws version uses the Wire library in the right way but does not get the maximum data from the sensor. The sensor can actually measure 0.11 lux to about 100k or 120k lux. I tried a test: https://gist.github.com/Koepel/b70f81c71a52d8d6d3da86b9fe56d50e but have not added auto-ranging yet and it is not a library.

droid41 commented 6 years ago

I have cleaned up the sketches and created another issue for using extended range. Currently I am fine with the "normal" range, but as soon as I deploy the sensor in a greenhouse the extended range would be nice.

Thank you for your suggestions.