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