I connected my clone of arduino nano (with CH340) and not-clone of arduino leonardo to nrf24l01 module and I have uploaded simple sketch which turn ON diode when I press button on another board. Leonardo had diode and Nano had button. It worked few times, sometimes I had to press button two times to turn ON diode or turn OFF but now I can only one time press button because Nano has freeze . I noticed that, when I click button, on nano board TX diode blinked and "L" diode begins little shine.
This diode are connected with pin 13 I think and this pin is connected to SCK in nrf24l01. I don't know why it worked and ceased.
EDIT: This is whole sketch who I use, this is from examples included to library:
#include SPI.h #include "nRF24L01.h" #include "RF24.h" #include "printf.h"RF24 radio(9,10);
const int role_pin = A4;
const uint8_t button_pins[] = {7}; const uint8_t num_button_pins = sizeof(button_pins);
const uint8_t led_pins[] = {7}; const uint8_t num_led_pins = sizeof(led_pins);
const uint64_t pipe = 0xE8E8F0F0E1LL;
typedef enum { role_remote = 1, role_led } role_e;
const char* role_friendly_name[] = { "invalid", "Remote", "LED Board"};
role_e role;
uint8_t button_states[num_button_pins]; uint8_t led_states[num_led_pins];
void setup(void) {
pinMode(role_pin, INPUT); digitalWrite(role_pin,HIGH); delay(20);
if ( digitalRead(role_pin) ) role = role_remote; else role = role_led;
Serial.begin(115200); printf_begin(); printf("\n\rRF24/examples/led_remote/\n\r"); printf("ROLE: %s\n\r",role_friendly_name[role]);
radio.begin();
if ( role == role_remote ) { radio.openWritingPipe(pipe); } else { radio.openReadingPipe(1,pipe); }
if ( role == role_led ) radio.startListening();
radio.printDetails();
if ( role == role_remote ) { int i = num_button_pins; while(i--) { pinMode(button_pins[i],INPUT); digitalWrite(button_pins[i],HIGH); } }
if ( role == role_led ) { int i = num_led_pins; while(i--) { pinMode(led_pins[i],OUTPUT); led_states[i] = HIGH; digitalWrite(led_pins[i],led_states[i]); } }
}
void loop(void) {
if ( role == role_remote ) { int i = num_button_pins; bool different = false; while(i--) { uint8_t state = ! digitalRead(button_pins[i]); if ( state != button_states[i] ) { different = true; button_states[i] = state; } }
if ( different ) { printf("Now sending..."); bool ok = radio.write( button_states, num_button_pins ); if (ok) printf("ok\n\r"); else printf("failed\n\r"); } delay(20);
}
if ( role == role_led ) { if ( radio.available() ) { while (radio.available()) { radio.read( button_states, num_button_pins );
printf("Got buttons\n\r"); int i = num_led_pins; while(i--) { if ( button_states[i] ) { led_states[i] ^= HIGH; digitalWrite(led_pins[i],led_states[i]); } } } } } }
Pinout:
Leonardo:
D7 - Led with resistor
D9 - NRF24 CE
D10- NRF24 CS
A4 - GND
ICSP MISO - NRF24 MISO
ICSP SCK - NRF24 SCK
ICSP MOSI - NRF24 MOSI
NANO:
D7 - Key from small arduino joystick
D9 - NRF24 CE
D10- NRF24 CS
D11- NRF24 MOSI
D12- NRF24 MISO
D13- NRF42 SCK
NRF24 is also connected to 3v3 pin.