Code Monkey home page Code Monkey logo

arduino-i2c-scd4x's Introduction

Sensirion I2C SCD4x Arduino Library

This is the Sensirion SCD4x library for Arduino using the I2C interface.

Click here to learn more about the SCD4x sensor and the SCD41 Evaluation Kit Board.

Installation

To install, download the latest release as .zip file and add it to your Arduino IDE via

Sketch => Include Library => Add .ZIP Library...

Don't forget to install the dependencies listed below the same way via Add .ZIP Library

Note: Installation via the Arduino Library Manager is coming soon.

Dependencies

Quick Start

  1. Connect the SCD4x sensor to your Arduino board's standard I2C bus. Check the pinout of your Arduino board to find the correct pins. The pinout of the SCD4x sensor board can be found here

    • VDD of the SEK-SCD41 to the 3.3V of your Arduino board (5V is also possible)
    • GND of the SEK-SCD41 to the GND of your Arduino board
    • SCL of the SEK-SCD41 to the SCL of your Arduino board
    • SDA of the SEK-SCD41 to the SDA of your Arduino board
  2. Open the exampleUsage sample project within the Arduino IDE

     File => Examples => Sensirion I2C Scd4x => exampleUsage
    
  3. Click the Upload button in the Arduino IDE or

     Sketch => Upload
    
  4. When the upload process has finished, open the Serial Monitor or Serial Plotter via the Tools menu to observe the measured CO2, Temperature and Humidity values. Note that the Baud Rate in the corresponding window has to be set to 115200 baud.

Contributing

Contributions are welcome!

We develop and test this driver using our company internal tools (version control, continuous integration, code review etc.) and automatically synchronize the master branch with GitHub. But this doesn't mean that we don't respond to issues or don't accept pull requests on GitHub. In fact, you're very welcome to open issues or create pull requests :)

This Sensirion library uses clang-format to standardize the formatting of all our .cpp and .h files. Make sure your contributions are formatted accordingly:

The -i flag will apply the format changes to the files listed.

clang-format -i *.cpp *.h

Note that differences from this formatting will result in a failed build until they are fixed.

License

See LICENSE.

arduino-i2c-scd4x's People

Contributors

crathje avatar leoniefierz avatar mbjoern avatar psachs avatar qfisch avatar rnestler avatar rol-la avatar sdru avatar sensirion-bot avatar zifzaf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduino-i2c-scd4x's Issues

Undocumented sleep mode and powerDown() / wakeUp() command codes

Hello dear all,

in the library, there are the powerDown() and wakeUp() functions, which send the command codes 0x36E0 and 0x36F6 respectively.
Also, the "sleep mode" is mentioned in the comments of these functions in SensirionI2CScd4x.h

* powerDown() - Put the sensor from idle to sleep mode to reduce current
.

My problem is that neither these commands, nor their codes nor the sleep mode are mentioned at all in the latest SCD4x datasheet (Version 1.1).
I've attached the Datasheet's Command Overview:
image

As you can see, they are missing.

My question is whether these commands work as described in the comments or if there's a reason they are not included in the Datasheet and whether it's safe to use these two functions.

Thanks in advance.

SEK-SCD41 kit stopped working: "Invalid sample detected, skipping." self-test error code: 196

So, this device was working fine for a month.
But suddenly, today, it would only read 0 ppm, out of the blue.

I programmed the exampleUsage code, to check, and I get:

Serial: 0x53CABF073B9F
Waiting for first measurement... (5 sec)
Invalid sample detected, skipping.
Invalid sample detected, skipping.
Invalid sample detected, skipping.
Invalid sample detected, skipping.
Invalid sample detected, skipping.
Invalid sample detected, skipping.
Invalid sample detected, skipping.
Invalid sample detected, skipping.
Invalid sample detected, skipping.
Invalid sample detected, skipping.
Invalid sample detected, skipping.
Invalid sample detected, skipping.
Invalid sample detected, skipping.

This is with v 0.3.1 of the library.

Also I did an I2C scan, and the device does show up at address 0x62.

Sending a factory reset command wit performFactoryReset() did not help.

What does it mean for an error code returned?

I connect the SCD41 sensor and Arduino Uno board with the breadboard and run the example program from this library. The program fails. After some time of debugging, I think the problem is my scd4x.getDataReadyFlag(isDataReady) always returns 267, which is a very odd number. I haven't found any useful information explaining the error codes, and the comments for this function just say "return 0 on success, an error code otherwise".

I wonder if the returned error code has some special meaning depending on the number, just like HTTP response status codes. Or the error code itself doesn't make any sense, which just simply means there is an error somewhere.

Unable to read CO2 but temperature and humidty works fine

Hi everyone!
I've bougth a SCD41 sensor from mouser and developed my own custom board with it. I originally had connected 3V3 on it, but since the readings of the CO2 didn't work, I changed to 5V, but still doesn't work.

I've been receiving "Invalid sample detected, skipping.". When I remove this validation, I can see that CO2 is zero, but temperature and humidty readings are fine. What could be?

image

Will there be an example for connecting multiple sensors?

The example usage code is quite great for newbies, however, after I connected more than one sensor to the Arduino board, my program crashed. And the provided error log is "Wrong CRC Found", which makes me lose my head. I wonder if there will be some example code to show how to interact with multiple sensors?

Adafruit QT-Py ESP32 S2 and Pimoroni SCD41: Received NACK

I was trying exampleUsage for Arduino, but with no success:
image

It's a Pimoroni SCD41, connected via StemmaQT/Qwiic connector to Adafruit QT-Py ESP32 S2.
I had this working before with Adafruit WipperSnapper, but since my Wi-Fi is unstable I'm looking for a standalone solution.

Cannot receive measurement data

I have an ESP8266 connected to an SCD41 Adafruit module, and cannot get the sensor to send any measurement data.
I have tried both periodic and single-shot mode, multiple MCU's at different voltages, and nothing.
There is another I2C sensor hooked up and it reads just fine, I've tried to get it working with this connected and disconnected.
I have also looked at it with my scope and logic analyzer and everything looks great, no noise problems.

The 2 problems I'm having are...
When I call getDataReadyStatus(), it returns 0 almost every time, it has returned 0x8000 a few times but was unable to read after, and even then I don't think that is the part of the "last 11 bits".
When I call readMeasurement() it returns "Not enough data received" every time.
I've only managed to get it to read literally once, but it returned Co2 as 0 which means a bad sample.
Other commands such as getting the serial number, setting/getting altitude/temp offset work just fine.

The example code also gives me the same error for the readMeasurement().

Is it safe to say its a faulty sensor?
I'm 95% sure it is, but this project is for a client and I need to be 100% before telling him he needs to order a new sensor.

Edit: Another command that isn't working is the self test.

scd41 connected to Atmega168PA

I am trying to use the example code on a longan I2C CAN BUS module. I use a adafruit friend as FTDI.

When i run this code : (stripped to bare minimum)

#include <Arduino.h>
#include <SensirionI2CScd4x.h>
#include <Wire.h>

SensirionI2CScd4x scd4x;

void setup() {
  Serial.begin(115200);
  while (!Serial) {
    delay(100);
  }
  Wire.begin();
  uint16_t error;
  Serial.println("1");
  scd4x.begin(Wire);
  error = scd4x.stopPeriodicMeasurement();
  Serial.println(error);
 }

void loop() {
}

I get no println at all. Even not the Serial.println("1"); So there has to be something very wrong, when i comment line "error = scd4x.stopPeriodicMeasurement();" . There is no problem at all. Then i have all println, so then my code run.

in arduino-1.8.15\libraries\arduino-i2c-scd4x\src\SensirionI2CScd4x.cpp , when i comment out "error = SensirionI2CCommunication::sendFrame(SCD4X_I2C_ADDRESS, txFrame,*_i2cBus);" Then it runs again.

I have connection to the scd41, when i do a i2c scan, i see a device on 0x62.

arduino-snippets/SCD4x_I2C_minimal_example/SCD4x_I2C_minimal_example.ino works great.

Any idea what the problem could be?

Measure stability at startup

I've just started using SCD41 evaluation module with an Arduino UNO for preliminary test purpose. It works with your provided example, but I found that the measures takes about 1 minute to stabilize, as you can see in the recorded data below (stable conditions, actual temperature = 21 deg) :

Serial: 0xC03ABF073B4D
Waiting for first measurement... (5 sec)
CO2 [ppm], Temp [degC], Humidity [%]
832, 22.03, 29.41
827, 21.98, 29.49
808, 21.88, 29.72
831, 21.81, 30.01
858, 21.74, 30.38
863, 21.65, 30.48
859, 21.58, 30.70
854, 21.52, 30.76
852, 21.46, 30.89
884, 21.40, 31.37
934, 21.37, 31.87
954, 21.31, 31.96
1020, 21.28, 32.06
1095, 21.24, 32.38
1141, 21.21, 33.02
1166, 21.19, 33.02
1167, 21.15, 32.77
1166, 21.15, 32.62
1151, 21.13, 32.46

I plan to use this module with a battery powered ESP32 board, in order to do a periodic CO2 measure (basically every minute) during a couple of days. I planned to have my module in deep sleep between 2 successive measures. Each measure should not last more than a couple of seconds.

What would be the best hardware and/or software design to get an accurate measure between two deep sleep ?

Let's suppose that my ESP32 wakes up every minute to do a single measure. Should the SDC41 be powered all the time, with a periodic measure period = 30s using startLowPowerPeriodicMeasurement(), so that the ESP32 reads a measure less than 30s old ?

Highly suspect values from single-shot measurements.

I am getting highly suspect values from single shot measurements.
As low as 217 ppm, with wild swings to 700, indoors.
I don't think they are correct.

I feed ambient pressure (991 currently, in my location) and wait for the data ready signal.

But I am getting nonsense back.

Is my sensor broken? Is single-shot function broken?

...
SensirionI2CScd4x cdos;
...
static void setupCO2Sensor(void)
{
  cdos.begin(Wire);
}

static void calibrateCO2Sensor(uint16_t pressure)
{
  const uint16_t err = cdos.setAmbientPressure(pressure);
  assert(err == 0);
}

In the main loop:

  // Request a co2 measurement.
  uint16_t err = cdos.measureSingleShot();
  assert( err == 0 );

  // Get the barometric pressure.
  const uint16_t pre = updateBarometer();
  
  // Calibrate the co2 device.
  calibrateCO2Sensor(pre);

  for (int attempt=0; attempt<10; ++attempt)
  {
    uint16_t rdy = 0xffff;
    uint16_t err = cdos.getDataReadyStatus(rdy);
    assert(err==0);
    Serial.println(rdy);
    if ( (rdy & 0x7ff ) != 0 )
    {
      uint16_t co2;
      float temperature;
      float humidity;
      uint16_t err = cdos.readMeasurement(co2,temperature,humidity);
      assert(err==0);
      Serial.println("co2:");
      Serial.println(co2);
      Serial.println("temperature:");
      Serial.println(temperature);
      Serial.println("humidity:");
      Serial.println(humidity);
      update_status_lines( pre, co2 );
      break;
    }
    if ( attempt==9 )
    {
      Serial.println("co2 data never became ready.");
    }
    delay(1000);
  }

Note: for some single shot measurements, the data rdy signal is never shown.

Receiving I2C errors occasionally from readMeasurement()

Serial.print("Error trying to execute readMeasurement(): ");

Occasionally readMeasurement() prints "Received NACK on transmit of address" or "Wrong CRC found" on one of my test devices. It's a SEK-SCD41 kit connected to an ESP32 using the excellent wires that come with the kit.

These errors are accompanied by ESD-IDF I2C messages when it's a NACK issue, and only then:

[I][esp32-hal-i2c.c:1138] i2cProcQueue(): Bus busy, reinit
[W][esp32-hal-i2c.c:1419] i2cCheckLineState(): invalid state sda(21)=0, scl(23)=1

Do you happen to have any indication as to what might be the root cause of this with your hardware? Have you seen this before?

When I2C communication fails, the CO2 reading I get out of readMeasurement() is 16300-something in https://github.com/Sensirion/arduino-i2c-scd4x/blob/master/examples/exampleUsage/exampleUsage.ino#L108. I think it should be internally reset to zero/0 so that your sample code would skip it.

