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_Transmit.ino (2721B)
1 /* 2 RadioLib SX128x Transmit Example 3 4 This example transmits packets using SX1280 LoRa radio module. 5 Each packet contains up to 256 bytes of data, in the form of: 6 - Arduino String 7 - null-terminated char array (C-string) 8 - arbitrary binary data (byte array) 9 10 Other modules from SX128x family can also be used. 11 12 For default module settings, see the wiki page 13 https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-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 // carrier frequency: 2400.0 MHz 39 // bandwidth: 812.5 kHz 40 // spreading factor: 9 41 // coding rate: 7 42 // output power: 10 dBm 43 // preamble length: 12 symbols 44 // CRC: enabled 45 int state = radio.begin(); 46 if (state == RADIOLIB_ERR_NONE) { 47 Serial.println(F("success!")); 48 } else { 49 Serial.print(F("failed, code ")); 50 Serial.println(state); 51 while (true); 52 } 53 54 // some modules have an external RF switch 55 // controlled via two pins (RX enable, TX enable) 56 // to enable automatic control of the switch, 57 // call the following method 58 // RX enable: 4 59 // TX enable: 5 60 /* 61 radio.setRfSwitchPins(4, 5); 62 */ 63 } 64 65 void loop() { 66 Serial.print(F("[SX1280] Transmitting packet ... ")); 67 68 // you can transmit C-string or Arduino string up to 69 // 256 characters long 70 // NOTE: transmit() is a blocking method! 71 // See example SX128x_Transmit_Interrupt for details 72 // on non-blocking transmission method. 73 int state = radio.transmit("Hello World!"); 74 75 // you can also transmit byte array up to 256 bytes long 76 /* 77 byte byteArr[] = {0x01, 0x23, 0x45, 0x56, 0x78, 0xAB, 0xCD, 0xEF}; 78 int state = radio.transmit(byteArr, 8); 79 */ 80 81 if (state == RADIOLIB_ERR_NONE) { 82 // the packet was successfully transmitted 83 Serial.println(F("success!")); 84 85 } else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) { 86 // the supplied packet was longer than 256 bytes 87 Serial.println(F("too long!")); 88 89 } else { 90 // some other error occurred 91 Serial.print(F("failed, code ")); 92 Serial.println(state); 93 94 } 95 96 // wait for a second before transmitting again 97 delay(1000); 98 }