Nrf24l01 não esta recebendo dados do MQ135

Bom, eu estou tentando fazer um projeto que 2 arduinos uno trabalhem juntos, um transmitindo os dados e outro recebendo, estou usando em ambos o nrf24l01, e no emissor um sensor MQ135, bmp180 e um MPU-6050
No código o receptor consegue receber os dados do bmp180 e do mpu6050 mas não do mq135, alguém consegue dar um help? (sou iniciante)

Emissor:

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include <Wire.h> 
#include <Adafruit_BMP085.h>
Adafruit_BMP085 bmp;
#include <MQUnifiedsensor.h>

#define placa "Arduino UNO"
#define Voltage_Resolution 5
#define pin A0 
#define type "MQ-135" 
#define ADC_Bit_Resolution 10 
#define RatioMQ135CleanAir 3.6 

MQUnifiedsensor MQ135(placa, Voltage_Resolution, ADC_Bit_Resolution, pin, type);
Adafruit_BMP085 BMP180;


RF24 radio(9,10);  // make sure this corresponds to the pins you are using
const uint64_t pipes[2] = { 
  0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

const int led = 0;

const int MPU=0x68;
int AccelX2,AccelY2,AccelZ2;



typedef struct{
  float Temperatura1;
  float Altitude1;
  float ATM1;
  float AccelX1;
  float AccelY1;
  float AccelZ1;
  float CO1;
  float Alcohol1;
  float CO21;
  float Tolueno1;
  float NH41;
  float Acetona1;}
A_t;

typedef struct{
  int Temperatura2;
  float Altitude2;
  float ATM2;
  float AccelX2;
  float AccelY2;
  float AccelZ2;
  float CO;
  float Alcohol;
  float CO2;
  float Tolueno;
  float NH4;
  float Acetona;
}
B_t;

A_t Cansat1;  
B_t Cansat2; 

void setup()
{
  Serial.begin(9600);
  Wire.begin();
  Wire.beginTransmission(MPU);
  Wire.write(0x6B); 
  MQ135.setRegressionMethod(1);
  MQ135.init(); 
   
  //Inicializa o MPU-6050
  Wire.write(0); 
  Wire.endTransmission(true);
  bmp.begin();
  pinMode(led, OUTPUT);
  radio.begin();
  radio.openWritingPipe(pipes[0]);
  radio.openReadingPipe(1,pipes[1]);



  float calcR0 = 0;
  for(int i = 1; i<=10; i ++)
  {
    MQ135.update(); 
    calcR0 += MQ135.calibrate(RatioMQ135CleanAir);
    Serial.print(".");
  }
  MQ135.setR0(calcR0/10);
  
  if(isinf(calcR0)) 
  if(calcR0 == 0);
  
}

void loop(void)
{

  Wire.beginTransmission(MPU);
  Wire.write(0x3B);  
  Wire.endTransmission(false);
  Wire.requestFrom(MPU,14,true);
  AccelX2=Wire.read()<<8|Wire.read();     
  AccelY2=Wire.read()<<8|Wire.read(); 
  AccelZ2=Wire.read()<<8|Wire.read();
  
  
  Cansat2.Temperatura2 = bmp.readTemperature();
  Cansat2.Altitude2 = bmp.readAltitude();
  Cansat2.ATM2 = bmp.readSealevelPressure()/100;
  Cansat2.AccelX2 = AccelX2;
  Cansat2.AccelY2 = AccelY2;
  Cansat2.AccelZ2 = AccelZ2;
  Cansat2.CO = MQ135.readSensor(); MQ135.setA(605.18); MQ135.setB(-3.937);
  Cansat2.Alcohol = MQ135.readSensor(); MQ135.setA(77.255); MQ135.setB(-3.18); 
  Cansat2.Tolueno = MQ135.readSensor(); MQ135.setA(44.947); MQ135.setB(-3.445);
  Cansat2.NH4 = MQ135.readSensor(); MQ135.setA(102.2 ); MQ135.setB(-2.473); 
  Cansat2.Acetona = MQ135.readSensor(); MQ135.setA(34.668); MQ135.setB(-3.369); 
  Cansat2.CO2 = MQ135.readSensor(); MQ135.setA(110.47); MQ135.setB(-2.862); 


  bool ok = radio.write( &Cansat2, sizeof(Cansat2) );
  
  radio.write( &Cansat2, sizeof(Cansat2) );

}

Receptor:

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"

typedef struct{
  int Temperatura2;
  float Altitude2;
  float ATM2;
  float AccelX2;
  float AccelY2;
  float AccelZ2;
  float CO;
  float Alcohol;
  float CO2;
  float Tolueno;
  float NH4;
  float Acetona;
}
B_t;
 
B_t Cansat2;

RF24 radio(9,10);   
const uint64_t pipes[2] = { 
  0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

void setup()
{
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(pipes[1]);
  radio.openReadingPipe(1,pipes[0]);
  radio.startListening();
}

void loop(void)
{ 
  if ( radio.available() )
  {
    bool done = false;
    while (!done)
    {
      done = radio.read( &Cansat2, sizeof(Cansat2) );
    }
    radio.stopListening();
  }

  Serial.println("  "); 
  Serial.println("       Resultados do HélioSat");
  Serial.println("  ---------------------------------"); 
  Serial.print("|   Temperatura:         "); Serial.print(Cansat2.Temperatura2);Serial.println("°");
  Serial.print("|   Altitude:            "); Serial.println(Cansat2.Altitude2);
  Serial.print("|   Pressão Atmosférica: "); Serial.println(Cansat2.ATM2);
  Serial.print("|   AcX:                 "); Serial.println(Cansat2.AccelX2);
  Serial.print("|   AcY:                 "); Serial.println(Cansat2.AccelY2);
  Serial.print("|   AcZ:                 "); Serial.println(Cansat2.AccelZ2);
  Serial.print("|   Monóxido de carbono: "); Serial.println(Cansat2.CO); 
  Serial.print("|   Álcool:              "); Serial.println(Cansat2.Alcohol);
  Serial.print("|   Dióxido de carbono:  "); Serial.println(Cansat2.CO2 + 400); 
  Serial.print("|   Tolueno:             "); Serial.println(Cansat2.Tolueno); 
  Serial.print("|   Amónio:              "); Serial.println(Cansat2.NH4); 
  Serial.print("|   Acetona:             "); Serial.println(Cansat2.Acetona);
  Serial.println("  ---------------------------------"); 
  Serial.println("  "); 
  
  delay(4000); 
}

The NRF24L01 has a maximum packet size of 32.

You try to send 12 floats, sizeof(Cansat2) is 48.

1 Like