「NRF24L01+」:修訂間差異

出自TSK WIKI
跳至導覽 跳至搜尋
Root​(留言 | 貢獻)
 
(未顯示由 2 位使用者於中間所作的 5 次修訂)
第2行: 第2行:
*[https://swf.com.tw/?p=1044 nRF24L01無線收發器模組與Arduino通訊實驗]
*[https://swf.com.tw/?p=1044 nRF24L01無線收發器模組與Arduino通訊實驗]
*[http://rhrwirmemhf.blogspot.com/2015/10/how-to-arduino-arduino-nrf24l01.html Arduino 簡易測試 NRF24L01 無線傳輸]
*[http://rhrwirmemhf.blogspot.com/2015/10/how-to-arduino-arduino-nrf24l01.html Arduino 簡易測試 NRF24L01 無線傳輸]
**http://2.bp.blogspot.com/-zKYqWcUzHos/VhEF8tzgQ0I/AAAAAAAAAco/xdi99HmfLwA/s1600/%25E5%259C%2596%25E7%2589%25873.png


==發射==
==發射==
第8行: 第9行:
#include "RF24.h"
#include "RF24.h"
#include <printf.h>
#include <printf.h>
RF24 rf24(7, 8); // CE腳, CSN腳
RF24 rf24(A0, A1); // CE腳, CSN腳
 
const byte addr[] = "1Node";
const byte addr[] = "1Node";
const char msg[] = "99.99";


int i=0;
void setup() {
void setup() {
 
   Serial.begin(9600);
   Serial.begin(9600);
   printf_begin();  
   printf_begin();  
第24行: 第26行:
   rf24.printDetails();
   rf24.printDetails();
}
}
 
void loop() {
void loop() {
  char msg[32] ;
  String str = String(i);
  str.toCharArray(msg,32);
  delay(1000);
   rf24.write(&msg, sizeof(msg));  // 傳送資料
   rf24.write(&msg, sizeof(msg));  // 傳送資料
   delay(1000);
   Serial.println(msg);
  //delay(50);
  i++;
  if(i>=1000) i=1 ;
}
}
/*
/*
11:00:39.472 -> RX_ADDR_P0-1 = 0x65646f4e31 0xc2c2c2c2c2
11:00:39.472 -> RX_ADDR_P0-1 = 0x65646f4e31 0xc2c2c2c2c2
第111行: 第119行:
*/
*/
</C>
</C>
==接收(沒有LCD)==
<c>
#include <SPI.h>
#include "RF24.h"
#include <printf.h>
#include <Wire.h>
//read mode
RF24 rf24(A4, A5); // CE腳, CSN腳
const byte addr[] = "1Node";
const byte pipe = 1;  // 指定通道編號
int i;
void setup() {
  Serial.begin(9600);
  printf_begin();  //初始化 RF24 的列印輸出功能
  rf24.begin();
  rf24.setChannel(76);  // 設定頻道編號
  rf24.setPALevel(RF24_PA_MAX);
  rf24.setDataRate(RF24_250KBPS);
  rf24.openReadingPipe(pipe, addr);  // 開啟通道和位址
  rf24.startListening();  // 開始監聽無線廣播
  Serial.println("nRF24L01 ready!");
  rf24.printDetails();  //印出 nRF24L01 詳細狀態
}
void loop() {
  if (rf24.available(&pipe)) {
    char msg[32] = "";
    rf24.read(&msg, sizeof(msg));
    Serial.println(msg); // 顯示訊息內容
  i++; 
  }
}
</c>

於 2020年6月3日 (三) 16:44 的最新修訂

參考網頁

發射

<C>

  1. include <SPI.h>
  2. include "RF24.h"
  3. include <printf.h>

RF24 rf24(A0, A1); // CE腳, CSN腳

const byte addr[] = "1Node";

int i=0; void setup() {

 Serial.begin(9600);
 printf_begin(); 
 rf24.begin();
 rf24.setChannel(76);       // 設定頻道編號
 rf24.openWritingPipe(addr); // 設定通道位址
 rf24.setPALevel(RF24_PA_MAX);   // 設定廣播功率
 rf24.setDataRate(RF24_250KBPS); // 設定傳輸速率
 rf24.stopListening();       // 停止偵聽;設定成發射模式
 rf24.printDetails();

}

void loop() {

 char msg[32] ;
 String str = String(i);
 str.toCharArray(msg,32);
 delay(1000);
 rf24.write(&msg, sizeof(msg));  // 傳送資料
 Serial.println(msg);
 //delay(50);
 i++;
 if(i>=1000) i=1 ;

} /* 11:00:39.472 -> RX_ADDR_P0-1 = 0x65646f4e31 0xc2c2c2c2c2 11:00:39.519 -> RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6 11:00:39.566 -> TX_ADDR = 0x65646f4e31 11:00:39.629 -> RX_PW_P0-6 = 0x20 0x00 0x00 0x00 0x00 0x00 11:00:39.629 -> EN_AA = 0x3f 11:00:39.629 -> EN_RXADDR = 0x03 11:00:39.660 -> RF_CH = 0x4c 11:00:39.707 -> RF_SETUP = 0x27 11:00:39.707 -> CONFIG = 0x0e 11:00:39.754 -> DYNPD/FEATURE = 0x00 0x00 11:00:39.754 -> Data Rate = 250KBPS 11:00:39.800 -> Model = nRF24L01+ 11:00:39.800 -> CRC Length = 16 bits 11:00:39.847 -> PA Power = PA_MAX

  • /

</C>

接收

<C>

  1. include <SPI.h>
  2. include "RF24.h"
  3. include <printf.h>
  4. include <Wire.h>
  5. include <LiquidCrystal_I2C.h>

RF24 rf24(7, 8); // CE腳, CSN腳 LiquidCrystal_I2C lcd(0x27,20,4); const byte addr[] = "1Node"; const byte pipe = 1; // 指定通道編號 int i; void setup() {

 Serial.begin(9600);
 printf_begin();  //初始化 RF24 的列印輸出功能
 rf24.begin();
 rf24.setChannel(76);  // 設定頻道編號
 rf24.setPALevel(RF24_PA_MAX);
 rf24.setDataRate(RF24_250KBPS);
 rf24.openReadingPipe(pipe, addr);  // 開啟通道和位址
 rf24.startListening();  // 開始監聽無線廣播
 Serial.println("nRF24L01 ready!");
 lcd.init();
 lcd.backlight();
 lcd.setCursor(1,0);
 lcd.print("Ready!!");
 rf24.printDetails();  //印出 nRF24L01 詳細狀態

}

void loop() {

 if (rf24.available(&pipe)) {
   char msg[32] = "";
   rf24.read(&msg, sizeof(msg));
   Serial.println(msg); // 顯示訊息內容
  lcd.clear();
   lcd.setCursor(1,0);
 lcd.print(msg);
 lcd.setCursor(6,1);
 lcd.print(i);
 i++;  
 }

}

/* 11:10:53.953 -> nRF24L01 ready! 11:10:55.059 -> STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0 11:10:55.106 -> RX_ADDR_P0-1 = 0xe7e7e7e7e7 0x65646f4e31 11:10:55.153 -> RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6 11:10:55.200 -> TX_ADDR = 0xe7e7e7e7e7 11:10:55.246 -> RX_PW_P0-6 = 0x00 0x20 0x00 0x00 0x00 0x00 11:10:55.246 -> EN_AA = 0x3f 11:10:55.293 -> EN_RXADDR = 0x02 11:10:55.293 -> RF_CH = 0x4c 11:10:55.340 -> RF_SETUP = 0x27 11:10:55.340 -> CONFIG = 0x0f 11:10:55.387 -> DYNPD/FEATURE = 0x00 0x00 11:10:55.387 -> Data Rate = 250KBPS 11:10:55.387 -> Model = nRF24L01+ 11:10:55.434 -> CRC Length = 16 bits 11:10:55.481 -> PA Power = PA_MAX

  • /

</C>

接收(沒有LCD)

<c>

  1. include <SPI.h>
  2. include "RF24.h"
  3. include <printf.h>
  4. include <Wire.h>

//read mode RF24 rf24(A4, A5); // CE腳, CSN腳 const byte addr[] = "1Node"; const byte pipe = 1; // 指定通道編號 int i; void setup() {

 Serial.begin(9600);
 printf_begin();  //初始化 RF24 的列印輸出功能
 rf24.begin();
 rf24.setChannel(76);  // 設定頻道編號
 rf24.setPALevel(RF24_PA_MAX);
 rf24.setDataRate(RF24_250KBPS);
 rf24.openReadingPipe(pipe, addr);  // 開啟通道和位址
 rf24.startListening();  // 開始監聽無線廣播
 Serial.println("nRF24L01 ready!");

 rf24.printDetails();  //印出 nRF24L01 詳細狀態

}

void loop() {

 if (rf24.available(&pipe)) {
   char msg[32] = "";
   rf24.read(&msg, sizeof(msg));
   Serial.println(msg); // 顯示訊息內容
 i++;  
 }

} </c>