sparkfun / SparkFun_SCD4x_Arduino_Library

An Arduino library for the Sensirion SCD4x (SCD40 and SCD41) family of CO2 sensors
Other
10 stars 8 forks source link

Crash since 1.1.0 #6

Closed DavidSichau closed 1 year ago

DavidSichau commented 1 year ago

I have the same program, which run perfectly with 1.0.4 and now crashes with version 1.1.0

ELF file SHA256: 0000000000000000

Rebooting...
ets Jul 29 2019 12:21:46

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13864
load:0x40080400,len:3608
entry 0x400805f0
SCD4x Example
Guru Meditation Error: Core  1 panic'ed (StoreProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x400d2f5c  PS      : 0x00060a30  A0      : 0x800d3382  A1      : 0x3ffb2780  
A2      : 0x3ffc1198  A3      : 0x00000000  A4      : 0x00000000  A5      : 0x000000fd  
A6      : 0x00000009  A7      : 0x00000001  A8      : 0x800d2f5c  A9      : 0x3ffb2750  
A10     : 0x00000002  A11     : 0x00002eb7  A12     : 0x00000b20  A13     : 0x000000b7  
A14     : 0x0000ff00  A15     : 0xff000000  SAR     : 0x0000001c  EXCCAUSE: 0x0000001d  
EXCVADDR: 0x00000000  LBEG    : 0x40087809  LEND    : 0x40087819  LCOUNT  : 0xfffffffc  

Backtrace:0x400d2f59:0x3ffb27800x400d337f:0x3ffb27b0 0x400d149a:0x3ffb27f0 0x400d5efa:0x3ffb2820 

Code:

/*
  Reading CO2, humidity and temperature from the SCD4x in Low Power mode
  By: Paul Clark
  Based on earlier code by: Nathan Seidle
  SparkFun Electronics
  Date: June 3rd, 2021
  License: MIT. See license file for more information but you can
  basically do whatever you want with this code.

  Feel like supporting open source hardware?
  Buy a board from SparkFun! https://www.sparkfun.com/products/18365

  This example prints the current CO2 level, relative humidity, and temperature in C.

  Hardware Connections:
  Attach RedBoard to computer using a USB cable.
  Connect SCD40/41 to RedBoard using Qwiic cable.
  Open Serial Monitor at 115200 baud.
*/

#ifndef ARDUINO_INKPLATE2
#error "Wrong board selection for this example, please select Soldered Inkplate2 in the boards menu."
#endif

#include <Wire.h>
#include "Inkplate.h" //Include Inkplate library to the sketch
Inkplate display;  
#include "SparkFun_SCD4x_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_SCD4x
SCD4x mySensor;

#define DELAY_MS 1000 * 30

#define INKPLATE2_WHITE 0
#define INKPLATE2_BLACK 1
#define INKPLATE2_RED 2

void setup()
{
  Serial.begin(115200);
  Serial.println(F("SCD4x Example"));
  Wire.begin();

  //mySensor.enableDebugging(); // Uncomment this line to get helpful debug messages on Serial

  //.begin will start periodic measurements for us (see the later examples for details on how to override this)
  if (mySensor.begin() == false)
  {
    Serial.println(F("Sensor not detected. Please check wiring. Freezing..."));
    while (1)
      ;
  }

  //By default, the SCD4x has data ready every five seconds.
  //We can enable low power operation and receive a reading every ~30 seconds

  //But first, we need to stop periodic measurements otherwise startLowPowerPeriodicMeasurement will fail
  if (mySensor.stopPeriodicMeasurement() == true)
  {
    Serial.println(F("Periodic measurement is disabled!"));
  }  

  //Now we can enable low power periodic measurements
  if (mySensor.startLowPowerPeriodicMeasurement() == true)
  {
    Serial.println(F("Low power mode enabled!"));
  }

  Serial.print(mySensor.getTemperatureOffset());

  display.begin();        // Init library (you should call this function ONLY ONCE)

  //The SCD4x has data ready every thirty seconds
}

#define MAX_CO2 2000
#define MIN_CO2 400

float relCO2(float input) {
  return (input - MIN_CO2) / (MAX_CO2 - MIN_CO2);
}

void print(uint16_t co2, float t, float h) {
  display.clearDisplay();

  float p = relCO2(co2);
  int color = INKPLATE2_BLACK;
  if (p >  0.3) {
    color = INKPLATE2_RED;
  }
  display.drawRect(10, 0, 190, 15, INKPLATE2_BLACK);
  display.fillRect(11, 1, p * 190, 13, color);

  Serial.print(F("CO2(%):"));
  Serial.print(p);

  display.setCursor(10, 25);
  display.setTextColor(INKPLATE2_BLACK, INKPLATE2_WHITE);

  display.setTextSize(2);

  display.printf("CO2 (ppm) %4u", co2);

  display.setTextColor(INKPLATE2_BLACK, INKPLATE2_WHITE);

  display.setCursor(10, 55);

  display.setTextSize(2);
  display.printf("Temperature %2.1f", t);

  display.setCursor(10, 85);

  display.setTextSize(2);
  display.printf("Humidity    %2.0f", h);

  display.display();                     
}

int prevCO2 = 0;
int prevT = 0;

void loop()
{
  if (mySensor.readMeasurement()) // readMeasurement will return true when fresh data is available
  {
    Serial.println();
    uint16_t co2 = mySensor.getCO2();
    float t = mySensor.getTemperature();
    float h = mySensor.getHumidity();

    if (abs(co2 - prevCO2) > 50 || abs(t - prevT) > 1) {
      print(co2, t, h);
    }

    Serial.print(F("\tCO2(ppm):"));
    Serial.print(co2);

    Serial.print(F("\tTemperature(C):"));
    Serial.print(t, 1);

    Serial.print(F("\tHumidity(%RH):"));
    Serial.print(h, 1);

    Serial.println();
    prevCO2 = co2;
    prevT = t;

  }
  else
    Serial.print(F("."));

  delay(DELAY_MS);
}
countrysideboy commented 1 year ago

Crash on scd40 too.

SFE-Brudnerd commented 1 year ago

Hello, I'm working on investigating this. In the meantime, please revert to 1.0.4.

Please provide the platform in use (atmega, esp32, etc.). Additionally, please post the output from running with debug enabled (uncomment mySensor.enableDebugging()), that will help narrow things down.

Thanks!

kharar commented 1 year ago

Using ESP8266 Debug output:

SCD40::begin: got serial number 0x6EE557073B66
SCD40::getSensorType: Word 1: 6EE5
SCD40::getSensorType: Word 2: 5707
SCD40::getSensorType: Word 3: 3B66
SCD40::extractMaskedSensorType: i: 0
SCD40::extractMaskedSensorType: serialNumberArray[i]: 6EE5
SCD40::extractMaskedSensorType: masks[i]: 3F
SCD40::extractMaskedSensorType: maskedValues[i]: 25
SCD40::extractMaskedSensorType: i: 1
SCD40::extractMaskedSensorType: serialNumberArray[i]: 5707
SCD40::extractMaskedSensorType: masks[i]: FF00
SCD40::extractMaskedSensorType: maskedValues[i]: 5700
SCD40::extractMaskedSensorType: Combined Value: 2557
SCD40::extractMaskedSensorType: Something's seriously wrong here...

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Exception (29):
epc1=0x40202df5 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

>>>stack>>>

ctx: cont
sp: 3ffffde0 end: 3fffffd0 offset: 0150
3fffff30:  57076ee5 00003b66 3ffeeb80 402048b0  
3fffff40:  00000000 00000001 3ffee99c 402033b5  
3fffff50:  35454536 37303735 36364233 3ffee900  
3fffff60:  00000001 3ffee9fc 3ffeeb80 402016c8  
3fffff70:  3ffe55f4 3ffee9fc 3ffeea40 3ffee9bc  
3fffff80:  3ffeea28 3ffee99c 3ffeeb80 4020110a  
3fffff90:  feefeffe feefeffe feefeffe feefeffe  
3fffffa0:  feefeffe feefeffe feefeffe 3ffeec00  
3fffffb0:  3fffdad0 00000000 3ffeebd4 40205108  
3fffffc0:  feefeffe feefeffe 3fffdab0 40101001  
<<<stack<<<

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 3424, room 16 
tail 0
chksum 0x2e
load 0x3fff20b8, len 40, room 8 
tail 0
chksum 0x2b
csum 0x2b
v00048c30
~ld
SFE-Brudnerd commented 1 year ago

Thanks for the debug log @kharar! Which SCD are you working with? I tried my code with a few dozen sensors, but your serial number is leading me to believe my solution for determining the sensor from the serial number might be flawed.

kharar commented 1 year ago

SCD41 (afaik - bought it from ebay)

On Thu, Jun 8, 2023, 19:45 Alex Brudner @.***> wrote:

Thanks for the debug log @kharar https://github.com/kharar! Which SCD are you working with? I tried my code with a few dozen sensors, but your serial number is leading me to believe my solution for determining the sensor from the serial number might be flawed.

— Reply to this email directly, view it on GitHub https://github.com/sparkfun/SparkFun_SCD4x_Arduino_Library/issues/6#issuecomment-1583083867, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKU4BQO2IT4LXHXS7SCZVLXKIFSPANCNFSM6AAAAAAYZCZR3Q . You are receiving this because you were mentioned.Message ID: @.***>

SFE-Brudnerd commented 1 year ago

Please try now. It worked with the atmega, but failed with the esp32. It now works with the ESP32.

circuit-activebuildings commented 1 year ago

I am using this with RP2040 and it is also crashing, does 1.1.1 has resolved the issue?

kharar commented 1 year ago

Cannot find SCD41 on ESP8266 with library 1.1.1

On Tue, Jun 13, 2023, 13:11 Vaibhav Jadhav @.***> wrote:

I am using this with RP2040 and it is also crashing, does 1.1.1 has resolved the issue?

— Reply to this email directly, view it on GitHub https://github.com/sparkfun/SparkFun_SCD4x_Arduino_Library/issues/6#issuecomment-1589086569, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKU4BXBBI6FDOGGGTL2N73XLBDG7ANCNFSM6AAAAAAYZCZR3Q . You are receiving this because you were mentioned.Message ID: @.***>

SFE-Brudnerd commented 1 year ago

1.1.1 should solve the crashing issue. I've been in contact with Sensirion about the sensor type. I'm testing a solution now. For now, you can just set the 4th input argument to begin to 'false' to have the functionality from 1.0.4.

SFE-Brudnerd commented 1 year ago

v1.1.2 was just published. Please give a few hours to allow it to propagate through to the Arduino libraries. This should finally resolve the issues introduced by 1.1.0. I'm closing this, if there are further issues, please open a new issue.