LilyGo-LoRa-Series/examples/ArduinoLoRa/LoRaSender/LoRaSender.ino

47 lines
1 KiB
Arduino
Raw Normal View History

2024-05-15 17:58:37 +08:00
// Only supports SX1276/SX1278
2022-06-16 14:01:20 +08:00
#include <LoRa.h>
2024-05-15 17:58:37 +08:00
#include "LoRaBoards.h"
2022-06-16 14:01:20 +08:00
int counter = 0;
void setup()
{
2024-05-15 17:58:37 +08:00
setupBoards();
2022-06-16 14:01:20 +08:00
// When the power is turned on, a delay is required.
delay(1500);
2024-05-15 17:58:37 +08:00
#ifdef RADIO_TCXO_ENABLE
pinMode(RADIO_TCXO_ENABLE, OUTPUT);
digitalWrite(RADIO_TCXO_ENABLE, HIGH);
#endif
2022-06-16 14:01:20 +08:00
Serial.println("LoRa Sender");
2022-12-26 16:53:44 +08:00
LoRa.setPins(RADIO_CS_PIN, RADIO_RST_PIN, RADIO_DIO0_PIN);
2024-05-15 17:58:37 +08:00
if (!LoRa.begin(LORA_FREQ_CONFIG)) {
2022-06-16 14:01:20 +08:00
Serial.println("Starting LoRa failed!");
while (1);
}
}
void loop()
{
Serial.print("Sending packet: ");
Serial.println(counter);
// send packet
LoRa.beginPacket();
LoRa.print("hello ");
LoRa.print(counter);
LoRa.endPacket();
if (u8g2) {
char buf[256];
u8g2->clearBuffer();
u8g2->drawStr(0, 12, "Transmitting: OK!");
snprintf(buf, sizeof(buf), "Sending: %d", counter);
u8g2->drawStr(0, 30, buf);
u8g2->sendBuffer();
}
counter++;
delay(5000);
}