RF24 TWO ANALOG DATA TRANSFER

RF24 data tr

The code can be downloaded at:

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/RF24%20TWO%20DATA.zip

TRANSMITTER

#include <SPI.h>
#include “nRF24L01.h”
#include “RF24.h”

RF24 radio(8,7);

void setupRadio()
{
// Initiate the radio
radio.begin();

// Define the number of retries sending a packet
radio.setRetries(15,15);

// Define the radio’s broadcast channel (0 – 127)
radio.setChannel(30);

// Define the radio’s bitrate (using cards lowest bitrate)
radio.setDataRate(RF24_250KBPS);

// Define the radio’s power amplifier level (RF24_PA_MIN for debugging, RF24_PA_HIGH for longest range)
radio.setPALevel(RF24_PA_MIN);

// Enable dynamic payloads for packets
radio.enableDynamicPayloads();
}
struct package
{
int temperature ;
int humidity ;
};
typedef struct package Package;
Package data;
void setup()
{

setupRadio();

}

void loop()
{

data.temperature = analogRead(A0);
data.humidity = analogRead(A1);

// Open a writing pipe on the radio
radio.openWritingPipe(0xE8E8F0F0E1LL);

// Write the temperature to the pipe
radio.write(&data, sizeof(data));

}

RF24 data rcv

RECEIVER

#include <SPI.h>
#include “nRF24L01.h”
#include “RF24.h”

// — Global variables —

RF24 radio(8,7);
//int packetCounter = 0;

// — Functions —

void setupRadio()
{
// Initiate the radio
radio.begin();

// Define the number of retries sending a packet
radio.setRetries(15,15);

// Define the radio’s broadcast channel (0 – 127)
// Must be the same on the sensor and the master node
radio.setChannel(30);

// Define the radio’s bitrate (using cards lowest bitrate)
radio.setDataRate(RF24_250KBPS);

// Define the radio’s power amplifier level (RF24_PA_MIN for debugging, RF24_PA_HIGH for longest range)
radio.setPALevel(RF24_PA_MIN);

// Enable dynamic payloads for packets
radio.enableDynamicPayloads();

// Open reading pipe
radio.openReadingPipe(1, 0xE8E8F0F0E1LL);

// Start listening for packets
radio.startListening();
}
struct package
{
int temperature ;
int humidity ;
};
typedef struct package Package;
Package data;
void setup()
{
// Initiate serial connection
Serial.begin(9600);

// RF Radio setup
setupRadio();
}

void loop()
{
// Check if the radio has received any data
if(radio.available()) {
//int temperature = 0;

// Read the packet received into the temperature variable
if(!radio.read(&data, sizeof(data))) {
// The sensor did not receive the ACK packet
//Serial.println(“ACK not received by client.”);
}

// Print the temperature
Serial.print(data.temperature);
Serial.print(” “);
Serial.println(data.humidity);

// Wait for serial print to complete
delay(1000);
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s