From 8860ccb98e2972ed63ac5030ea61dbc20ef5d2f7 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Wed, 1 Apr 2020 10:07:17 +0200 Subject: [PATCH] first test-version --- LoRa_APRS_Tracker/LoRa_APRS_Tracker.ino | 58 +++++++++++ LoRa_APRS_Tracker/display.cpp | 132 ++++++++++++++++++++++++ LoRa_APRS_Tracker/display.h | 14 +++ LoRa_APRS_Tracker/settings.h | 20 ++++ 4 files changed, 224 insertions(+) create mode 100644 LoRa_APRS_Tracker/LoRa_APRS_Tracker.ino create mode 100644 LoRa_APRS_Tracker/display.cpp create mode 100644 LoRa_APRS_Tracker/display.h create mode 100644 LoRa_APRS_Tracker/settings.h diff --git a/LoRa_APRS_Tracker/LoRa_APRS_Tracker.ino b/LoRa_APRS_Tracker/LoRa_APRS_Tracker.ino new file mode 100644 index 0000000..af6cd48 --- /dev/null +++ b/LoRa_APRS_Tracker/LoRa_APRS_Tracker.ino @@ -0,0 +1,58 @@ +#include +#include +#include + +#include "settings.h" +#include "display.h" + + +void setup_lora(); + +void setup() +{ + Serial.begin(115200); + setup_display(); + + delay(500); + Serial.println("[INFO] LoRa APRS iGate by OE5BPA (Peter Buchegger)"); + show_display("OE5BPA", "LoRa APRS iGate", "by Peter Buchegger", 2000); + + setup_lora(); + + delay(500); +} + +void loop() +{ + String buffer = "OE5BPA-7>APRS:=4819.82NI01418.68E&LoRa Tracker test\n"; + LoRa.beginPacket(); + LoRa.write((const uint8_t*)buffer.c_str(), buffer.length()); + LoRa.endPacket(); + Serial.print("[INFO] Package sent: "); + Serial.println(buffer); + show_display("OE5BPA", "Package sent", buffer); + delay(30000); +} + +void setup_lora() +{ + Serial.println("[INFO] Set SPI pins!"); + SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_SS); + LoRa.setPins(LORA_SS, LORA_RST, LORA_DIO0); + Serial.println("[INFO] Set LoRa pins!"); + + long freq = 433775000; + Serial.print("[INFO] frequency: "); + Serial.println(freq); + if (!LoRa.begin(freq)) { + Serial.println("[ERROR] Starting LoRa failed!"); + show_display("ERROR", "Starting LoRa failed!"); + while (1); + } + LoRa.setSpreadingFactor(12); + LoRa.setSignalBandwidth(125E3); + LoRa.setCodingRate4(5); + LoRa.enableCrc(); + Serial.println("[INFO] LoRa init done!"); + show_display("INFO", "LoRa init done!", 2000); +} diff --git a/LoRa_APRS_Tracker/display.cpp b/LoRa_APRS_Tracker/display.cpp new file mode 100644 index 0000000..e02732e --- /dev/null +++ b/LoRa_APRS_Tracker/display.cpp @@ -0,0 +1,132 @@ + +#include +#include +#include + +#include "display.h" +#include "settings.h" + +Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RST); + +void setup_display() +{ + pinMode(OLED_RST, OUTPUT); + digitalWrite(OLED_RST, LOW); + delay(20); + digitalWrite(OLED_RST, HIGH); + + Wire.begin(OLED_SDA, OLED_SCL); + if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)) + { + Serial.println("SSD1306 allocation failed"); + while (1); + } + + display.clearDisplay(); + display.setTextColor(WHITE); + display.setTextSize(1); + display.setCursor(0,0); + display.print("LORA SENDER "); + display.display(); +} + +void show_display(String header, int wait) +{ + display.clearDisplay(); + display.setTextColor(WHITE); + display.setTextSize(2); + display.setCursor(0,0); + display.println(header); + display.display(); + delay(wait); +} + +void show_display(String header, String line1, int wait) +{ + display.clearDisplay(); + display.setTextColor(WHITE); + display.setTextSize(2); + display.setCursor(0,0); + display.println(header); + display.setTextSize(1); + display.setCursor(0,16); + display.println(line1); + display.display(); + delay(wait); +} + +void show_display(String header, String line1, String line2, int wait) +{ + display.clearDisplay(); + display.setTextColor(WHITE); + display.setTextSize(2); + display.setCursor(0,0); + display.println(header); + display.setTextSize(1); + display.setCursor(0,16); + display.println(line1); + display.setCursor(0,26); + display.println(line2); + display.display(); + delay(wait); +} + +void show_display(String header, String line1, String line2, String line3, int wait) +{ + display.clearDisplay(); + display.setTextColor(WHITE); + display.setTextSize(2); + display.setCursor(0,0); + display.println(header); + display.setTextSize(1); + display.setCursor(0,16); + display.println(line1); + display.setCursor(0,26); + display.println(line2); + display.setCursor(0,36); + display.println(line3); + display.display(); + delay(wait); +} + +void show_display(String header, String line1, String line2, String line3, String line4, int wait) +{ + display.clearDisplay(); + display.setTextColor(WHITE); + display.setTextSize(2); + display.setCursor(0,0); + display.println(header); + display.setTextSize(1); + display.setCursor(0,16); + display.println(line1); + display.setCursor(0,26); + display.println(line2); + display.setCursor(0,36); + display.println(line3); + display.setCursor(0,46); + display.println(line4); + display.display(); + delay(wait); +} + +void show_display(String header, String line1, String line2, String line3, String line4, String line5, int wait) +{ + display.clearDisplay(); + display.setTextColor(WHITE); + display.setTextSize(2); + display.setCursor(0,0); + display.println(header); + display.setTextSize(1); + display.setCursor(0,16); + display.println(line1); + display.setCursor(0,26); + display.println(line2); + display.setCursor(0,36); + display.println(line3); + display.setCursor(0,46); + display.println(line4); + display.setCursor(0,56); + display.println(line5); + display.display(); + delay(wait); +} diff --git a/LoRa_APRS_Tracker/display.h b/LoRa_APRS_Tracker/display.h new file mode 100644 index 0000000..2aec8de --- /dev/null +++ b/LoRa_APRS_Tracker/display.h @@ -0,0 +1,14 @@ + +#ifndef DISPLAY_H_ +#define DISPLAY_H_ + +void setup_display(); + +void show_display(String header, int wait = 0); +void show_display(String header, String line1, int wait = 0); +void show_display(String header, String line1, String line2, int wait = 0); +void show_display(String header, String line1, String line2, String line3, int wait = 0); +void show_display(String header, String line1, String line2, String line3, String line4, int wait = 0); +void show_display(String header, String line1, String line2, String line3, String line4, String line5, int wait = 0); + +#endif diff --git a/LoRa_APRS_Tracker/settings.h b/LoRa_APRS_Tracker/settings.h new file mode 100644 index 0000000..2ac0c7d --- /dev/null +++ b/LoRa_APRS_Tracker/settings.h @@ -0,0 +1,20 @@ + +#ifndef SETTINGS_H_ +#define SETTINGS_H_ + +#define CALL "OE5BPA-7" + +#define LORA_SCK 5 +#define LORA_MISO 19 +#define LORA_MOSI 27 +#define LORA_SS 18 +#define LORA_RST 23 +#define LORA_DIO0 26 + +#define OLED_SDA 21 +#define OLED_SCL 22 +#define OLED_RST 4 +#define SCREEN_WIDTH 128 // OLED display width, in pixels +#define SCREEN_HEIGHT 64 // OLED display height, in pixels + +#endif