Advertisement
phirippu

Lilygo T-Beam Lora Receiver

Feb 13th, 2025
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.33 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <LoRa.h>
  3. #include <Wire.h>  
  4.  
  5. #define SCK     5    // GPIO5  -- SX1278's SCK
  6. #define MISO    19   // GPIO19 -- SX1278's MISO
  7. #define MOSI    27   // GPIO27 -- SX1278's MOSI
  8. #define SS      18   // GPIO18 -- SX1278's CS
  9. #define RST     14   // GPIO14 -- SX1278's RESET
  10. #define DI0     26   // GPIO26 -- SX1278's IRQ(Interrupt Request)
  11.  
  12. #ifdef ARDUINO_SAMD_MKRWAN1300
  13. #error "This example is not compatible with the Arduino MKR WAN 1300 board!"
  14. #endif
  15.  
  16. void setup() {
  17.   Serial.begin(115200);
  18.   while (!Serial);
  19.  
  20.   Serial.println("LoRa Sender");
  21.   SPI.begin(SCK,MISO,MOSI,SS);
  22.   LoRa.setPins(SS,RST,DI0);
  23.  
  24.   if (!LoRa.begin(434.75E6)) {
  25.     Serial.println("Starting LoRa failed!");
  26.     while (1);
  27.   }
  28.  
  29.   // Uncomment the next line to disable the default AGC and set LNA gain, values between 1 - 6 are supported
  30.   // LoRa.setGain(6);
  31.  
  32.   // register the receive callback
  33.   LoRa.onReceive(onReceive);
  34.  
  35.   // put the radio into receive mode
  36.   LoRa.receive();
  37. }
  38.  
  39. void loop() {
  40.   // do nothing
  41. }
  42.  
  43. void onReceive(int packetSize) {
  44.   // received a packet
  45.   Serial.print("Received packet '");
  46.  
  47.   // read packet
  48.   for (int i = 0; i < packetSize; i++) {
  49.     Serial.print((char)LoRa.read());
  50.   }
  51.  
  52.   // print RSSI of packet
  53.   Serial.print("' with RSSI ");
  54.   Serial.println(LoRa.packetRssi());
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement