arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
21.86k stars 4.75k forks source link

scd30 sensor not recognized when Power Cycle of ESP8266 (Wemos) #15438

Closed solarslurpi closed 2 years ago

solarslurpi commented 2 years ago

PROBLEM DESCRIPTION

scd30 sensor with ESP826 Wemos is not detected on Power cycle. The scd30 sensor is detected and readings are available on restart 1

REQUESTED INFORMATION

Make sure your have performed every step and checked the applicable boxes before submitting your issue. Thank you!

- [ ] If using rules, provide the output of this command: `Backlog Rule1; Rule2; Rule3`:
```lua
  Rules output here:
- [ ] Set `weblog` to 4 and then, when you experience your issue, provide the output of the Console log:
```lua
  Console output here:

TO REPRODUCE

Steps to reproduce the behavior: Power cycle an ESP826 (wemos - not sure that matters).

EXPECTED BEHAVIOUR

A clear and concise description of what you expected to happen. I expected to see CO2 readings.

This is what I did to fix it for me:

void Scd30Detect(void)
{
#ifdef ESP32
  if (!I2cSetDevice(SCD30_ADDRESS)) { return; }
#endif
  scd30.begin();

ie.: Not running I2cSetDevice() if the chipset is 8266. This is not a robust way. However, I take it the scd30 needs more time to get back to Tasmota than Tasmota is giving it...I don't want to introduce a delay. But I do not have enough context in the code to fix timing of loading i2c drivers.

SCREENSHOTS

If applicable, add screenshots to help explain your problem.

ADDITIONAL CONTEXT

Add any other context about the problem here.

(Please, remember to close the issue when the problem has been addressed)

sfromis commented 2 years ago

I've also seen SCD30 not being detected for power-up boot with ESP8266, but only after a restart. Maybe the sensor is slow to boot till ready on the I2C bus. Saw no similar trouble with ESP32.

I'm concerned that the "fix" suggested here is not good, as I suspect that it will work badly in case of the driver being included in a build where no SCD30 sensor is present. Has this been tested?

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it hasn't any activity in last few weeks. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] commented 2 years ago

This issue was automatically closed because of being stale. Feel free to open a new one if you still experience this problem.

arnowelzel commented 2 years ago

I also experience this issue. When power cycle a D1 mini connected to a SCD30 I have to reset the device once to get it recognize the SCD30.

arendst commented 2 years ago

From the datasheet it needs 2 seconds to power up. The current code doesn't allow this.

I'll order one and rewrite the setup code once received.

arendst commented 2 years ago

@arnowelzel could you pls try to change

bool Xsns42(byte function)
{
  if (!I2cEnabled(XI2C_29)) { return false; }

  bool result = false;

  if (FUNC_INIT == function) {
    Scd30Detect();
  }
  else if (scd30Found) {

into

bool scd30InitOnce = false;

bool Xsns42(byte function)
{
  if (!I2cEnabled(XI2C_29)) { return false; }

  bool result = false;

/*
  if (FUNC_INIT == function) {
    Scd30Detect();
  }
*/
  if (!scd30InitOnce && (FUNC_EVERY_SECOND == function) && (TasmotaGlobal.uptime > 2)) {
    scd30InitOnce = true;
    Scd30Detect();
  }
  else if (scd30Found) {

and report back.

arendst commented 2 years ago

@sfromis if you can find the time could pls try the above code change to see if it fixes the power on SCD30 detection?

arnowelzel commented 2 years ago

@arnowelzel could you pls try to change

[...] into

bool scd30InitOnce = false;

bool Xsns42(byte function)
{
  if (!I2cEnabled(XI2C_29)) { return false; }

  bool result = false;

/*
  if (FUNC_INIT == function) {
    Scd30Detect();
  }
*/
  if (!scd30InitOnce && (FUNC_EVERY_SECOND == function) && (TasmotaGlobal.uptime > 2)) {
    scd30InitOnce = true;
    Scd30Detect();
  }
  else if (scd30Found) {

and report back.

Just tried that change and looks good so far. Even after a power cycle the SCD30 was detected properly and everything is fine:

image

The code makes sense as well - wait until the global uptime is more than 2 seconds before trying to detect the SCD30.

Thanks for the quick fix!

arnowelzel commented 2 years ago

Just for completeness - after I let some fresh air in, the readings also got down:

image

sfromis commented 2 years ago

I can also see it working after a power cycle restart. 00:00:01.925 I2C: SCD30 found at 0x61

arendst commented 2 years ago

Thx. Integrated just now.

DrUseless commented 1 year ago

Has this issue been fixed in the Tasmota-Sensors.bin (12.1.1) file. If I load the latest release of the bin file I still have the issue of the SCD30 not being detected after a power cycle. Only when I restart from the web interface it detects the SCD30. I'm a bit of a newbie so I apologies if this has been addressed somewhere else.

arendst commented 1 year ago

Should have been fixed in 12.1.1

If not try latest dev release (available in an hour) which has an additional waiting second before initializing

DrUseless commented 1 year ago

Thank I loaded the new Dev file . Stupid question. Think I might be missing something. With the Dev Release I'm still experiencing the power cycle issue. Do I need to build my own bin file where I #define USE_SCD30? Currently I'm just flashing my D1 Mini with the Tasmota-sensor.bin file and then just assigning the I2C ports. Doing it this way gives me the issue with the power cycle . Like I said Newbie here 🤦🏻‍♂️

arendst commented 1 year ago

It looks like the Wemos devices are a problem regarding power up.

On another device it works fine after power up and v12.1.1

I changed the power up init time to 5 seconds and it still fails to see the SCD30 on my wemos D1 too.

I guess you can forget to make this work due to I2C bus noise during Wemos power up. Just make a good rule to do a restart after initial power up to solve this issue.

arendst commented 1 year ago

As I thought. The Wemos D1 is flakey at power on.

I just included a wait for a second before init I2C. Than it works.

I will need time to find a solution.

arendst commented 1 year ago

OK.

In latest dev there is a new command called SetOption46 0..255 allowing you to stall initialization for 0..255 * 10 milliseconds to let stabilize the local Wemos power.

You might want to experiment with values like SO46 10 os SO46 20 for a 100mSec or 200mSec delay.

If you own the Adafruit SCD30 you might also want to power the device from 5V as it draws a lot of power when measuring (notice the fainting power led because the wemos LDO just cannot provide enough power for the device.

YMMV.

DrUseless commented 1 year ago

Apologies for the late response. So I tried the suggestion you said with the new Dev firmware Tasmota-Sensor.bin file and SetOption46 0-255. I still can't get the scd30 to work on power up. No matter the value I set. I will either move to a different MCU or perhaps try running a rule for the device to restart after a Power cycle. Thanks

DrUseless commented 1 year ago

Okay so I tried another D1 mini and the SetOption46 200 does work. Think there might have been an issue with the one I initially tested on. So every time I power cycle the SCD30 comes online . Thanks for the assistance in getting this too function. Much Appreciated

kdelios commented 9 months ago

I have exactly the same behavior with esp32 (esp32 wroom-32 development board). Tested at 13.2.0, 13.2.0.2 and older 13.1.0 with no success. Each (100%) power recycle leads to unrecognized sensor with empty sensor details etc. Sensor is a genuine Sensirion SCD30, supplied with 5V. Only after restart is OK

sfromis commented 9 months ago

Did you try tweaking SetOption46 as suggested by arendst?

kdelios commented 9 months ago

Thanks I saw the possible solution. Didn't tried yet, (I'm out of office) and I have no physical access to it. I am panning to do it tomorrow morning and I will report back.

sfromis commented 9 months ago

Did a small test hooking up a SCD30 to an ESP32, and can confirm that it was not found on first boot after power up. When restarting, it was found, but I notice that other I2C sensors on same board were found less than 0.3 seconds after boot, while the SCD30 was only found nearly 2.7 seconds later. So there is already a delay for SCD30.

When using SetOption46 255 (the max of 2.55 secs), the whole I2C initialization was delayed by that time, and SCD30 was found at first boot after power up. It may be feasible with a shorter delay than 255, if you want to make boot a bit faster.

kdelios commented 9 months ago

SO46 seems to work. In any case, as a failsafe action I am detecting tasmota restart season as "Vbat power on reset" at node red and publish a restart 1 mqtt message after 5 sec.

B0rax commented 3 months ago

I think this issue should be opened again. I am facing the same issue with an ESP32 C3 and the SCD30 sensor. Even SO46 255 does not fix the issue. Only a software restart allows the sensor to be recognized.

sfromis commented 3 months ago

With ESP32-C3, Tasmota 13.4.1.2 dev build and SetOption46 255, right after power on:

"SCD30":{"CarbonDioxide":769,"eCO2":798,"Temperature":26.54,"Humidity":38.42,"DewPoint":11.20,"HeatIndex":26.48},"TempUnit":"C"}
B0rax commented 3 months ago

I am running a pre compiled binary from the web flasher: Tasmota 13.4.1.2 (5ecd45e-tasmota32). The board I am using is an ESP32 c3 super mini. I2C is connected to gpio 3 (SDA) and 4 (SCL).

It is definitely not recognized on every normal boot.