Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //modified lora library by Sandeep Mistry for TTGO ESP32 Lora
- // lora receiverCallBack 915Mhz with OLED
- // Modified by HwThinker
- #include <SPI.h>
- #include <LoRa.h>
- #include <Wire.h> // Only needed for Arduino 1.6.5 and earlier
- #include "SSD1306Wire.h" // legacy include: `#include "SSD1306.h"`
- #ifdef ARDUINO_SAMD_MKRWAN1300
- #error "This example is not compatible with the Arduino MKR WAN 1300 board!"
- #endif
- #define SCK 5 // GPIO5 -- lora SCK
- #define MISO 19 // GPIO19 -- lora MISO
- #define MOSI 27 // GPIO27 -- lora MOSI
- #define SS 18 // GPIO18 -- lora CS
- #define RST 14 // GPIO14/12 -- RESET (If Lora does not work, replace it with GPIO14)
- #define DI0 26 // GPIO26 -- IRQ(Interrupt Request)
- #define BAND 915E6
- //replace default pin OLED_SDA=4, OLED_SCL=15 with OLED_SDA=21, OLED_SCL=22
- #define OLED_SDA 4
- #define OLED_SCL 15
- #define OLED_RST 16
- #define LED_BUILTIN 2
- // Initialize the OLED display using Wire library
- SSD1306Wire display(0x3c, OLED_SDA, OLED_SCL); // OLED_SDA=4, OLED_SCL=15
- int RxDataRSSI = 0;
- char Str1[15];
- void setup() {
- // START aktivas Oled
- pinMode(LED_BUILTIN, OUTPUT);
- pinMode(OLED_RST , OUTPUT);
- digitalWrite(OLED_RST , LOW); // set GPIO16 low to reset OLED
- delay(50);
- digitalWrite(OLED_RST , HIGH); // while OLED is running, must set GPIO16 in high、
- // Initialising the UI will init the display too.
- display.init();
- display.flipScreenVertically();
- display.setFont(ArialMT_Plain_10);
- // clear the display
- display.clear();
- // aktivasi Oled END
- Serial.begin(9600);
- while (!Serial);
- SPI.begin(SCK, MISO, MOSI, SS);
- LoRa.setPins(SS, RST, DI0);
- Serial.println("LoRa Receiver Callback");
- if (!LoRa.begin(BAND)) {
- Serial.println("Starting LoRa failed!");
- while (1);
- }
- // register the receive callback
- LoRa.onReceive(onReceive);
- // put the radio into receive mode
- LoRa.receive();
- display.setFont(ArialMT_Plain_24);
- display.drawString(0, 0, "HwThinker");
- display.display();
- delay(1000);
- display.clear();
- }
- void loop() {
- // do nothing
- display.setFont(ArialMT_Plain_16);
- display.drawString(0, 0, "Lora Receiver");
- display.setFont(ArialMT_Plain_10);
- display.drawString(0, 26, "rx Data:" + String(Str1));
- display.setTextAlignment(TEXT_ALIGN_LEFT);
- display.setFont(ArialMT_Plain_10);
- display.drawString(0, 45, "RSSI : " + String(LoRa.packetRssi()));
- display.display();
- }
- void onReceive(int packetSize) {
- // received a packet
- Serial.print("Received packet '");
- memset(Str1, 0, sizeof(Str1));
- // read packet
- for (int i = 0; i < packetSize; i++) {
- Str1[i] = (char)LoRa.read();
- }
- Serial.print(Str1);
- // print RSSI of packet
- Serial.print("' with RSSI ");
- RxDataRSSI = LoRa.packetRssi();
- Serial.println(RxDataRSSI);
- // digitalWrite(LED_BUILTIN, (state) ? HIGH : LOW);
- // state = !state;
- digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
- display.clear();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement