Error when trying to use another library with mysensors



  • Hello, I am new to mysensors. I have success created my first sensor. It is CCS811 CO2 sensor connected to arduino pro mini. To the mini there is also connected RF24 radio. CO2 sensor and the radio share VCC pin.

    For the sensor I found a library (https://github.com/maarten-pennings/CCS811) that allows to easily interact with the sensor. If I upload example sketch to the pro mini everything works fine. In the serial monitor I can see the readings from the sensor. If I do the same for the passive node example in order to test my radio, everything works fine and my serial gateway receives messages from my pro mini. However, when I try to combine the two sketches I run into issues.

    Basically once I include my sensors library together with CCS811 library the latter fails to setup and gives an error through serial ("ccs811: ping failed (VDD/GND connected? SDA/SCL connected?)"). Upon closer inspection of the CCS811 library, it seems, that the only reason can be that the function i2cwrite fails. Why does it fail with mysensors library included? What am i doing wrong?

    Here is the sketch I am trying to use that fails with above described error:

    /*
      ccs811basic.ino - Demo sketch printing results of the CCS811 digital gas sensor for monitoring indoor air quality from ams.
      Created by Maarten Pennings 2017 Dec 11
    */
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    // Enable encryption
    #define MY_RF24_ENABLE_ENCRYPTION
    #define MY_SECURITY_SIMPLE_PASSWD "testpassword123" 
    
    
    #include <MySensors.h> // MySensors Library
    #include <Wire.h>    // I2C library
    #include "ccs811.h"  // CCS811 library
    
    // using pin3 for nWake
    CCS811 ccs811(3); // nWAKE on 3
    
    
    #define CHILD_ID_AIQ 0
    
    uint32_t SLEEP_TIME = 1*1000; // Sleep time between reads (in milliseconds)
    
    float valAIQ =0.0;
    float lastAIQ =0.0;
    
    MyMessage msg(CHILD_ID_AIQ, V_LEVEL);
    MyMessage msg2(CHILD_ID_AIQ, V_UNIT_PREFIX);
    
    void setup() {
      // Enable serial
      Serial.begin(115200);
      Serial.println("");
      Serial.println("setup: Starting CCS811 basic demo");
      Serial.print("setup: ccs811 lib  version: "); Serial.println(CCS811_VERSION);
    
      // Enable I2C
      Wire.begin(); 
      
      // Enable CCS811
     // ccs811.set_i2cdelay(50); // Needed for ESP8266 because it doesn't handle I2C clock stretch correctly
      bool ok= ccs811.begin();
      if( !ok ) Serial.println("setup: CCS811 begin FAILED");
    
      // Print CCS811 versions
      Serial.print("setup: hardware    version: "); Serial.println(ccs811.hardware_version(),HEX);
      Serial.print("setup: bootloader  version: "); Serial.println(ccs811.bootloader_version(),HEX);
      Serial.print("setup: application version: "); Serial.println(ccs811.application_version(),HEX);
      
      // Start measuring
      ok= ccs811.start(CCS811_MODE_1SEC);
      if( !ok ) Serial.println("setup: CCS811 start FAILED");
    }
    
    void presentation()
    {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("AIQ Sensor CO2 CCS811", "1.0");
    
      // Register all sensors to gateway (they will be created as child devices)
      present(CHILD_ID_AIQ, S_AIR_QUALITY);
      send(msg2.set("ppm"));
    }
    void loop() {
      // Read
      uint16_t eco2, etvoc, errstat, raw;
      ccs811.read(&eco2,&etvoc,&errstat,&raw); 
      
      // Print measurement results based on status
      if( errstat==CCS811_ERRSTAT_OK ) { 
        if ((eco2 != lastAIQ)&&(abs(eco2-lastAIQ)>=10)) {
          send(msg.set((int32_t)ceil(eco2)));
          lastAIQ = ceil(eco2);
        }
        Serial.print("CCS811: ");
        Serial.print("eco2=");  Serial.print(eco2);     Serial.print(" ppm  ");
        Serial.print("etvoc="); Serial.print(etvoc);    Serial.print(" ppb  ");
        //Serial.print("raw6=");  Serial.print(raw/1024); Serial.print(" uA  "); 
        //Serial.print("raw10="); Serial.print(raw%1024); Serial.print(" ADC  ");
        //Serial.print("R="); Serial.print((1650*1000L/1023)*(raw%1024)/(raw/1024)); Serial.print(" ohm");
        Serial.println();
      } else if( errstat==CCS811_ERRSTAT_OK_NODATA ) {
        delay(1); 
        //Serial.println("CCS811: waiting for (new) data");
      } else if( errstat & CCS811_ERRSTAT_I2CFAIL ) { 
        Serial.println("CCS811: I2C error");
      } else {
        Serial.print("CCS811: errstat="); Serial.print(errstat,HEX); 
        Serial.print("="); Serial.println( ccs811.errstat_str(errstat) ); 
      }
      
      // Wait
      sleep(SLEEP_TIME); //sleep for: sleepTime
    }```


  • @un4 did you try it without the sleep function enabled?



  • How nWake connected? Is it connected to pin or gnd?
    I've also just did node with ccs811 sensor, but i've used SparkFunCCS811 library.



  • @krabbi I have a similar issue as un4 described.
    When nWake is connected on GND it works fine, when connecting to D3 (6) it stops working. I'm using the same sketch source as krabbi. Any suggestions?


Log in to reply
 

Suggested Topics

  • 1
  • 6
  • 1
  • 2
  • 1
  • 3

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts