Hey everyone,
I hope everything is going well. Recently I bought a pack of three nRF24L01+PA+LNA+breakout boards from Amazon. I followed this tutorial and hooked the transmitter and receiver into two seperate Arduino Uno's, however nothing is working. Here is the code.
Transmitter
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN // Define instance of RF24 object called 'radio' and define pins used
const byte address[6] = "00001"; // Define address/pipe to use.
unsigned long count = 0; // Use to count the number of messages sent
char countStr[10]; // Create a char array to hold count as a string
//===============================================================================
// Initialization
//===============================================================================
void setup()
{
Serial.begin(9600);
radio.begin(); // Start instance of the radio object
radio.openWritingPipe(address); // Setup pipe to write data to the address that was defined
radio.setPALevel(RF24_PA_MAX); // Set the Power Amplified level to MAX in this case
radio.stopListening(); // We are going to be the transmitter, so we will stop listening
}
//===============================================================================
// Main
//===============================================================================
void loop()
{
count++; // Increment the count
ltoa(count,countStr, 10); // Convert the count and put into the char array.
char text[30] = "Sending Message: "; // Create our base message.
strcat (text, countStr); // Append the count to the base message
radio.write(&text, sizeof(text)); // Write the char array.
Serial.println("Send message");
delay(1000); // Delay for 1 second, then repeat
}
Receiver
/*
* nRF24L01 Receiver Test Software
*
* Exercises the nRF24L01 Module. This code runs on the receiver 'slave' device.
* Use the nRF24L01_Transmitter_Test software for the transmitting 'master' device
*
* This uses the RF24.h library which can be installed from the Arduino IDE
* Pins used for the SPI interface are determined by the Arduino being used.
* The other two pins are arbitrary and can be changed if needed. Redfine them in the RF24
* statement. Default shown here is to use pins 7 &
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN // Define instance of RF24 object called 'radio' and define pins used
const byte address[6] = "00001"; // Define address/pipe to use. This can be any 5 alphnumeric letters/numbers
//===============================================================================
// Initialization
//===============================================================================
void setup() {
Serial.begin(9600); // Start serial port to display messages on Serial Monitor Window
radio.begin(); // Start instance of the radio object
radio.openReadingPipe(0, address); // Setup pipe to write data to the address that was defined
radio.setPALevel(RF24_PA_MAX); // Set the Power Amplified level to MAX in this case
radio.startListening(); // We are going to be the receiver, so we need to start listening
}
//===============================================================================
// Main
//===============================================================================
void loop() {
if (radio.available()) {
char text[32] = ""; // Clear buffer
radio.read(&text, sizeof(text)); // Read incoming message into buffer
Serial.println(text); // Print the message to the Serial Monitor window
}
}
Currently, this does not work. All of the wires are hooked up correctly. What is interesting is when the receiver is plugged into the arduino's 3.3v, radio.available() is always true. However when plugged into 5v, it is always false. This is the case for all components, which makes me think either I'm doing something wrong, or all of them are faulty.
Same setup for TX and RX
These things are known sometimes to be faulty, however can someone make sure there is no problem with the code so I know for sure it is a hardware problem?
Thank you all for your time!