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 |
SX128x_FLRC_Modem.ino (3264B)
1 /* 2 RadioLib SX128x FLRC Modem Example 3 4 This example shows how to use FLRC modem in SX128x chips. 5 6 NOTE: The sketch below is just a guide on how to use 7 FLRC modem, so this code should not be run directly! 8 Instead, modify the other examples to use FLRC 9 modem and use the appropriate configuration 10 methods. 11 12 For default module settings, see the wiki page 13 https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---flrc-modem 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 // SX1280 has the following connections: 23 // NSS pin: 10 24 // DIO1 pin: 2 25 // NRST pin: 3 26 // BUSY pin: 9 27 SX1280 radio = new Module(10, 2, 3, 9); 28 29 // or using RadioShield 30 // https://github.com/jgromes/RadioShield 31 //SX1280 radio = RadioShield.ModuleA; 32 33 void setup() { 34 Serial.begin(9600); 35 36 // initialize SX1280 with default settings 37 Serial.print(F("[SX1280] Initializing ... ")); 38 int state = radio.beginFLRC(); 39 if (state == RADIOLIB_ERR_NONE) { 40 Serial.println(F("success!")); 41 } else { 42 Serial.print(F("failed, code ")); 43 Serial.println(state); 44 while (true); 45 } 46 47 // if needed, you can switch between any of the modems 48 // 49 // radio.begin() start LoRa modem (and disable FLRC) 50 // radio.beginFLRC() start FLRC modem (and disable LoRa) 51 52 // the following settings can also 53 // be modified at run-time 54 state = radio.setFrequency(2410.5); 55 state = radio.setBitRate(520); 56 state = radio.setCodingRate(2); 57 state = radio.setOutputPower(5); 58 state = radio.setDataShaping(1.0); 59 uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67}; 60 state = radio.setSyncWord(syncWord, 4); 61 if (state != RADIOLIB_ERR_NONE) { 62 Serial.print(F("Unable to set configuration, code ")); 63 Serial.println(state); 64 while (true); 65 } 66 67 #warning "This sketch is just an API guide! Read the note at line 6." 68 } 69 70 void loop() { 71 // FLRC modem can use the same transmit/receive methods 72 // as the LoRa modem, even their interrupt-driven versions 73 74 // transmit FLRC packet 75 int state = radio.transmit("Hello World!"); 76 /* 77 byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 78 0x89, 0xAB, 0xCD, 0xEF}; 79 int state = radio.transmit(byteArr, 8); 80 */ 81 if (state == RADIOLIB_ERR_NONE) { 82 Serial.println(F("[SX1280] Packet transmitted successfully!")); 83 } else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) { 84 Serial.println(F("[SX1280] Packet too long!")); 85 } else if (state == RADIOLIB_ERR_TX_TIMEOUT) { 86 Serial.println(F("[SX1280] Timed out while transmitting!")); 87 } else { 88 Serial.println(F("[SX1280] Failed to transmit packet, code ")); 89 Serial.println(state); 90 } 91 92 // receive FLRC packet 93 String str; 94 state = radio.receive(str); 95 /* 96 byte byteArr[8]; 97 int state = radio.receive(byteArr, 8); 98 */ 99 if (state == RADIOLIB_ERR_NONE) { 100 Serial.println(F("[SX1280] Received packet!")); 101 Serial.print(F("[SX1280] Data:\t")); 102 Serial.println(str); 103 } else if (state == RADIOLIB_ERR_RX_TIMEOUT) { 104 Serial.println(F("[SX1280] Timed out while waiting for packet!")); 105 } else { 106 Serial.print(F("[SX1280] Failed to receive packet, code ")); 107 Serial.println(state); 108 } 109 }