Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This demo Working with Arduino Uno or nano.
- //For nRF24L01, rec string.
- //TX:http://pastebin.com/5Ju5XUPr
- //這程式碼是給Arduino+nRf24L01用來傳送訊息的
- //It working good.
- //部分修改自網路
- //接收訊息完整 沒有缺漏
- ////Library:https://codeload.github.com/maniacbug/RF24/zip/master
- #include <nRF24L01.h>
- #include <RF24.h>
- #include <RF24_config.h>
- #include <SPI.h>
- //Rec MSG
- /*
- This sketch receives strings from sending unit via nrf24
- and prints them out via serial. The sketch waits until
- it receives a specific value (2 in this case), then it
- prints the complete message and clears the message buffer.
- */
- int msg[1];
- RF24 radio(9,10);
- const uint64_t pipe = 0xF0F0F0F0E1LL; //選擇管線,接收與傳送需要一致
- int lastmsg = 1;
- String theMessage = "";
- void setup(void){
- Serial.begin(9600);
- Serial.println("I am getter.");
- radio.begin();
- radio.enableDynamicPayloads();
- radio.setAutoAck(1);
- radio.setRetries(15,15);
- radio.setDataRate(RF24_250KBPS);
- radio.setPALevel(RF24_PA_MAX);
- radio.setChannel(76);//選擇76頻道,避開干擾
- // radio.openWritingPipe(0xF0F0F0F0E1LL);
- radio.openReadingPipe(1,pipe);
- radio.startListening();
- }
- void loop(void){
- if (radio.available()){
- bool done = false;
- done = radio.read(msg, 1);
- char theChar = msg[0];
- if (msg[0] != 11){ //接收傳送需一致
- theMessage.concat(theChar);
- }
- else {
- Serial.println(theMessage);
- theMessage= "";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement