Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <LoRa.h>
- #include <Wire.h>
- #define SCK 5 // GPIO5 -- SX1278's SCK
- #define MISO 19 // GPIO19 -- SX1278's MISO
- #define MOSI 27 // GPIO27 -- SX1278's MOSI
- #define SS 18 // GPIO18 -- SX1278's CS
- #define RST 14 // GPIO14 -- SX1278's RESET
- #define DI0 26 // GPIO26 -- SX1278's IRQ(Interrupt Request)
- #ifdef ARDUINO_SAMD_MKRWAN1300
- #error "This example is not compatible with the Arduino MKR WAN 1300 board!"
- #endif
- void setup() {
- Serial.begin(115200);
- while (!Serial);
- Serial.println("LoRa Sender");
- SPI.begin(SCK,MISO,MOSI,SS);
- LoRa.setPins(SS,RST,DI0);
- if (!LoRa.begin(434.75E6)) {
- Serial.println("Starting LoRa failed!");
- while (1);
- }
- // Uncomment the next line to disable the default AGC and set LNA gain, values between 1 - 6 are supported
- // LoRa.setGain(6);
- // register the receive callback
- LoRa.onReceive(onReceive);
- // put the radio into receive mode
- LoRa.receive();
- }
- void loop() {
- // do nothing
- }
- void onReceive(int packetSize) {
- // received a packet
- Serial.print("Received packet '");
- // read packet
- for (int i = 0; i < packetSize; i++) {
- Serial.print((char)LoRa.read());
- }
- // print RSSI of packet
- Serial.print("' with RSSI ");
- Serial.println(LoRa.packetRssi());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement