// lora Sender for TTGO ESP32 915 Mhz modified by HwThinker
#include <SPI.h>
#include <LoRa.h>
#define LED_BUILTIN 2
#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 12 // GPIO14 -- RESET (If Lora does not work, replace it with GPIO14)
#define DI0 26 // GPIO26 -- IRQ(Interrupt Request)
#define BAND 915E6
int counter = 0;
int state = 0;
void setup() {
// START aktivas Oled
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);
while (!Serial); //If just the the basic function, must connect to a computer
SPI.begin(SCK, MISO, MOSI, SS);
LoRa.setPins(SS, RST, DI0);
// Serial.println("LoRa Sender");
if (!LoRa.begin(BAND)) {
Serial.println("Starting LoRa failed!");
while (1);
}
Serial.println("LoRa Initial OK! Blinky 1.5 second");
for (int i=0;i<15;i++) {
digitalWrite(LED_BUILTIN, digitalRead(LED_BUILTIN) ? LOW : HIGH);
delay(100);
}
}
void loop() {
Serial.print("Sending packet: ");
Serial.println(counter);
// send packet
LoRa.beginPacket();
LoRa.print("hello ");
LoRa.print(counter);
LoRa.endPacket();
counter++;
digitalWrite(LED_BUILTIN, (state) ? HIGH : LOW);
delay(1000);
state = !state;
//or digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
Comments