Need some help with ADT7420 data and communication with NRF24L01

Hey guys, here me again with another problem i couldn't solve. This time i made work almost everything but in this case i have the big problem of how to send the data that i receive from my artyx 7 FPGA, more especifically the data that send the adt7420 of the artyx 7, i can show the data of the adt7420 with the LCD, i can show the data of both sensors MQ7 and MG811, but the problem is i can't send the data of the ADT7420 to other arduino using NRF24L01, it sends me 0. I don't know where i am wrong so i come to you for help

Here is my code for the transmitter where the sensors and my FPGA is connected:

#include "CO2Sensor.h"
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include "MQ7.h"
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <avr/io.h>
#include <avr/interrupt.h>

//Declaramos las partes de temperatura
int integerPart;
float fractionalPart;
//Declaremos los pines CE y el CSN
const int pinCE = 9;
const int pinCSN = 10;
//creamos el objeto radio (NRF24L01)
RF24 radio(pinCE, pinCSN);

//Variable con la dirección del canal por donde se va a transmitir
// Single radio pipe address for the 2 nodes to communicate.
const uint64_t pipe = 0xE8E8F0F0E1LL;

//vector con los datos a enviar
float datos[4];

//Declaramos caracteristicas para el LCD
LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display

//Declaramos sensor CO2 MG811
CO2Sensor co2Sensor(A1, 0.99, 100);

//Declaramos pines sensor CO MQ7
#define A_PIN 2
#define VOLTAGE 5

// init MQ7 device
MQ7 mq7(A_PIN, VOLTAGE);

//Declaramos valores provenientes del FPGA y valor para interrupcion
volatile byte lowerByte = 0;
volatile byte upperByte = 0;
volatile bool dataReady = false;

void setup() {
  
  //inicializamos el NRF24L01 
  radio.begin();
  
  //Abrimos un canal de escritura
  radio.openWritingPipe(pipe);
  
  //Inicializamos el LCD
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Temp: ");
  lcd.setCursor(0, 1);
  lcd.print("CO2:");
  lcd.setCursor(9, 1);
  lcd.print("CO:"); 

  //Inicializamos los sensores
  Serial.begin(9600);
  co2Sensor.calibrate();
  mq7.calibrate();		// calculates R0

  // UART setup
  unsigned int ubrr1 = F_CPU / 16 / 9600 - 1;  // Calculate UBRR value for 9600 baud
  UBRR1H = (ubrr1 >> 8);
  UBRR1L = ubrr1;
  UCSR1B = (1 << RXEN1) | (1 << RXCIE1);  // Enable receiver and RX interrupt
  UCSR1C = (1 << UCSZ11) | (1 << UCSZ10); // 8 data bits, no parity, 1 stop bit
}

void loop() {
  int val = co2Sensor.read();
  lcd.setCursor(4, 1);
  lcd.print(val);

  lcd.setCursor(12,1);
  lcd.print(mq7.readPpm()); 
  // Check if data is ready to be processed
  if (dataReady) {
    // Combine the two bytes into a 12-bit value
    int combinedValue = (lowerByte << 4) | upperByte;
    combinedValue &= 0x0FFF; // Mask to ensure only 12 bits

    // Calculate integer and fractional parts
    int integerPart = (combinedValue >> 4) & 0xFF;  // The upper 8 bits
    float fractionalPart = (combinedValue & 0x0F) * 0.0625; // The lower 4 bits multiplied by 0.0625
    
    // Print the temperature on the LCD
    lcd.setCursor(6, 0); // Move cursor to start of temperature display
    lcd.print(integerPart);
    lcd.print(".");
    lcd.print(fractionalPart * 10000, 0); // Print fractional part as an integer (multiplied by 100 for 2 decimal places)

    // Print other values
    //int parteentera = integerPart;
    //float partedecimal = fractionalPart;
    // Reset the flag
    dataReady = false;
  }
  //cargamos los datos en la variable datos[]
  datos[0]=val;;
  datos[1]=mq7.readPpm();;
  datos[2]=integerPart;
  datos[3]=fractionalPart;
  // datos[2]=integerPart.fractionalPart;;
  //enviamos los datos
  bool ok = radio.write(datos, sizeof(datos));
   if(ok)
  {
     Serial.print("Datos enviados: "); 
     Serial.print(datos[0]); 
     Serial.print(" , "); 
     Serial.print(datos[1]); 
     Serial.print(" , "); 
     Serial.print(datos[2]);
     Serial.print("."); 
     Serial.println(datos[3] * 10000, 0);
  }
  else
  {
     Serial.println("no se ha podido enviar");
  }
  delay(1000);
}

// ISR for receiving UART data
ISR(USART1_RX_vect) {
  static bool receivingUpperByte = false;

  // Read the received byte from the USART Data Register
  byte receivedByte = UDR1;

  if (!receivingUpperByte) {
    // Store the lower byte
    lowerByte = receivedByte;
    receivingUpperByte = true;
  } else {
    // Store the upper byte and set the flag to indicate data is ready
    upperByte = receivedByte;
    receivingUpperByte = false;
    dataReady = true;
  }
}

And here is the code for my receiver where is connected the NRF24L01 and a LCD:

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

//Declaremos los pines CE y el CSN
const int pinCE = 9;
const int pinCSN = 10;

//Variable con la dirección del canal que se va a leer
const uint64_t pipe = 0xE8E8F0F0E1LL;

//creamos el objeto radio (NRF24L01)
RF24 radio(pinCE, pinCSN);

//vector para los datos recibidos
float data[4];

//Declaramos caracteristicas para el LCD
LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup() {
  //inicializamos el NRF24L01 
  radio.begin(); 
  
  //Abrimos el canal de Lectura
  radio.openReadingPipe(1, pipe);
  
  //empezamos a escuchar por el canal
  radio.startListening();

  //Inicializamos el LCD
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Temp: ");
  lcd.setCursor(0, 1);
  lcd.print("CO2:");
  lcd.setCursor(9, 1);
  lcd.print("CO:"); 
}

void loop() {
 //if ( radio.available(&numero_canal) )
 if ( radio.available() )
 {    
    //Leemos los datos y los guardamos en la variable datos[]
    radio.read(data, sizeof data);
    Serial.print("CO2= " );
    Serial.print(int(data[0]));
    Serial.print("CO= " );
    Serial.print(data[1]);
    Serial.print("Temperatura: ");
    Serial.print(data[2]);
    Serial.print(".");
    Serial.println(data[3] * 10000, 0);
     //reportamos por el LCD los datos recibidos 

 }
    
    lcd.setCursor(4, 1);
    lcd.print(int(data[0]));

    lcd.setCursor(12,1);
    lcd.print(data[1]);

    lcd.setCursor(6, 0); // Move cursor to start of temperature display
    lcd.print(data[2]);
    lcd.print(".");
    lcd.print(data[3] * 10000, 0); // Print fractional part as an integer (multiplied by 100 for 2 decimal places)

    
 delay(1000);

}

I appreciate your help

There is a nrf24-tutorial written by user robin2 that explains quite a lot

Most problems are power-problems

You should check your hardware with a very simple nrf24-demo-code to make sure that your hardware is working like it should

ty for your reply, i previously check about power supply, and my NRF24L01 sends the data of my sensors MQ7 and MG811 so it is not the NRF, even i ckeck now, and it is not i can't send data, the data becomes 0 and i dont know why xD, it only sends 0 when it is supposed to send the data of my adt7420

still way too less details for analysing.

post the complete sketch that does send and receive data successfully from your MQ7 MG811-sensors

post the sketch that tries to send data from your adt7420

For debugging print to the serial monitor all variable-values that are related to sending the data

What looks strange to me is you are setting up details for UART

  // UART setup
  unsigned int ubrr1 = F_CPU / 16 / 9600 - 1;  // Calculate UBRR value for 9600 baud
  UBRR1H = (ubrr1 >> 8);
  UBRR1L = ubrr1;
  UCSR1B = (1 << RXEN1) | (1 << RXCIE1);  // Enable receiver and RX interrupt
  UCSR1C = (1 << UCSZ11) | (1 << UCSZ10); // 8 data bits, no parity, 1 stop bit

I never had the need to code something like this

For what do you need the USART ISR?

// ISR for receiving UART data
ISR(USART1_RX_vect) {
  static bool receivingUpperByte = false;

  // Read the received byte from the USART Data Register
  byte receivedByte = UDR1;

  if (!receivingUpperByte) {
    // Store the lower byte
    lowerByte = receivedByte;
    receivingUpperByte = true;
  } else {
    // Store the upper byte and set the flag to indicate data is ready
    upperByte = receivedByte;
    receivingUpperByte = false;
    dataReady = true;
  }
}

usually send / receive serial data works without such lines of code

TY, it is because the ADT 7420 from Artyx 7 use 16 bits, and that ISR is for giving time for the FPGA to process the data of the ADT7420 and then send, I need that arrangement to separate the bits of data of the Artyx to extract the bits of important information of the temperature, and why i configure the USART? it is because if i use an UART library it doesn't work properly, that is why i configure the USART 1 of my arduino MEGA manually

You are writing very confusing.
Is Artyx 7 the company that manufactures the ADT7420-chip?

Why the heck does a code running on the Arduino that receives data
give an FPGA time to process the data which comes from the ADT7420??

From your comments I conclude that your native language is spanish.

I suggest that you write your explanation very detailed in spanish and then let do the website deepL the translation to english

Still I don't have any clue where you send the ADT7420-data
There is only one line of code that seems to send MQ7-data which is this one

  //enviamos los datos
  bool ok = radio.write(datos, sizeof(datos));

Lo siento por no poder responderte, @StefanL38, ya pude resolver mi problema. El problema era mi código, no estaba ordenado de la manera adecuada y por eso no enviaba los datos del ADT7420 del FPGA. Ya lo pude resolver y ahora los datos del FPGA los recibo, tanto en el transmisor como en el receptor.

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