Add support for BMP280 Sensor

lora-esp32-dev
US1GHQ 2021-08-08 00:16:11 +03:00
parent 19c8cbfaae
commit 2d33740630
2 changed files with 138 additions and 16 deletions

View File

@ -25,9 +25,11 @@ lib_deps =
Adafruit SSD1306
Adafruit GFX Library
Adafruit Unified Sensor
adafruit/Adafruit BMP280 Library @ 2.4.0
https://github.com/SQ9MDD/AXP202X_Library.git
SparkFun u-blox Arduino Library
bblanchon/ArduinoJson
DallasTemperature
build_flags =
-Wl,--gc-sections,--relax
-D 'KISS_PROTOCOL'
@ -44,7 +46,7 @@ build_flags =
-D 'SHOW_RX_PACKET'
-D 'SHOW_RX_TIME=10000'
-D 'TXFREQ=433.775'
; -D 'SPEED_1200' ; comment out to set 300baud
-D 'SPEED_1200' ; comment out to set 300baud
-D 'TXdbmW=20'
-D 'ENABLE_OLED'
-D 'ENABLE_LED_SIGNALING'
@ -53,9 +55,11 @@ build_flags =
-D 'FIX_BEACON_INTERVAL=1800000L'
; -D 'RSSI_SNR_REPORT' ; RSSI and snr report in the KISS PACKET
; -D 'TX_RX_LNA' ; Set external pins for 1W modules
; -D 'USE_BME280' ; Temp sensor for simple WX station
; -D 'HEIGTH_PRESET=34'
[env:ttgo-t-beam-v1.0]
platform = espressif32 @ 3.3.0
platform = espressif32 @ 3.3.1
board = ttgo-t-beam
build_flags =
${env.build_flags}
@ -64,7 +68,7 @@ build_flags =
; -D ENABLE_BLUETOOTH
[env:ttgo-t-beam-v0.7]
platform = espressif32 @ 3.3.0
platform = espressif32 @ 3.3.1
board = ttgo-t-beam
build_flags =
${env.build_flags}
@ -73,7 +77,7 @@ build_flags =
-D T_BEAM_V0_7
[env:ttgo-lora32-v2.1]
platform = espressif32 @ 3.3.0
platform = espressif32 @ 3.3.1
board = ttgo-lora32-v21
build_flags =
${env.build_flags}
@ -82,7 +86,7 @@ build_flags =
-D LORA32_21
[env:ttgo-lora32-v2]
platform = espressif32 @ 3.3.0
platform = espressif32 @ 3.3.1
board = ttgo-lora32-v2
build_flags =
${env.build_flags}
@ -91,7 +95,7 @@ build_flags =
-D LORA32_2
[env:ttgo-lora32-v1]
platform = espressif32 @ 3.3.0
platform = espressif32 @ 3.3.1
board = ttgo-lora32-v1
build_flags =
${env.build_flags}
@ -100,7 +104,7 @@ build_flags =
-D LORA32_1
[env:Heltec-WiFi-v1]
platform = espressif32 @ 3.3.0
platform = espressif32 @ 3.3.1
board = heltec_wifi_kit_32
build_flags =
${env.build_flags}
@ -109,7 +113,7 @@ build_flags =
-D HELTEC_V1
[env:Heltec-WiFi-v2]
platform = espressif32 @ 3.3.0
platform = espressif32 @ 3.3.1
board = heltec_wifi_kit_32_v2
board_build.f_cpu = 80000000L
build_flags =
@ -119,14 +123,14 @@ build_flags =
-D HELTEC_V2
[env:Esp32-Dev-v1]
platform = espressif32 @ 3.3.0
platform = espressif32 @ 3.3.1
board = esp32dev
; change MCU frequency
;board_build.f_cpu = 80000000L
build_flags =
${env.build_flags}
; -D ENABLE_WIFI
-D ENABLE_BLUETOOTH
-D ENABLE_WIFI
; -D ENABLE_BLUETOOTH
-D ESP32_DEV_V1
[env:ttgo-t-beam-v1.0-development]

View File

@ -32,6 +32,10 @@
#include "taskWebServer.h"
#endif
#ifdef USE_BME280
#include <Adafruit_BMP280.h> // BME280 Library
#endif
// oled address
#define SSD1306_ADDRESS 0x3C
@ -123,7 +127,7 @@ double aprsFreq = TXFREQ;
ulong aprsMode = 300;
#endif
boolean gps_state = true;
boolean gps_state = false;
boolean key_up = true;
boolean t_lock = false;
boolean fixed_beacon_enabled = false;
@ -149,6 +153,11 @@ boolean show_cmt = true;
#else
boolean enabled_oled = false;
#endif
#ifdef USE_BME280
boolean enable_bme280 = true;
#else
boolean enable_bme280 = false;
#endif
// Variables and Constants
String loraReceivedFrameString = ""; //data on buff is copied to this string
@ -203,7 +212,7 @@ ulong time_delay = 0;
ulong shutdown_delay = 0;
ulong shutdown_delay_time = 10000;
ulong shutdown_countdown_timer = 0;
boolean shutdown_active =true;
boolean shutdown_active =false;
boolean shutdown_countdown_timer_enable = false;
boolean shutdown_usb_status_bef = false;
#define ANGLE 60 // angle to send packet at smart beaconing
@ -211,6 +220,16 @@ boolean shutdown_usb_status_bef = false;
float average_course[ANGLE_AVGS];
float avg_c_y, avg_c_x;
//Variables for BME Sensors
boolean hum_temp = false;
uint8_t hum_temp_ctr, hum_temp_ctr_max = 3;
boolean tempsensoravailable=true;
float hum=0; //Stores humidity value
float temp=99.99; //Stores temperature value
float tempf=99.99; //Stores temperature value
float pressure=0; //Stores pressure value in hPa
int pressure_offset=0; //Stores offset for pressure correction
uint8_t txPower = TXdbmW;
#ifdef ENABLE_WIFI
@ -239,6 +258,10 @@ uint8_t loraReceivedLength = sizeof(lora_RXBUFF);
#else
#define OLED_RESET 16
#endif
//Temp sensor
#ifdef USE_BME280
Adafruit_BMP280 bme; // if BME is used
#endif
Adafruit_SSD1306 display(128, 64, &Wire, OLED_RESET);
@ -308,12 +331,48 @@ void prepareAPRSFrame(){
}
outString += Talt;
}
}else{ //fixed position not compresed
}
else
{
//fixed position not compresed
outString += aprsLatPreset;
outString += aprsSymbolTable;
outString += aprsLonPreset;
outString += aprsSymbol;
}
#ifdef USE_BME280
if(enable_bme280)
{
// bme.takeForcedMeasurement();
tempf = bme.readTemperature()*9/5+29;
// hum = bme.readHumidity();
pressure = bme.readPressure()/100 + pressure_offset;
outString += ".../...g...t";
if (tempf < 0) { // negative Werte erstellen
outString += "-";
if(tempf>-10) {outString += "0"; }
tempf = abs(tempf);
}
else
{ // positive Werte erstellen
if(tempf<100) {outString += "0"; }
if(tempf<10) {outString += "0"; }
}
helper = String(tempf-3,0);
helper.trim();
outString += helper;
outString += "r...p...P...h";
if(hum<10) {outString += "0"; }
helper = String(hum,0);
helper.trim();
outString += helper;
outString += "b";
if(pressure<1000) {outString += "0"; }
helper = String(pressure*10,0);
helper.trim();
outString += helper;
}
#endif
}
if(show_cmt){
outString += aprsComment;
@ -553,7 +612,9 @@ void sendTelemetryFrame() {
// + SETUP --------------------------------------------------------------+//
void setup(){
SPI.begin(SPI_sck,SPI_miso,SPI_mosi,SPI_ss); //DO2JMG Heltec Patch
bool bme_status;
#ifdef BUZZER
ledcSetup(0,1E5,12);
ledcAttachPin(BUZZER,0);
@ -869,11 +930,28 @@ void setup(){
writedisplaytext("","","","","","");
time_to_refresh = millis() + showRXTime;
displayInvalidGPS();
#ifdef USE_BME280
bme_status = bme.begin(0x76);
if (!bme_status)
{
Serial.println("Could not find a valid BME280 sensor, check wiring!");
//writedisplaytext("LoRa-APRS","","Init:","BME280 ERROR!","","",3000);
tempsensoravailable = false;
}
pressure_offset = calc_pressure_offset(HEIGTH_PRESET);
// bme.takeForcedMeasurement();
temp = bme.readTemperature() - 3; // bme Temperatur auslesen
// hum = bme.readHumidity();
pressure = bme.readPressure()/100 + pressure_offset;
#endif
#ifdef TX_RX_LNA
digitalWrite(TXPIN, LOW);
digitalWrite(RXPIN, HIGH);
#endif
digitalWrite(TXLED, LOW);
hum_temp_ctr = 0;
}
// +---------------------------------------------------------------------+//
@ -971,6 +1049,34 @@ void loop() {
}
#endif
if (hum_temp)
{
++hum_temp_ctr;
if (hum_temp_ctr>hum_temp_ctr_max)
{
hum_temp_ctr = 0;
hum_temp=false;
}
#ifdef USE_BME280
//bme.takeForcedMeasurement();
temp = bme.readTemperature() - 3; // bme Temperatur auslesen
#endif
}
else
{
++hum_temp_ctr;
if (hum_temp_ctr>hum_temp_ctr_max)
{
hum_temp_ctr = 0;
hum_temp=true;
}
#ifdef USE_BME280
//bme.takeForcedMeasurement();
//hum = bme.readHumidity();
pressure = bme.readPressure()/100 + pressure_offset;
#endif
}
if (rf95.waitAvailableTimeout(100)) {
#ifdef T_BEAM_V1_0
#ifdef ENABLE_LED_SIGNALING
@ -1113,4 +1219,16 @@ void loop() {
#endif
#endif
vTaskDelay(1);
}
int calc_pressure_offset(int height) {
//
// A very simple method to calculate the offset for correcting the measured air pressure
// to the pressure at mean sea level (MSL). It is simplificated to "For each 8m change in height
// the pressure is changing by 1hPa."
// The exact method is described at
// https://de.wikipedia.org/wiki/Barometrische_H%C3%B6henformel#Internationale_H%C3%B6henformel
//
int offset = round(height / 8);
return(offset);
}