Module nrf24L01 problem

Hello guys, I was using two nrf24L01 module and two arduino UNO R3 SMD to transmit and receive the value of the X axis and Yaxis of the joystick but it keeps receiving 0 values and then when i unplug it from the computer it doesnt transmit anymore. I'm pretty sure that the wire hook up is ok and here is my code:
Transmitter code:

#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
RF24 radio(7, 8);
const byte address[1]="00001";

byte msg[3];

void setup() {
  // put your setup code here, to run once:
radio.begin();
radio.setChannel(100);
radio.openWritingPipe(address);
radio.setDataRate(RF24_250KBPS);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}

void loop() {
  // put your main code here, to run repeatedly:

msg[0]=analogRead(A0);
msg[1]=analogRead(A2);
radio.write(&msg, sizeof(msg));
}

Receiver code:

#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>

byte msg[3];
RF24 radio(7, 8);
const byte address[1]="00001";




void setup() {
  // put your setup code here, to run once:
radio.begin();
radio.setPALevel(RF24_PA_MIN);
radio.setDataRate(RF24_250KBPS);
radio.setChannel(100);
radio.openReadingPipe(0, address);
radio.startListening();
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
if(radio.available()){
 

  radio.read(&msg, sizeof(msg));
  Serial.print(msg[0]);
  Serial.print(";");
  Serial.println(msg[1]);
  delay(200);
}
}

Pls help me i'm desperately need someone help and the pins on arduino is ok and i use an adapter module to make the connection more stable.

Don't you need this in your receiver as well...???

#include <SPI.h>

Have you tried this tested and proven method of making sure your hardware setup is correct and working Simple nRF24L01+ 2.4GHz transceiver demo - Exhibition / Gallery - Arduino Forum, Also have you got a 10uF cap close to the power supply pins ?
Are the modules been powered from the 3.3V Arduino board ?

You could try these codes that I posted in another topic and know they work.

TX code

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
//########################################
// Define all the input/output pins      #
//########################################
#define CE_PIN   7
#define CSN_PIN 8
#define POT_X A0
#define POT_Y A1
//#define POT_A A2
//#define POT_B A3

//########################################
// Set the transreiciver module          #
//########################################
RF24 radio(CE_PIN, CSN_PIN); // select  CSN  pin
const uint64_t pipeOut = 0xE8E8F0F0E1LL; // Define the transmit pipe

// The sizeof this struct should not exceed 32 bytes
// This gives us up to 32 8 bits channals
struct MyData {
  int Pot_X_channel;
  int Pot_Y_channel;
  // int Pot_A_channel;
  // int Pot_B_channel;

};

MyData data;

void resetData()
{
  //This are the start values of each channal
  // Throttle is 0 in order to stop the motors
  data.Pot_X_channel = 0;
  data.Pot_Y_channel = 0;
  // data.Pot_A_channel = 0; //Steer left signal
  // data.Pot_B_channel = 0;

}

void setup()
{
  Serial.begin(9600);
  radio.begin();
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.openWritingPipe(pipeOut);
  resetData();
  delay(200);
}


void loop()
{
  data.Pot_X_channel = analogRead(POT_X);
  data.Pot_Y_channel = analogRead(POT_Y);
  //data.Pot_A_channel = analogRead(POT_A);
  //data.Pot_B_channel = analogRead(POT_B);
  radio.write(&data, sizeof(MyData));
}

RX code

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
//#include <Servo.h>      // include the servo library But I dont have installed
//########################################
// Define all the input/output pins      #
//########################################
#define CE_PIN   7
#define CSN_PIN 8
const uint64_t pipeIn =  0xE8E8F0F0E1LL;//0xE8E8F0F0E1LL;
RF24 radio(CE_PIN, CSN_PIN);
unsigned long previousMillis = 0;        // will store last time LED was updated
const long interval = 1000;           // interval at which to blink (milliseconds)

//Servo servo1;
//Servo servo2;
unsigned long lastRecvTime = 0;
struct MyData {
  int Pot_X_channel_in;
  int Pot_Y_channel_in;
  // int Pot_A_channel_in;
  // int Pot_B_channel_in;
};

MyData data;

void resetData()
{
  Serial.println("LOST DATA/CONNECTION");

}
/**************************************************/
void setup()
{
  Serial.begin(9600);
  Serial.println("Nrf24L01 Receiver Starting");
  radio.begin();
  radio.setDataRate(RF24_250KBPS); // Both endpoints must have this set the same
  radio.setAutoAck(false);
  radio.openReadingPipe(1, pipeIn);
  radio.startListening();
}
/**************************************************/


void recvData()
{
  while ( radio.available() ) {
    radio.read(&data, sizeof(MyData));
    lastRecvTime = millis();
  }
}

/**************************************************/
void loop()
{
  recvData();
  unsigned long now = millis();
  if ( now - lastRecvTime > 500 ) { //if data stops coming turn everything off with a half of second
    // signal lost? tunr it off
    resetData();
  }

  int servoAngle1 = map(data.Pot_X_channel_in, 1, 1023, 50, 130);
  int servoAngle2 = map(data.Pot_Y_channel_in, 1, 1023, 50, 130);
  //  int servoAngle31 = map(data.Pot_A_channel_in, 0, 1023, 50, 130);
  //  int servoAngle42 = map(data.Pot_BX_channel_in, 0, 1023, 50, 130);
  //#######################################
  //# Print the data every second can be more)
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;
    //Print the Incoming data
    Serial.print("Pot_X_channel_in = ");
    Serial.print(data.Pot_X_channel_in);
    Serial.println("   ");
    Serial.print("Pot_Y_channel_in = ");
    Serial.print(data.Pot_Y_channel_in);
    Serial.println("   ");
    Serial.print("servoAngle1 Mapped = ");
    Serial.print(servoAngle1);
    Serial.println("   ");
    Serial.print("servoAngle2 Mapped = ");
    Serial.print(servoAngle2);
    Serial.println("   ");
  }
  //  servo1.write(servoAngle1);
  // delay (20);
  //  servo2.write(servoAngle2);
  // delay (20);

}

/**************************************************/

nicholas1507:
I'm pretty sure that the wire hook up is ok and here is my code:

Please show us circuit diagrams.
How are you powering the two units?
Thanks.. Tom... :slight_smile:

Well i try to copy your code and download it to my program it didn't work either. About power source, I power the nrf24L01 module from the adapter module and i power the arduino Transmitter with a 9v battery and about the circuit diagram i don't have anything to draw it right now but i could tell you that the CE pin goes to pin 7, CSN go to pin 8, SCK go to pin 13, MOSI goes to pin 11 and finally MISO is going to pin 12. Oh and one more thing i power the arduino receiver with USB port.

And i did write the SPI library in my code. It just i forgot to copy it.

Hi,
Use a pen(cil) and paper for you circuit diagram, its quick, its easy, and you already know how to use drawing implements. :slight_smile:
Then attach a picture of your handy work.
What sort of 9V battery?

Thanks.. Tom... :slight_smile:

nicholas1507:
Transmitter with a 9v battery

9v batteries are for smoke alarms...don't use them.
Use AA's.

nicholas1507:
Well i try to copy your code and download it to my program it didn't work either.

If you are referring to the code in my Simple nRF24L01+ Tutorial then stick with that until you get it working. It will be much easier to help with code I am familiar with.

Please post the actual programs that YOU uploaded to your two Arduinos, and also the circuit diagrams as requested in Reply #6

...R

Can i draw power directly from the USB port for both receiver and transmitter? bluejet. Can that replace the AA battery bluejet?

Hi,
What NRF module do you have?
Are you supplying it with 3.3V?

Tom... :slight_smile:

nicholas1507:
Can i draw power directly from the USB port for both receiver and transmitter? bluejet. Can that replace the AA battery bluejet?

That would be fine for the Arduinos, but how are you providing the 3.3v for the nRF24?

And just to be clear, I'm sure @bluejets meant a pack of 6 x AA cells to provide 9v.

...R