PitNRF24L01 SPI HelloWorld

Comunicazione wireless tra due NRF24L01 tramite BUS SPI.

Comunicazione wireless tra due arduini con nRF2401l collegati al bus SPI

Riferimenti e istruzioni dal sito How to Mechatronics

Cosa serve:

  • 2 Arduini
  • 2 nRF2401l
  • cavetti

Codice sorgente trsmettitore:


/*
* Arduino Wireless Communication Tutorial
*     Example 1 - Transmitter Code
*                
* by Dejan Nedelkovski, www.HowToMechatronics.com
* 
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/
#include 
#include 
#include 
RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";
void setup() {
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
}
void loop() {
  const char text[] = "Hello World";
  radio.write(&text, sizeof(text));
  delay(1000);
}

Codice sorgente ricevitore:


/*
* Arduino Wireless Communication Tutorial
*       Example 1 - Receiver Code
*                
* by Dejan Nedelkovski, www.HowToMechatronics.com
* 
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/
#include 
#include 
#include 
RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";
void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN); // RF24_PA_LOW
  radio.startListening();
}
void loop() {
  if (radio.available()) {
    char text[32] = "";
    radio.read(&text, sizeof(text));
    Serial.println(text);
  }
}

 

 

 

Scarica tutto quello che serve:

 

 

 

ZappocoS, 3 febbraio 2018