acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
nRF24_Receive.ino (2577B)
1 /* 2 RadioLib nRF24 Receive Example 3 4 This example listens for FSK transmissions using nRF24 2.4 GHz radio module. 5 To successfully receive data, the following settings have to be the same 6 on both transmitter and receiver: 7 - carrier frequency 8 - data rate 9 - transmit pipe on transmitter must match receive pipe 10 on receiver 11 12 For default module settings, see the wiki page 13 https://github.com/jgromes/RadioLib/wiki/Default-configuration#nrf24 14 15 For full API reference, see the GitHub Pages 16 https://jgromes.github.io/RadioLib/ 17 */ 18 19 // include the library 20 #include <RadioLib.h> 21 22 // nRF24 has the following connections: 23 // CS pin: 10 24 // IRQ pin: 2 25 // CE pin: 3 26 nRF24 radio = new Module(10, 2, 3); 27 28 // or using RadioShield 29 // https://github.com/jgromes/RadioShield 30 //nRF24 radio = RadioShield.ModuleA; 31 32 void setup() { 33 Serial.begin(9600); 34 35 // initialize nRF24 with default settings 36 Serial.print(F("[nRF24] Initializing ... ")); 37 int state = radio.begin(); 38 if(state == RADIOLIB_ERR_NONE) { 39 Serial.println(F("success!")); 40 } else { 41 Serial.print(F("failed, code ")); 42 Serial.println(state); 43 while(true); 44 } 45 46 // set receive pipe 0 address 47 // NOTE: address width in bytes MUST be equal to the 48 // width set in begin() or setAddressWidth() 49 // methods (5 by default) 50 Serial.print(F("[nRF24] Setting address for receive pipe 0 ... ")); 51 byte addr[] = {0x01, 0x23, 0x45, 0x67, 0x89}; 52 state = radio.setReceivePipe(0, addr); 53 if(state == RADIOLIB_ERR_NONE) { 54 Serial.println(F("success!")); 55 } else { 56 Serial.print(F("failed, code ")); 57 Serial.println(state); 58 while(true); 59 } 60 } 61 62 void loop() { 63 Serial.print(F("[nRF24] Waiting for incoming transmission ... ")); 64 65 // you can receive data as an Arduino String 66 // NOTE: receive() is a blocking method! 67 // See example ReceiveInterrupt for details 68 // on non-blocking reception method. 69 String str; 70 int state = radio.receive(str); 71 72 // you can also receive data as byte array 73 /* 74 byte byteArr[8]; 75 int state = radio.receive(byteArr, 8); 76 */ 77 78 if (state == RADIOLIB_ERR_NONE) { 79 // packet was successfully received 80 Serial.println(F("success!")); 81 82 // print the data of the packet 83 Serial.print(F("[nRF24] Data:\t\t")); 84 Serial.println(str); 85 86 } else if (state == RADIOLIB_ERR_RX_TIMEOUT) { 87 // timeout occurred while waiting for a packet 88 Serial.println(F("timeout!")); 89 90 } else { 91 // some other error occurred 92 Serial.print(F("failed, code ")); 93 Serial.println(state); 94 95 } 96 }