Location of the `errorToString` function

First of all, I try to find the implementation details of the function errorToString, which is used in the example usage program. But I can't find it. I think there is something wrong with this function, and the reason is as follows...

I connected a Micro SD Card Adapter (which has an SD card in it) and an SCD41 sensor with the Arduino Uno board, and I confirmed all the wires were correctly connected. I tried to run the program below but failed. Only after I commented out the two lines errorToString(error, errorMsg, 256);, the program ran smoothly. I was shocked, but I couldn't find the reason. I hope someone who has the same devices can try the program below, and I wonder if you will find the same error as me. I am very free to talk with you about this very odd bug, which has confused me for three days.

(p.s. Plus, I can confirm this odd error only happens when we want to read data from the sensor scd41 and write it to the sd card. If we only read it or write it, this would be completely fine.)

#include <Arduino.h>
#include <SensirionI2CScd4x.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>

SensirionI2CScd4x scd4x;
File dataFile;

void setup() {
    Serial.begin(115200);
    while (!Serial) {
        delay(100);
    }

    Serial.println("Initializing SD card...");
    if (!SD.begin(4)) {
        Serial.println("SD card initialization failed!");
        while (1) {};
    }
    Serial.println("done.");

    dataFile = SD.open("c_data.csv", O_WRITE | O_APPEND);
    if (dataFile) dataFile.println("CO2, Temperature, Humidity");

    Wire.begin();
    scd4x.begin(Wire);

    uint16_t error; char errorMsg[256];

    error = scd4x.stopPeriodicMeasurement();
    if (error) {
        Serial.print("Error trying to execute stopPeriodicMeasurement(): ");
        errorToString(error, errorMsg, 256); // comment out this line
        Serial.println(errorMsg);
    }

    error = scd4x.startPeriodicMeasurement();
    
    if (error) {
        Serial.print("Error trying to execute startPeriodicMeasurement().");
        errorToString(error, errorMsg, 256);  // comment out this line
        Serial.println(errorMsg);
    }

    Serial.println("Data collection started...");
}

void loop() {}

Question about the forced calibration procedure

Hi,

We are calibrating some SCD41’s together in a fixed CO2 environment (500ppm). After calibration we noticed big differences between the sensors.

In the datasheet:

“ 3.7.1 perform_forced_recalibration
Description: To successfully conduct an accurate forced recalibration, the following steps need to be carried out:

  1. Operate the SCD4x in the operation mode later used in normal sensor operation (periodic measurement, low power
    periodic measurement or single shot) for > 3 minutes in an environment with homogenous and constant CO2
    concentration.
  2. Issue stop_periodic_measurement. Wait 500 ms for the stop command to complete.
  3. Subsequently issue the perform_forced_recalibration command and optionally read out the FRC correction (i.e. the
    magnitude of the correction) after waiting for 400 ms for the command to complete.
    • A return value of 0xffff indicates that the forced recalibration has failed.
    Note that the sensor will fail to perform a forced recalibration if it was not operated before sending the command. Please make
    sure that the sensor is operated at the voltage desired for the application when applying the forced recalibration sequence.”

While calibrating we take a 10 minute period to build up the gas value in the gas chamber, how important is the measurement done in that 10 min period? (While its not stable yet, only after 5 min). Are all those measurements in the 10 min period used for calibration, or only one measurement at the moment measurement is stopped and the forced cal command is issued?

Example needed to print some internal values

Hello,

I would like to confirm that self-calibration is enabled/disabled as well as the ASC Initial Period and Standard Period.
I have tried a (naive) approach:

uint16_t ascEnabled;
scd4x.getAutomaticSelfCalibration(ascEnabled);
Serial.println(ascEnabled);

uint16_t ascInitialPeriod;	
scd4x.getAutomaticSelfCalibrationInitialPeriod(ascInitialPeriod);
Serial.println(ascInitialPeriod);

But obviously this is not correct as I am getting weird outputs.

Would it be possible to write a small example ?

Thanks a lot

Comments don't match function

Hello everyone,
Just wanted to point out something minor.
In the SensirionI2CScd4x.h file from line 265 to 313 the comment describing the function doesn't match the function.

I'm not sure if I should do a pull request, because it's #stated that the file should not be changed manually.

Error: Not enough data received

Hello,

This is an awesome sensor that works perfectly with my SensorBridge and monitoring its measurements in ControlCenter. However, when I try to use this library it throws and error! The example script reads the serial number of the sensor just fine, but then repeats this constantly:

Error trying to execute readMeasurement(): Not enough data received
Error trying to execute readMeasurement(): Not enough data received
Error trying to execute readMeasurement(): Not enough data received
Error trying to execute readMeasurement(): Not enough data received
...

Is there something that I need to configure on the sensor that isn't included in the example sketch? Thanks.

Single shot measurement

Dear,

Thanks a lot for the new sensor. I'm amazed by the size and the ease of installation.
I used the example code to compare the behavior with the previous SCD30.
They are running next to each other with very similar results.

When I try to lower power - I want to run it on a single 3,6V 3000mAh - battery, I had a strange behavior.
I changed line 88 of the example
error = scd4x.startPeriodicMeasurement();

To
error = scd4x.measureSingleShot();

I measure the data the same way
error = scd4x.readMeasurement(co2, temperature, humidity);

After the measurement I send the data to a server and let the ESP32 board go to sleep for 15 minutes.
I wake up the ESP32 board, reinitialize the sensor, single shot measure, going back to sleep. This works for the SCD30 sensor (measurement interval of 60 seconds - and waiting for data available), but the low power option is still consuming +/- 5mA, so the battery last only a week.

the strange behavior in the measurement:

  • CO2 is +/- 100ppm higher in measureSingleShot() modus than in startPeriodicMeasurement() modus
  • Temperature is 3 to 4 degrees lower in measureSingleShot() modus than in startPeriodicMeasurement() modus
  • humidity is +/- 4% higher in measureSingleShot() modus than in startPeriodicMeasurement() modus

I have 2 SCD41 sensors and 2 SCD30 sensors running on the same table to verify results. I run one SCD 41 with the example code, and one with the single shot.
I exchanged them to be sure it was not a sensor problem, but same behavior.

Did I miss something?
Is there a warming up time or something?

Sensor is continuously powered from the battery on the breadboard.
ESP32 board is going to sleep.

Thanks in advance.

Automatic measurements: only a few received, then only errors.

Running the example code on the SCD41 devkit:

Serial: 0x53CABF073B9F
Waiting for first measurement... (5 sec)
Co2:498	Temperature:22.40	Humidity:26.96
Co2:600	Temperature:22.34	Humidity:27.22
Co2:678	Temperature:22.20	Humidity:27.46
Error trying to execute readMeasurement(): Not enough data received
Error trying to execute readMeasurement(): Not enough data received
Error trying to execute readMeasurement(): Not enough data received
Error trying to execute readMeasurement(): Not enough data received
Error trying to execute readMeasurement(): Not enough data received
Error trying to execute readMeasurement(): Not enough data received
Error trying to execute readMeasurement(): Not enough data received

This is with a 5V Arduino Pro Micro.

How to use multiples SCD4x in the same arduino ?

Hi everyone,

I would like to use more than one sensor in my arduino uno, how can I use I2C to do this ?

Code exemple:


//---------------------
// SENSOR CO2
#include <Arduino.h>
#include <SensirionI2CScd4x.h>
#include <Wire.h>
SensirionI2CScd4x scd4x;
SensirionI2CScd4x scd4x_2;
//---------------------

//---------------------
// CARTAO SD
#include <SPI.h>
#include <SD.h>
File myFile;
int pinoSS = 10;  // Pin 53 para Mega / Pin 10 para UNO e NANO
//---------------------


//---------------------
// GPS
#define GPS_RX 0
#define GPS_TX 1
#define GPS_Serial_Baud 9600
#include <SoftwareSerial.h>
#include <TinyGPS.h>
TinyGPS gps;
SoftwareSerial gpsSerial(GPS_RX, GPS_TX);
int ano;
byte mes, dia, hora, minuto, segundo, centesimo;
//---------------------

//---------------------
// RELE
// byte rele = 3;
//---------------------


void setup() {

  Serial.begin(GPS_Serial_Baud);

  //---------------------
  // GPS

  gpsSerial.begin(GPS_Serial_Baud);
  //---------------------

  //---------------------
  // CARTAO SD
  pinMode(pinoSS, OUTPUT);
  SD.begin();
  myFile = SD.open("dados.txt", FILE_WRITE);
  //---------------------


  // SENSOR CO2
  //---------------------
  Wire.begin();

  uint16_t error;
  scd4x.begin(Wire, 0x3C);
  scd4x_2.begin(Wire, 0x3D);
  error = scd4x.stopPeriodicMeasurement();
  error = scd4x.startPeriodicMeasurement();
  //---------------------

  // RELE
  //---------------------
  // pinMode(rele, OUTPUT);
  //---------------------
}

void loop() {

  // delay(5000);

  //---------------------
  // GPS
  bool newData = false;
  unsigned long chars;
  // For one second we parse GPS data and report some key values
  for (unsigned long start = millis(); millis() - start < 5000;) {
    while (gpsSerial.available()) {
      char c = gpsSerial.read();
      // Serial.write(c); //apague o comentario para mostrar os dados crus
      if (gps.encode(c))  // Atribui true para newData caso novos dados sejam recebidos
        newData = true;
    }
  }
  //---------------------

  //---------------------
  // GPS


  //---------------------
  if (newData) {
    float flat, flon;
    unsigned long age;
    gps.f_get_position(&flat, &flon, &age);
    Serial.print("LAT=");
    Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
    Serial.print(" LON=");
    Serial.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
    Serial.print(" SAT=");
    Serial.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites());
    Serial.print(" PREC=");
    Serial.print(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop());
    Serial.println();
    int ano1;
    byte mes, dia, hora, minuto, segundo, centesimo;
    gps.crack_datetime(&ano1, &mes, &dia, &hora, &minuto, &segundo, &centesimo);
    Serial.println(ano1);
    Serial.println("---------------------------------------------------------");
    //---------------------



    //---------------------
    // SENSOR CO2
    uint16_t error;
    uint16_t co2;
    float temperature;
    float humidity;
    error = scd4x.readMeasurement(co2, temperature, humidity);
    // Serial.print("Co2:");
    // Serial.print(co2);
    // Serial.print("\t");
    // Serial.print("Temperature:");
    // Serial.print(temperature);
    // Serial.print("\t");
    // Serial.print("Humidity:");
    // Serial.println(humidity);
    //---------------------

    //---------------------
    // CARTAO SD
    myFile = SD.open("dados.txt", FILE_WRITE);
    //---------------------

    //---------------------
    // CARTAO SD - GPS

    gps.crack_datetime(&ano, &mes, &dia, &hora, &minuto, &segundo, &centesimo);
    myFile.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);  // Escreve no Arquivo
    myFile.print(";");
    myFile.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);  // Escreve no Arquivo
    myFile.print(";");
    myFile.print(ano);
    myFile.print(";");
    myFile.print(mes);
    myFile.print(";");
    myFile.print(dia);
    myFile.print(";");
    myFile.print(hora);
    myFile.print(";");
    myFile.print(minuto);
    myFile.print(";");
    myFile.print(segundo);
    myFile.print(";");

    //altitude
    float altitudeGPS;
    altitudeGPS = gps.f_altitude();

    //velocidade
    float velocidade;
    velocidade = gps.f_speed_kmph();  //km/h

    //sentito (em centesima de graus)
    unsigned long sentido;
    sentido = gps.course();
    sentido = float(sentido) / 100;

    //satelites e precisão
    unsigned short satelites;
    unsigned long precisao;
    satelites = gps.satellites();
    precisao = gps.hdop();

    myFile.print(altitudeGPS);  // Escreve no Arquivo
    myFile.print(";");
    myFile.print(velocidade);  // Escreve no Arquivo
    myFile.print(";");
    myFile.print(sentido);  // Escreve no Arquivo
    myFile.print(";");
    myFile.print(satelites);  // Escreve no Arquivo
    myFile.print(";");
    myFile.print(precisao);  // Escreve no Arquivo
    myFile.print(";");



    // CARTAO SD - SENSOR CO2
    myFile.print(co2);  // Escreve no Arquivo
    myFile.print(";");
    myFile.print(temperature);  // Escreve no Arquivo
    myFile.print(";");
    myFile.print(humidity);  // Escreve no Arquivo
    myFile.println(";");
    myFile.close();
    //---------------------
  }
}

The error:

/Users/joaojcsq/Desktop/Programa_AREJA/source_us_com_011/source_us_com_011.ino: In function 'void setup()':
/Users/joaojcsq/Desktop/Programa_AREJA/source_us_com_011/source_us_com_011.ino:62:25: error: no matching function for call to 'SensirionI2CScd4x::begin(TwoWire&, int)'
   scd4x.begin(Wire, 0x3C);
                         ^
In file included from /Users/joaojcsq/Desktop/Programa_AREJA/source_us_com_011/source_us_com_011.ino:5:0:
/Users/joaojcsq/Documents/Arduino/libraries/Sensirion_I2C_SCD4x/src/SensirionI2CScd4x.h:56:10: note: candidate: void SensirionI2CScd4x::begin(TwoWire&)
     void begin(TwoWire& i2cBus);
          ^~~
/Users/joaojcsq/Documents/Arduino/libraries/Sensirion_I2C_SCD4x/src/SensirionI2CScd4x.h:56:10: note:   candidate expects 1 argument, 2 provided
/Users/joaojcsq/Desktop/Programa_AREJA/source_us_com_011/source_us_com_011.ino:63:27: error: no matching function for call to 'SensirionI2CScd4x::begin(TwoWire&, int)'
   scd4x_2.begin(Wire, 0x3D);
                           ^
In file included from /Users/joaojcsq/Desktop/Programa_AREJA/source_us_com_011/source_us_com_011.ino:5:0:
/Users/joaojcsq/Documents/Arduino/libraries/Sensirion_I2C_SCD4x/src/SensirionI2CScd4x.h:56:10: note: candidate: void SensirionI2CScd4x::begin(TwoWire&)
     void begin(TwoWire& i2cBus);
          ^~~
/Users/joaojcsq/Documents/Arduino/libraries/Sensirion_I2C_SCD4x/src/SensirionI2CScd4x.h:56:10: note:   candidate expects 1 argument, 2 provided
Multiple libraries were found for "SensirionI2CScd4x.h"
  Used: /Users/joaojcsq/Documents/Arduino/libraries/Sensirion_I2C_SCD4x
  Not used: /Users/joaojcsq/Documents/Arduino/libraries/arduino-i2c-scd4x-master
exit status 1

Compilation error: no matching function for call to 'SensirionI2CScd4x::begin(TwoWire&, int)'

Library error in Forced Recalibration

I keep getting "Not enough data received" error when I execute a forced recalibration. I believe it's because the wrong number of bytes is expected in a the response. The library expects 5 but the response is only 3.

The write command is 5 bytes : 2 for command, 2 for data, 1 for crc
The response command is 3 bytes: 2 for data, 1 for crc

temperature and humidity conversion not exact

File SensirionI2CScd4x.cpp, function readMeasurement() uses 65536.0 in the conversion formulas from temperature ticks to temperature degrees C and for humidity ticks to humidity RH.

The SCD4x Datasheet Table 11 in section 3.5.2 says to use "2^16 - 1" which would be 65535.0.

Error trying to execute readMeasurement()

Hello everyone,

I'm having a problem using this library with the arduino nano as shown in the image below:

image

Here is an exemple of the code:

#include <Arduino.h>
#include <SensirionI2CScd4x.h>
#include <Wire.h>

SensirionI2CScd4x scd4x;

void printUint16Hex(uint16_t value) {
    Serial.print(value < 4096 ? "0" : "");
    Serial.print(value < 256 ? "0" : "");
    Serial.print(value < 16 ? "0" : "");
    Serial.print(value, HEX);
}

void printSerialNumber(uint16_t serial0, uint16_t serial1, uint16_t serial2) {
    Serial.print("Serial: 0x");
    printUint16Hex(serial0);
    printUint16Hex(serial1);
    printUint16Hex(serial2);
    Serial.println();
}

void setup() {

    Serial.begin(115200);
    while (!Serial) {
        delay(100);
    }

    Wire.begin();

    uint16_t error;
    char errorMessage[256];

    scd4x.begin(Wire);

    // stop potentially previously started measurement
    error = scd4x.stopPeriodicMeasurement();
    if (error) {
        Serial.print("Error trying to execute stopPeriodicMeasurement(): ");
        errorToString(error, errorMessage, 256);
        Serial.println(errorMessage);
    }

    uint16_t serial0;
    uint16_t serial1;
    uint16_t serial2;
    error = scd4x.getSerialNumber(serial0, serial1, serial2);
    if (error) {
        Serial.print("Error trying to execute getSerialNumber(): ");
        errorToString(error, errorMessage, 256);
        Serial.println(errorMessage);
    } else {
        printSerialNumber(serial0, serial1, serial2);
    }

    // Start Measurement
    error = scd4x.startPeriodicMeasurement();
    if (error) {
        Serial.print("Error trying to execute startPeriodicMeasurement(): ");
        errorToString(error, errorMessage, 256);
        Serial.println(errorMessage);
    }

    Serial.println("Waiting for first measurement... (5 sec)");
}

void loop() {
    uint16_t error;
    char errorMessage[256];

    delay(100);

    // Read Measurement
    uint16_t co2 = 0;
    float temperature = 0.0f;
    float humidity = 0.0f;
    bool isDataReady = false;
    error = scd4x.getDataReadyStatus(isDataReady);
    if (error) {
        Serial.print("Error trying to execute getDataReadyFlag(): ");
        errorToString(error, errorMessage, 256);
        Serial.println(errorMessage);
        return;
    }
    if (!isDataReady) {
        return;
    }
    error = scd4x.readMeasurement(co2, temperature, humidity);
    if (error) {
        Serial.print("Error trying to execute readMeasurement(): ");
        errorToString(error, errorMessage, 256);
        Serial.println(errorMessage);
    } else if (co2 == 0) {
        Serial.println("Invalid sample detected, skipping.");
    } else {
        Serial.print("Co2:");
        Serial.print(co2);
        Serial.print("\t");
        Serial.print("Temperature:");
        Serial.print(temperature);
        Serial.print("\t");
        Serial.print("Humidity:");
        Serial.println(humidity);
    }
}

Can you help me ?

Integration issue of SCD41 with ESP32 board from Heltec

The exampleUsage.ino code supplied by Sensirion works perfectly on the Heltec WiFi Kit 32 (ESP32) board. I can receive correct sensor data via COM port.

However, when I tried to display the sensor reading on the local OLED display by adding a few line of the code in the setup:
Heltec.display->init();
Heltec.display->flipScreenVertically();
Heltec.display->setFont(ArialMT_Plain_10);
Heltec.display->clear();
Heltec.display->drawString(0, 0, "SCD41 CO2 V100");
Heltec.display->display();

The OLED shows the correct display, but I can no longer receive correct data on my COM port. Instead I got the following error message:
Error trying to execute readMeasurement(): Received NACK on transmit of address_

The IIC address of SCD41 is 0x62. The IIC address for SSD1306 OLED is 0x3C. No conflict here.

Any ideas or suggestions on how to resolve this problem?

Documentation error, bad information for getDataReadyStatus

In the process of debugging the FRC library error - previous issue, I implemented scd4x.getDataReadyStatus(dataRdy);
The .h file says * @param dataReady If last 11 bits are 0 data not ready, else data ready
So I implemented this but it didn't work. Printing out the dataReady byte shows that a value of 0x8006 indicates valid data. When the FRC command failed, I would get results of 8000 and 0, but in both cases, the data was bad.
I don't really know what to test for because I don't know if the 0x8006 is stable. Could some of the other bits change and still be valid? For now, I'm just checking for 11 zeroes after the leading bit because that's closest to what the documentation says but it's misleading.

Linus's Law, which states that “given enough eyeballs, all bugs are shallow. Cathedral and Bazaar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.