Test programme for Easy Migration from Arduino IDE to Platform IO Part 2 of 2

Test Program for TTGO issue in PLATFORM IO

main.cpp

//////////////////////////////////////////////////////////////////
// DHT22 Test program for the ESP32 TTGO-T Display //
// Jordan Rubin 2020 //
// More at https://www.youtube.com/c/jordanrubin6502 //
// http://technocoma.blogspot.com //
//////////////////////////////////////////////////////////////////

// Provides a graphical output on the built in display of the TTGO for both
// Temperature and humidity or switch between those and heat index with a
// push of a button. The second button switches everything between Celsius
// and Fahrenheit. Both switches have built in interrupt and debounce.

// Directly related to the video https://youtu.be/C_Th3e-HnDY
#include <Arduino.h>
#include <DHT.h>
#include <TFT_eSPI.h>
#include <SPI>

#define DHTPIN 17
#define DHTTYPE DHT22
#define BUTTON1PIN 35
#define BUTTON2PIN 0 //13 to test

DHT dht(DHTPIN, DHTTYPE);
TFT_eSPI tft = TFT_eSPI();

bool useFahrenheit = true; // Default to Fahrenheit
bool showTemp = true; // Default to Temp / Humidity
long lastDebounceButton1 = 0; // Holds Button1 last debounce
long lastDebounceButton2 = 0; // Holds Button2 last debounce
long debounceDelay = 200; // 200ms between re-polling

// INTRPT Function to execute when Button 1 is Pushed
void IRAM_ATTR toggleButton1() {
if ((millis() - lastDebounceButton1) > debounceDelay) {
if (useFahrenheit){useFahrenheit = false;}
else {useFahrenheit = true;}
lastDebounceButton1 = millis();
}
}

// INTRPT Function to execute when Button 2 is Pushed
void IRAM_ATTR toggleButton2() {
if ((millis() - lastDebounceButton2) > debounceDelay) {
if (showTemp){showTemp = false;}
else {showTemp = true;}
lastDebounceButton2 = millis();
}
}

// What to display if showTemp = true
void showScrn1() {
float t = dht.readTemperature(useFahrenheit);
float h = dht.readHumidity();
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.setCursor(0, 30);
tft.setFreeFont(&Orbitron_Light_24);
tft.println("Temp Humidity");
tft.drawLine(0, 35, 250, 35, TFT_BLUE);
tft.setCursor(0, 60);
tft.print(t);
Serial.print("Temprature: "); Serial.println(t); // Causes issue
if (useFahrenheit){tft.print(F("f"));}
else {tft.print(F("c"));}
tft.setCursor(130, 60);
tft.print(h);tft.print(F("%"));
}

// What to display if showTemp = false
void showScrn2() {
float t = dht.readTemperature(useFahrenheit);
float h = dht.readHumidity();
float hi = dht.computeHeatIndex(t, h, useFahrenheit);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_RED, TFT_BLACK);
tft.setCursor(50, 30);
tft.setFreeFont(&Orbitron_Light_24);
tft.println("Heat Index");
tft.drawLine(0, 35, 250, 35, TFT_BLUE);
tft.setFreeFont(&Orbitron_Light_32);
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.setCursor(60, 100);
tft.print(hi);
if (useFahrenheit){tft.print(F("f"));}
else {tft.print(F("c"));}
}

void setup() {
Serial.begin(115200);
pinMode(BUTTON1PIN, INPUT);
pinMode(BUTTON2PIN, INPUT);
attachInterrupt(BUTTON1PIN, toggleButton1, FALLING);
attachInterrupt(BUTTON2PIN, toggleButton2, FALLING);
dht.begin();
tft.begin();
tft.setRotation(1); //Landscape
}

void loop() {
delay(1000); //Required by this device to function properly
if (showTemp){showScrn1();} // Temp Humidity
else {showScrn2();} // Heat Index
}





platformio.ini

; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:ttgo-lora32-v1]
platform = espressif32
board = ttgo-lora32-v1
framework = arduino
monitor_speed = 115200

lib_deps=
DHT sensor library
TFT_eSPI

build_flags =
-DUSER_SETUP_LOADED=1
-DST7789_DRIVER=1
-DTFT_WIDTH=135
-DTFT_HEIGHT=240
-DCGRAM_OFFSET=1
-DTFT_MOSI=19
-DTFT_SCLK=18
-DTFT_CS=5
-DTFT_DC=16
-DTFT_RST=23
-DTFT_BL=4
-DTFT_BACKLIGHT_ON=HIGH
-DLOAD_GLCD=1
-DLOAD_FONT2=1
-DLOAD_FONT4=1
-DLOAD_FONT6=1
-DLOAD_FONT7=1
-DLOAD_FONT8=1
-DLOAD_GFXFF=1
-DSMOOTH_FONT=1
-DSPI_FREQUENCY=40000000
-DSPI_READ_FREQUENCY=6000000


No comments:

Post a Comment