Problemas con inicialización css811

tengo un proyecto con FreeRTOs,es un contador de personas. Cuando la puerta está cerrada y hay personas dentro de la sala, se leen determinados sensores, tengo problemas con el CSS811 que no me hace lecturas.

void todasTareas(void *parameter) {

  const int minutosCO2 = 30;          // 30 segundos
                                    
  

  // // Convertir a ticks (FreeRTOS usa milisegundos por defecto)
  const TickType_t intervaloCO2 = (minutosCO2 * 1000) / portTICK_PERIOD_MS;
  

  TickType_t tiempoAnteriorCO2 = xTaskGetTickCount();
 
  for (;;) {
  
    MagneticReed();  // Siempre activo

    if (estadoPuerta == 0 && counter > 0) {
      
      TickType_t ahora = xTaskGetTickCount();

           if (ahora - tiempoAnteriorCO2 >= intervaloCO2) {
       
            sensorCo2();
           tiempoAnteriorCO2 = ahora;
           }
    

     
        
    }
    vTaskDelay(50 / portTICK_PERIOD_MS);  // Delay de cada ciclo del loop
  }
}

void sensorCo2(void) {
  float humedad;


  if (xSemaphoreTake(i2cMutex, portMAX_DELAY)) {
    humedad = dht.readHumidity();  //Leemos la Humedad
    if (humedad != humdadAnterior) {
      ccs.setEnvironmentalData(humedad, t);
      humdadAnterior = humedad;
    }

    while (!ccs.available());


      if (!ccs.readData()) {
        ppm = ccs.geteCO2();
        Serial.println("Co2 ");
        Serial.println(ppm);
      } else {
        Serial.println("Error al leer del sensor CCS811");
      }
    }
    xSemaphoreGive(i2cMutex);
  }

Intenta ponerte en nuestro lugar y dime si con la información que das alguien puede entenderte.

tienes toda la razón, cuando el magneticreed esta cerrado está siempre esperando a que esté listo el sensor, pero cuando abro el magnetic aparece la lectura y no quiero eso quiero que lea cuando este el magnetic cerrado.

#include "Adafruit_CCS811.h"
#include <Wire.h>

Adafruit_CCS811 ccs;
const int PinInterrupcion = 2;
float ppm = 0;
int estadoPuerta = 0;

int estadoAnterior = 0;            // Estado del pin en la lectura anterior
unsigned long tiempoAnterior = 0;  // Tiempo de la última lectura

 SemaphoreHandle_t i2cMutex;

void sensorCo2(void);  // Declaración
void MagneticReed(void);  // Declaración





void setup() {
  Serial.begin(9600);

i2cMutex = xSemaphoreCreateMutex();

   



  // // inicialización I2C
  Wire.begin();
  delay(500);

  // inicializacion c02
  Serial.println("inicializar co2");
  if (!ccs.begin()) {
    Serial.println("sensor de co2 no inicializa.");
 
  }


  // Wait for the sensor to be ready
   while (!ccs.available()){
    delay(500);
    Serial.println("Esperando que el sensor esté listo...");
   }

  Serial.println("Sensor CCS811 listo.");



  

 
  pinMode(PinInterrupcion, INPUT_PULLUP);

  xTaskCreatePinnedToCore(todasTareas, "TareasSecuenciales", 8192, NULL, 1, NULL, 1);
}

void loop() {}

void todasTareas(void *parameter) {



  const int minutosCO2 = 3;          // 3 minuto
                                   
  
   // Convertir a ticks (FreeRTOS usa milisegundos por defecto)
  const TickType_t intervaloCO2 = (minutosCO2 * 1000) / portTICK_PERIOD_MS;
  
  TickType_t tiempoAnteriorCO2 = xTaskGetTickCount();


  for (;;) {
 
    MagneticReed();  // Siempre activo

    if (estadoPuerta == 0 ) {
      
      TickType_t ahora = xTaskGetTickCount();

          if (ahora - tiempoAnteriorCO2 >= intervaloCO2) {
            //Serial.println("Co2 ");
           sensorCo2();
            tiempoAnteriorCO2 = ahora;
          }
    }
    vTaskDelay(50 / portTICK_PERIOD_MS);  // Delay de cada ciclo del loop
  }
}

void MagneticReed(void) {


  bool estadoPuertaActual = digitalRead(PinInterrupcion);
  unsigned long tiempoActual = millis();
 


  if (estadoPuertaActual != estadoAnterior) {
    tiempoAnterior = millis();
    estadoAnterior = estadoPuertaActual;
  }

  if (tiempoActual - tiempoAnterior > 200) {  // rebotes

    estadoPuerta = estadoPuertaActual;
    
       
     }
}

void sensorCo2(void) {
 

  Serial.print("entro en co2 ");
  if (xSemaphoreTake(i2cMutex, portMAX_DELAY)) {
  
   


       while (!ccs.available()){
    delay(500);
    Serial.println("Esperando que el sensor esté listo...");
   }
      if (!ccs.readData()) {
       ppm = ccs.geteCO2();
        Serial.print("CO2: ");
        Serial.println(ppm);
      } else {
        Serial.println("Error leyendo el CCS811");
      }
    

    }
    
    
    xSemaphoreGive(i2cMutex);
  }



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