Go Down

Topic: arduino nano and nrf24 transceiver (Read 335 times) previous topic - next topic

Wistec

Please friends, i need your help. here is my code, can any  body tell me the reason why there is 5v ouput on digital pin 9, 10 and 11 of my aduino nano, i used digital pin 9 and 10 as CE and CSN, while 11, 12 and 13 i used for SPI connection, please, this have burned two of my NRF24 transievers, i really need your help.




/* Receiver code for the Arduino Radio control with PWM output
 * Install the NRF24 library to your IDE
 * Upload this code to the Arduino UNO, NANO, Pro mini (5V,16MHz)
 * Connect a NRF24 module to it:
 
    Module // Arduino UNO,NANO
   
    GND    ->   GND
    Vcc    ->   3.3V
    CE     ->   D9
    CSN    ->   D10
    CLK    ->   D13
    MOSI   ->   D11
    MISO   ->   D12

This code receive 7 channels and create a PWM output for each one on D2, D3, D4, D5, D6, D7and D8
Please, like share and subscribe : https://www.youtube.com/c/ELECTRONOOBS
*/


#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>  //To create PWM signals we need this lybrary

const uint64_t pipeIn = 0xE8E8F0F0E1LL;     //Remember that this code is the same as in the transmitter
RF24 radio(9, 10);  //CSN and CE pins

// The sizeof this struct should not exceed 32 bytes
struct Received_data {
  byte ch1;
  byte ch2;
  byte ch3;
  byte ch4;
  byte ch5;
  byte ch6;
  byte ch7;
};

Received_data received_data;

Servo channel_1;
Servo channel_2;
Servo channel_3;
Servo channel_4;
Servo channel_5;
Servo channel_6;
Servo channel_7;

int ch1_value = 0;
int ch2_value = 0;
int ch3_value = 0;
int ch4_value = 0;
int ch5_value = 0;
int ch6_value = 0;
int ch7_value = 0;




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

void setup()
{
    //Attach the servo signal on pins from D2 to D8
  channel_1.attach(2);
  channel_2.attach(3);
  channel_3.attach(4);
  channel_4.attach(5);
  channel_5.attach(6);
  channel_6.attach(7);
  channel_7.attach(8);

  //We reset the received values
  received_data.ch1 = 127;     
  received_data.ch2 = 127;
  received_data.ch3 = 127;
  received_data.ch4 = 127;
  received_data.ch5 = 0;
  received_data.ch6 = 0;
  received_data.ch7 = 0;

      //Once again, begin and radio configuration
  radio.begin();
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS); 
  radio.openReadingPipe(1,pipeIn);
 
  //We start the radio comunication
  radio.startListening();

}

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

unsigned long lastRecvTime = 0;

//We create the function that will read the data each certain time
void receive_the_data()
{
  while ( radio.available() ) {
  radio.read(&received_data, sizeof(Received_data));
  lastRecvTime = millis(); //Here we receive the data
}
}

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

void loop()
{
  //Receive the radio data
  receive_the_data();


  ch1_value = map(received_data.ch1,0,255,1000,2000);
  ch2_value = map(received_data.ch2,0,255,1000,2000);
  ch3_value = map(received_data.ch3,0,255,1000,2000);
  ch4_value = map(received_data.ch4,0,255,1000,2000);
  ch5_value = map(received_data.ch5,0,1,1000,2000);
  ch6_value = map(received_data.ch6,0,1,1000,2000);
  ch7_value = map(received_data.ch7,0,255,1000,2000);
  Serial.println(ch1_value);

  //Creathe the PWM signals
  channel_1.writeMicroseconds(ch1_value); 
  channel_2.writeMicroseconds(ch2_value); 
  channel_3.writeMicroseconds(ch3_value); 
  channel_4.writeMicroseconds(ch4_value); 
  channel_5.writeMicroseconds(ch5_value); 
  channel_6.writeMicroseconds(ch6_value); 
  channel_7.writeMicroseconds(ch7_value); 
 
 
}//Loop end

Robin2

Have a look at this Simple nRF24L01+ Tutorial.

Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.

The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work


In my experience the nRF24 modules survive a surprising amount of abuse so you must have been trying hard to make them fail.

I believe that the 3.3v pin on a nano cannot provide enough current for an nRF24. Try powering them with a pair of AA alkaline cells (3v) with the battery GND connected to the Arduino GND.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

BabyGeezer

...can any  body tell me the reason why there is 5v ouput on digital pin 9, 10 and 11 of my aduino nano,
...
because you are using a 5V microcontroller - that is normal !

the nRF24 module IO pins are 5V tolerant, meaning you *can* connect them to 5V Arduino pins for communication without level-shifting, BUT the power (Vcc) MUST BE 3v3.

as mentioned before, the Nano 3v3 is too weak for this, the Uno one is okay (for me - using original Uno).

and don't forget to use capacitors, almost every tutorial for the nRF24 module will mention this - so far i have had success without it - although i use PA_LEVEL = min.


...
This code receive 7 channels and create a PWM output for each one on D2, D3, D4, D5, D6, D7and D8
Please, like share and subscribe : https://www.youtube.com/c/ELECTRONOOBS
*/
...
that is not possible - PWM pins (on Uno and Nano) are only D3, D5, D6, D9, D10 and D11.


work through Robin2's tutorial - it is THE BEST for beginners - i used it !
Attach your images to be viewed directly - THIS WAY;
https://forum.arduino.cc/index.php?topic=519037.0

John_SB

I don't know if these are any help, but I'm currently using two of them in a project I'm working on. They have a built-in socket for the nRF24L01, with a 3.3v regulator to power it, so it doesn't draw power from the Nano. So far I've got them controlling up to 6 servos. No wiring or soldering needed, so it's likely that any problems will only be with the sketch.

Go Up