Error with transmitter and receiver

Ok so basically what I am doing is reading data from the joystick connection to a nano and sending it through nRF24L01 (PA) and sending to arduino uno with just a nRF24L01 I am able to send my data but the output I get out of my uno is 192 for all values. but the output for the values in nano is correct. I tried a lot but couldn't understand the problem.

Transmitter code

#define Pitch A0
#define Roll A1
#define Yaw A2

int pitch;
int roll;
int yaw;

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

RF24 radio(7, 8); // CE CSN
const byte Address[6] = "00009";

void setupTransmitter(void)
{
  radio.begin();
  radio.openWritingPipe(Address);
  radio.setPALevel(RF24_PA_MAX);
  radio.stopListening(); // set as transmitter
  Serial.println("Transmitting");
}

void sendData(int *pPitch, int *pRoll, int *pYaw)
{
  radio.write(pPitch, sizeof(*pPitch));
  radio.write(pRoll, sizeof(*pRoll));
  radio.write(pYaw, sizeof(*pYaw));
  Serial.print("Transmitting Data : ");
  delay(1000);
}

void readJoysticks(int *pPitch, int *pRoll, int *pYaw)
{
  *pPitch = analogRead(Pitch);
  *pRoll = analogRead(Roll);
  *pYaw = analogRead(Yaw);

  Serial.print("Pitch: ");
  Serial.print(*pPitch);
  Serial.print("Roll: ");
  Serial.print(*pRoll);
  Serial.print("Yaw: ");
  Serial.print(*pYaw);
  Serial.println();
}

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(115200);

  setupTransmitter();
}

void loop()
{
  // put your main code here, to run repeatedly:
  readJoysticks(&pitch, &roll, &yaw);
  sendData(&pitch, &roll, &yaw);
}

Reciever Code



int pitch;
int roll;
int yaw;

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

RF24 radio(7, 8); // CE, CSN
const byte Address[6] = "00009";

void setupReciever()
{
  radio.begin();
  radio.openReadingPipe(1, Address);
  radio.setPALevel(RF24_PA_MAX);
  radio.startListening();
  Serial.println("Setup Reciever Done");
}

void recieveData(int *pPitch, int *pRoll, int *pYaw)
{
  if (radio.available())
  {
    Serial.println("Listened");
    radio.read(pPitch, sizeof(*pPitch));
    radio.read(pRoll, sizeof(*pRoll));
    radio.read(pYaw, sizeof(*pYaw));
    Serial.println("Received Data : ");
    Serial.print("Pitch: ");
    Serial.print(pitch);
    Serial.print(" Roll: ");
    Serial.print(roll);
    Serial.print(" Yaw: ");
    Serial.print(yaw);
    Serial.println();
    delay(1000);
  }
  else
  {
    Serial.println("Not listening");
  }
}

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(115200);
  setupReciever();
}

void loop()
{
  // put your main code here, to run repeatedly:
  recieveData(&pitch, &roll, &yaw);
}

Welcome to the forum

Try the examples in url=Simple nRF24L01+ 2.4GHz transceiver demo - Exhibition / Gallery - Arduino Forum]Simple nRF24L01+ 2.4GHz transceiver demo[/url]

Most problems with NRF24 reported here are caused by inadequate power supplies. How are yours powered ?

You are using 3 writes to send the data and 3 reads to receive. That is not optimal. Put the 3 data points into an array or struct and send with 1 write and 1 receive on the other end.

Here is my (tested on real hardware) joystick send and receive code that uses a struct to send and receive the data from 2 joysticks. Adapt as necessary (mind the CE and CSN pins).

Sender code:

// joystick send by groundFungus aka c.goulding
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>


const byte CE_PIN = 9;
const byte CSN_PIN = 10;

const byte slaveAddress[5] = {'R', 'x', 'A', 'A', 'A'};


RF24 radio(CE_PIN, CSN_PIN); // Create a Radio

struct JoyValues
{
   int joy1x;
   int joy1y;
   int joy2x;
   int joy2y;
} joyValues;

unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1000; // send once per second

const byte joy1xPin = A0;
const byte joy1yPin = A1;
const byte joy2xPin = A2;
const byte joy2yPin = A3;

void setup()
{

   Serial.begin(115200);
   Serial.println("SimpleTx Starting");

   radio.begin();
   radio.setChannel(76);  //76 library default
   //RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH and RF24_PA_MAX
   radio.setPALevel(RF24_PA_HIGH);
   radio.setDataRate( RF24_250KBPS );
   radio.setRetries(3, 5); // delay, count
   radio.openWritingPipe(slaveAddress);
   radio.stopListening();
}

void loop()
{
   currentMillis = millis();
   if (currentMillis - prevMillis >= txIntervalMillis)
   {
      send();
      Serial.print("JOY 1 X = ");
      Serial.print( joyValues.joy1x);
      Serial.print("  JOY 1 Y = ");
      Serial.print( joyValues.joy1y);
      Serial.print("  JOY 2 X = ");
      Serial.print( joyValues.joy2x);
      Serial.print("  JOY 2 Y = ");
      Serial.println( joyValues.joy2y);
      prevMillis = millis();
   }
}

//====================

void send()
{
   joyValues.joy1x = analogRead(joy1xPin);
   joyValues.joy1y = analogRead(joy1yPin);
   joyValues.joy2x = analogRead(joy2xPin);
   joyValues.joy2y = analogRead(joy2yPin);
   radio.write( &joyValues, sizeof(joyValues) );
}

receiver code:



// SimpleRx - the slave or the receiver

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

const byte CE_PIN = 9;
const byte CSN_PIN = 10;

const byte thisSlaveAddress[5] = {'R', 'x', 'A', 'A', 'A'};

RF24 radio(CE_PIN, CSN_PIN);

struct JoyValues
{
  int joy1x;
  int joy1y;
  int joy2x;
  int joy2y;
}joyValues;

bool newData = false;

//===========

void setup()
{

   Serial.begin(115200);

   Serial.println("SimpleRx Starting");

   radio.begin();
   radio.setChannel(76);  //76 library default
   //RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH and RF24_PA_MAX
   radio.setPALevel(RF24_PA_HIGH);
   radio.setDataRate( RF24_250KBPS );
   radio.openReadingPipe(1, thisSlaveAddress);
   radio.startListening();
}

//=============

void loop()
{
   getData();
   showData();
}

//==============

void getData()
{
   if ( radio.available() )
   {
      radio.read( &joyValues, sizeof(joyValues) );
      newData = true;
   }
}

void showData()
{
   if (newData == true)
   {
      Serial.print("Data received >> ");
      Serial.print("JOY 1 X = ");
      Serial.print( joyValues.joy1x);
      Serial.print("  JOY 1 Y = ");
      Serial.print( joyValues.joy1y);
      Serial.print("  JOY 2 X = ");
      Serial.print( joyValues.joy2x);
      Serial.print("  JOY 2 Y = ");
      Serial.println( joyValues.joy2y);
      newData = false;
   }
}

I do not understand that. Why the *?


This is what i am getting at the reciever end

On my end, as I said, the code tests fine on real hardware.

Did you change the pins (analog inputs, CE, CSN) to match your setup?

The point of sharing my code was to show how to use the struct to make a data packet so that only one send and one receive are necessary.

How many LEDs are you driving and what circuit are you using to multiplexing them?

Yes but now it is just sending 0, 0, 0 on the reciever end

Then you have a hardware or power problem.

In Robin2's simple rf24 tutorial in post #30 there is a sketch to check the hardware connection between each radio module and its attached processor (Arduino). Run that sketch for each module and post the results.

How is each radio module powered? Post a schematic or wiring diagram.

Hi, @nuclearzzet
Welcome to the forum.

Can you please post some images of your project?
So we can see your component layout.

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

These require a decent power supply, and some supply filtering to perform properly, especially the units with PA (Power Amplifier), fitted.

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

The higher power radios (external antenna) may not comminicate if too close together. Try moving them a few meters apart and/or reduce transmitter power.

Ok. I will try so I guess that is the problem

sure I will post it as soon as possible

Hi @TomGeorge,
You said about giving decent power supply and supply filtering at the moment the supply to it is from my PC and laptop. The receiver power supply will soon be switched into a 3 cell Li-Po battery
Thanks nuclear

Actually maybe true because when I first used the code you gave it worked perfectly then I changed the position of the modules maybe that is the problem

I don't have a schematic.

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