I'm working on a project combining a DS3231 RTC, 1.3" OLED, and a BME280 sensor.
The BME280 sensor displays correctly on the OLED without any issues.
The time from the DS3231 skips a second every 10 seconds, but makes up for it in the next 10 seconds. I haven't been able to figure out why this is happening.
I have also tried this configuration with an SPI connected 1.3" OLED without any second skipping, but I prefer to run the screen on I2C if possible.
Can anyone give me some insight as to why this may be happening?
combined.ino (2.69 KB)
I think it's due to using delay(1000) as the metronome for your loop. The code takes some time to execute and then you add 1 second onto that time, so each loop is a little longer than a second. It's better to use millis(), maybe something like this:
unsigned long ms, newMs;
void setup()
{
ms = millis();
}
void loop()
{
// do your stuff
while ((newMs=millis()) - ms) < 1000) {}
ms = newMs;
}
Also, you don't need to get the compensation values and configure the device repeatedly in loop(). Reconfiguring each time might even cause the filter to reset, although I'm not sure about that. In any case, it makes sense to move that code to setup().
How do like the BME280?
edit:
I see there's a breakout board available for this chip. Very nice. I wish I'd discovered that before hand soldering BMP280 chips onto a couple of surface mount proto boards.
Thank you so much for your help jboyton!
For the compensation values, that was a good catch, I am too much of a novice to have noticed that. I moved that bit of code into the (setup) and that part works good.
As for the (millis) code that you gave me, that worked great (except for an extra ( typo, no worries), but the screen is now updating i would guess every 250ms it seems. I doubt this will be a problem as most of the time the unit will be in deep sleep unless I trigger an external interrupt to wake it up for 10 seconds.
The BME280 works better then I could ever anticipate. I was using BMP180's in my projects before, and they were very reliable as well. I do have to say I was astonished that the physical size of the IC is half of the BMP180. Right now with the new millis code, the humidity is extremely responsive to my breath, and touching a finger to the metal can makes the temperature readout to respond faster then any thermocouple would.
I still have to get the code integrated for an AS3935 Lightning detector into this combined code, and take a closer look at the rtc code. For some reason the hour never advances, and it's stuck in 20-29 minutes then just recycles.
combined.ino (2.8 KB)
njsharkracer:
As for the (millis) code that you gave me, that worked great (except for an extra ( typo, no worries), but the screen is now updating i would guess every 250ms it seems.
That's weird. It should be once per second.
Those little sensors are quite nice. When I was preparing to solder the BMP280 (which is slightly smaller than the BME) I was terrified that I'd sneeze and never see it again. It seemed like a shame to have such a large proto board dedicated to the tiny thing.
I'm finding the BMP280 easier to use than the 180. I read the BMP180 10 times per second, average those readings, and then do a 5 second moving average on top of that. With the 280 I read it once per second (configured like you have) and the trace looks as good, if not better, as the 180 with all the extra averaging.