Last active
August 26, 2022 14:14
-
-
Save martinschierle/923e2dfea1360096f29090c35e9babd0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include <LoRa.h> | |
#include <Wire.h> | |
#include <BME280I2C.h> | |
#include "SSD1306.h" | |
#include <TinyGPS++.h> | |
#include <HardwareSerial.h> | |
#define GPS_TX 34 | |
#define GPS_RX 12 | |
#define SCK 5 // GPIO5 -- SX1278's SCK | |
#define MISO 19 // GPIO19 -- SX1278's MISnO | |
#define MOSI 27 // GPIO27 -- SX1278's MOSI | |
#define SS 18 // GPIO18 -- SX1278's CS | |
#define RST 23 // GPIO14 -- SX1278's RESET | |
#define DI0 26 // GPIO26 -- SX1278's IRQ(Interrupt Request) | |
#define BAND 868E6 | |
unsigned int counter = 0; | |
SSD1306 display(0x3c, 21, 22); | |
String rssi = "RSSI --"; | |
String packSize = "--"; | |
String packet ; | |
BME280I2C bme; // Default : forced mode, standby time = 1000 ms | |
// Oversampling = pressure ×1, temperature ×1, humidity ×1, filter off, | |
HardwareSerial GPSSerial(1); | |
TinyGPSPlus tGps; | |
String name = "tbeam1"; | |
void setup() { | |
pinMode(16,OUTPUT); | |
pinMode(2,OUTPUT); | |
digitalWrite(16, LOW); // set GPIO16 low to reset OLED | |
delay(50); | |
digitalWrite(16, HIGH); // while OLED is running, must set GPIO16 in high | |
GPSSerial.begin(9600, SERIAL_8N1, GPS_TX, GPS_RX); | |
GPSSerial.setTimeout(2); | |
Serial.begin(115200); | |
while (!Serial); | |
Serial.println(); | |
Serial.println("LoRa Test"); | |
SPI.begin(SCK,MISO,MOSI,SS); | |
LoRa.setPins(SS,RST,DI0); | |
if (!LoRa.begin(868E6)) { | |
Serial.println("Starting LoRa failed!"); | |
while (1); | |
} | |
Wire.begin(); | |
while(!bme.begin()) | |
{ | |
Serial.println("Could not find BME280 sensor!"); | |
delay(1000); | |
} | |
switch(bme.chipModel()) | |
{ | |
case BME280::ChipModel_BME280: | |
Serial.println("Found BME280 sensor! Success."); | |
break; | |
case BME280::ChipModel_BMP280: | |
Serial.println("Found BMP280 sensor! No Humidity available."); | |
break; | |
default: | |
Serial.println("Found UNKNOWN sensor! Error!"); | |
} | |
Serial.println("init ok"); | |
display.init(); | |
display.flipScreenVertically(); | |
display.setFont(ArialMT_Plain_10); | |
delay(1500); | |
} | |
void loop() { | |
display.clear(); | |
display.setTextAlignment(TEXT_ALIGN_LEFT); | |
display.setFont(ArialMT_Plain_10); | |
display.drawString(0, 0, "Sending packet: "); | |
display.drawString(90, 0, String(counter)); | |
Serial.println(String(counter)); | |
unsigned long start = millis(); | |
do | |
{ | |
while (GPSSerial.available()) | |
tGps.encode(GPSSerial.read()); | |
} while (millis() - start < 1000); | |
display.drawString(0, 45, "G:"); | |
display.drawString(15, 45, String(tGps.location.lat()) + "," + String(tGps.location.lng()) + "," + String(tGps.altitude.meters()) + "," + String(tGps.satellites.value())); | |
sendLora("Latitude," + String(tGps.location.lat())); | |
sendLora("Longitude," + String(tGps.location.lng())); | |
sendLora("Altitude," + String(tGps.altitude.meters())); | |
sendLora("Speed," + String(tGps.speed.value())); | |
float temp(NAN), hum(NAN), pres(NAN); | |
BME280::TempUnit tempUnit(BME280::TempUnit_Celsius); | |
BME280::PresUnit presUnit(BME280::PresUnit_Pa); | |
bme.read(pres, temp, hum, tempUnit, presUnit); | |
display.drawString(0, 15, "ENV: "); | |
display.drawString(30, 15, String(temp) + "," + String(hum) + "," + String(pres)); | |
sendLora("Temperature," + String(temp)); | |
sendLora("Humidity," + String(hum)); | |
sendLora("Pressure," + String(pres)); | |
// send packet | |
Serial.println("Sending..."); | |
Serial.println(String(counter)); | |
counter++; | |
display.display(); | |
delay(1000); // wait for a second | |
} | |
void sendLora(String msg) { | |
LoRa.beginPacket(); | |
LoRa.print(msg); | |
LoRa.endPacket(); | |
delay(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment