Connected sensors freeze

I am new to Arduino programming and have implemented a project to monitor my bee hive. Connected to an IOT Octopus are via I2C a qwiic scale (with 4 load cells attached to it), an external BME680 sensor to go inside the bee hive, and an scd30 sensor to measure the environment temperatur+humidity+CO2.
The values are collected every 30 minutes and sent via LoraWan to TTN. Everything works fine for several days but then suddenly after some random time all the sensors on I2C somehow stop working and always the same unchanged values are transmitted via LoraWAN. The program is still running and sending values every 30 min, its just that it is not measuring the values anymore and just sending the same ones over and over (even though they have changed in reality). After about 20 h in this state with unchanged values sent the IOT Octopus suddenly restarts by itself and then everything is working again.
Can anyone explain and help me fix it?

A link to your IOT Octopus might have helped, I guess it's not Googles first hit.

Sounds like a software problem, usually a memory problem. As you failed to post your code we're unable to help you any further.

I have written the code in Ardublocks so its generated automatically. I am adding it here (sorry most texts and variables are in German):

And this is the link to the IOT Octopus:
I was also thinking about whether it is a memory problem or some I2C problem because only the I2C sensors stopped working correctly. The rain sensor on A0 continued to send correct values and the LoraWAN connection also continued working. Any ideas?

I don't trust the proprietary Bosch library. It's always a bad idea to use precompiled libraries in an open source environment. Any update of the environment and the binary interface may have changed slightly.

Endless loops are a bad idea in such projects:

      for (;;) {
      } // Halt in case of failure 


    while(1) {

You shouldn't increase the I2C clock speed if you use wires (not PCB only traces):

  Wire.setClock(400000); // ---- Qwiic Scale is capable of running at 400kHZ if desired  

How long are you wires? Keep them as short as ever possible.

Thanks a lot for looking through the code. I understand why you say the endless loops that come with the Bosch BME680 Ardublock blocks are a bad idea. But as they are only called once during the setup() they can't be responsible for the issues that I am seeing. Is that correct?

Could the too fast wire clock speed be causing the problems? I just read through the code again and noticed that in the setup() method setClock() is called twice. Once at the beginning with 400000 (generated by the Qwiic scale block) and once at the end (generated by the SCD30 block) with
Wire.setClock(100000L); // 100 kHz SCD30
Wire.setClockStretchLimit(200000L);// CO2-SCD30
So is the clock speed not 100000 anyhow?
If not what should I set the I2C clock speed to? 100000 or even lower? Or should I just remove that command from the code so it uses the default speed?

The SCD30 and the Qwiic Scale are connected via an I2C hub with very short wires (approx. 10 centimeters). The Qwiic scale then has an about 2 meter long wire to the actual load cells but I assume that they are not communicating via I2C, so that should not affect the I2C bus.
The one BME680 that I use for pressure is on board of the IOT Octopus, so no wires at all. The other BME680 is inside the bee hive and also connected to the I2C hub. The wire length is about 2 meters. I am using a shielded CAT7 cable for the connection. Is there anything I can improve?

Yes, that's correct.

Yes, the higher the bus speed, the shorter the bus wires must be to work correctly (bus capacitance).

Yes, I didn't noticed the second call.

Do you have a link to that I2C hub? Is that just a passive PCB or does it contain components?

Can you post the complete serial output of such a session? What exact values do you get once the sensors stop working correctly?

The I2C hub is just passive. Here is the link: seeed Grove - 4 Port I2C Hub kaufen bei BerryBase

I can't paste the complete serial out as its currently at the bee hive with no serial connected to it. The issue never happened while I had serial connected. It ususally takes several days till it happens and I notice when looking at the values in Thingspeak.
The values that it sends once it freezes and that I can see on TTN/Thingspeak are the last values that it measured correctly. So it just keeps the last values and doesn't update them anymore. So all the temperatures, the pressure, the iaq and the humidity are frozen to last correctly measured values (no change anymore even when at night the temperatures drop). The only value that is different from the last "correct" value is the weight from the qwiic scale. Instead of the last measured approx 44.5 kg it starts sending -27.579.
And as mentioned before the only value thats still updated once the other sensors freeze is the value from the rain sensor on A0. So its only related to the I2C sensors.

Have you tried to reset the ESP once the scale returns negative values?

I usually just restarted (removed the power and connected it again) and then everything worked fine again.

I mean automatically reset it. I want to know if a simple reset does bring it to a working state again.


should do the job, just call it if the scale returns negative values. This might work if the reason is in the ESP's firmware. If the bus is blocked by one of the sensors it won't work.

Thanks for the tip! I will definatly try it after the next time it freezes. I will update the code now and put the updated code on the IOT Octopus after I see the next freeze of the I2C bus. I will report here if it works, but it will typically take several days till it comes to that point.

now I am seeing a new but similar problem. Today only the BME680 that is inside the bee hive froze and startet sending the always same values. So my check for negative weight values didn't detect the problem and therefore didn't call the reset. All other sensors continued working properly also the other ones on I2C. But the new problem shows that it is specific to either the i2c bus or the BME680 sensor or the wiring of this sensor. Any ideas what I could do to find the root cause and solve it?

Can you post a picture of your setup?

I don't trust this BOSCH library. Do you need any special functionality it provides?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.