BH1750 hang with DS3231

Hi guys, help me please!

I use two module with Arduino Due: - RTC DS3231 - Light sensor BH1750

Libraries: - BH1750FVI for light sensor - For clock, I took example code here http://www.glacialwanderer.com/hobbyrobotics/?p=12

My sketch here: http://pastebin.com/EPRkUiYk

Watching the following problem: When the light sensor in the shade - shows the correct data. If the light sensor is placed under the sun's rays - returns 54612 lux. Then I remove the light sensor back into the shadows, and expect that the data will be less than 54612 lux, but it does not happen. The sensor always returns 54612 lux.

I found that if you comment out the lines:

Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.endTransmission();

problems with hanging data will no longer. But RTC sends me this a time:

Lux: 718, Time: 0:20:0 20/19/3 28 Lux: 2152, Time: 16:6:1 0/0/0 0 Lux: 54612, Time: 0:0:0 88/0/20 22 Lux: 54612, Time: 20:31:0 3/1/6 19 Lux: 54612, Time: 0:0:16 0/0/0 0 Lux: 384, Time: 8:22:0 20/80/33 0 Lux: 332, Time: 3:19:20 6/16/0 1 Lux: 668, Time: 0:0:0 0/0/22 0 Lux: 911, Time: 20:0:8 36/20/19 80 Lux: 20715, Time: 6:1:3 0/0/0 16

Tell me, how can I fix this problem?

You can't remove lines at random and expect things to work. You just broke the sequence for reading the RTC. Put it back and look elsewhere for the problem.

If your code is too long to post here, add it as an attachment. Not too many people are willing to visit wastebin.com

Ok, thanks. I returned the code back. Maybe the problem is BH1750 library? :frowning:

With both devices connected, have you run the I2C scanner sketch, to see if both devices are being found? That is the FIRST thing to do when using more than one I2C device.

PaulS: With both devices connected, have you run the I2C scanner sketch, to see if both devices are being found? That is the FIRST thing to do when using more than one I2C device.

Thanks, but the scanner detects both devices. No problem if the light level is not greater than 54612 lux.

No problem if the light level is not greater than 54612 lux.

A piece of duct tape would assure that that was always the case. 8)

I'd look at your code, but you put it in the rubbish bin, and I'm not fishing it out. If you want help HERE, post your code HERE.

PaulS:
I’d look at your code, but you put it in the rubbish bin, and I’m not fishing it out. If you want help HERE, post your code HERE.

Ok, this is my sketch:

#include <Wire.h>
#include <BH1750FVI.h>
 
#define DS1307_I2C_ADDRESS 0x68
 
BH1750FVI LIGHT_SENSOR;
 
byte date_second,
date_minute,
date_hour,
date_dayOfWeek,
date_dayOfMonth,
date_month,
date_year;
 
byte bin2dec(byte val)
{
  return byte( (val/16*10) + (val%16) );
}
 
void date_get()
{
  // Reset the register pointer
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.write(0);
  Wire.endTransmission();
 
  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
 
  // A few of these need masks because certain bits are control bits
  date_second     = bin2dec(Wire.read() & 0x7f);
  date_minute     = bin2dec(Wire.read());
  date_hour       = bin2dec(Wire.read() & 0x3f);  // Need to change this if 12 hour am/pm
  date_dayOfWeek  = bin2dec(Wire.read());
  date_dayOfMonth = bin2dec(Wire.read());
  date_month      = bin2dec(Wire.read());
  date_year       = bin2dec(Wire.read());
}
 
void setup() {
  Serial.begin(9600);
  Wire.begin();
 
  LIGHT_SENSOR.begin();
  LIGHT_SENSOR.SetAddress(Device_Address_L);
  LIGHT_SENSOR.SetMode(Continuous_H_resolution_Mode);
}
 
void loop() {
 
  date_get();
 
  uint16_t light_sensor_current_value = LIGHT_SENSOR.GetLightIntensity();
 
  Serial.print("Lux: ");
  Serial.print(light_sensor_current_value);
  Serial.print(", Time: ");
 
  String datetime = "";
  datetime += (int)date_hour;
  datetime += ":";
  datetime += (int)date_minute;
  datetime += ":";
  datetime += (int)date_second;
  datetime += " ";
  datetime +=(int)date_dayOfMonth;
  datetime += "/";
  datetime += (int)date_month;
  datetime += "/";
  datetime += (int)date_year;
  datetime += " ";
  datetime += (int)date_dayOfWeek;
 
  Serial.println(datetime);
 
  delay(1000);
}
  String datetime = "";
  datetime += (int)date_hour;
  datetime += ":";
  datetime += (int)date_minute;
  datetime += ":";
  datetime += (int)date_second;
  datetime += " ";
  datetime +=(int)date_dayOfMonth;
  datetime += "/";
  datetime += (int)date_month;
  datetime += "/";
  datetime += (int)date_year;
  datetime += " ";
  datetime += (int)date_dayOfWeek;

  Serial.println(datetime);

What a f**king waste of effort and resources.