Skip to content

Instantly share code, notes, and snippets.

@chartinger
Created May 13, 2019 13:18
Show Gist options
  • Save chartinger/3b8eb889fc291b65176adf80d01a3e0b to your computer and use it in GitHub Desktop.
Save chartinger/3b8eb889fc291b65176adf80d01a3e0b to your computer and use it in GitHub Desktop.
D1 Mini - TFT+BME280 - VSCODE
{
"board": "esp8266:esp8266:d1_mini",
"configuration": "xtal=80,vt=flash,exception=disabled,eesz=4M,ip=lm2f,dbg=Disabled,lvl=None____,wipe=none,baud=921600",
"port": "COM4",
"sketch": "TFT_BMP280.ino",
"output": "./build"
}
{
"configurations": [
{
"name": "Win32",
"includePath": [
"C:\\\\Users\\\\<USER>\\\\AppData\\\\Local\\\\Arduino15\\\\packages\\\\esp8266\\\\tools\\\\**",
"C:\\\\Users\\\\<USER>\\\\AppData\\\\Local\\\\Arduino15\\\\packages\\\\esp8266\\\\hardware\\\\esp8266\\\\2.5.0\\\\**",
"C:\\\\Users\\\\<USER>\\\\Documents\\\\Arduino\\\\libraries\\\\**"
],
"forcedInclude": [
"C:\\\\Users\\\\<USER>\\\\AppData\\\\Local\\\\Arduino15\\\\packages\\\\esp8266\\\\hardware\\\\esp8266\\\\2.5.0\\\\variants\\\\d1_mini\\\\pins_arduino.h"
],
"intelliSenseMode": "gcc-x64",
"compilerPath": "C:\\\\Program Files (x86)\\\\Arduino\\\\hardware\\\\tools\\\\avr\\\\bin\\\\avr-gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"defines": [ "ARDUINO=10809" ]
}
],
"version": 4
}
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <XPT2046_Touchscreen.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <Fonts/FreeMonoBoldOblique12pt7b.h>
#define TFT_CS D0 //for D1 mini or TFT I2C Connector Shield (V1.1.0 or later)
#define TFT_DC D8 //for D1 mini or TFT I2C Connector Shield (V1.1.0 or later)
#define TFT_RST -1 //for D1 mini or TFT I2C Connector Shield (V1.1.0 or later)
#define TS_CS D3 //for D1 mini or TFT I2C Connector Shield (V1.1.0 or later)
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
XPT2046_Touchscreen ts(TS_CS);
#define SEALEVELPRESSURE_HPA (1013.25)
unsigned long delayTime;
Adafruit_BME280 bme; // I2C
void setup()
{
Serial.begin(115200);
bool status;
// default settings
// (you can also pass in a Wire library object like &Wire2)
status = bme.begin();
if (!status) {
Serial.println(F("Could not find a valid BME280 sensor, check wiring!"));
while (1);
}
delayTime = 1000;
Serial.println();
ts.begin();
ts.setRotation(1);
tft.begin();
tft.setRotation(1);
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(3);
tft.println(F("Touch to test"));
while (!Serial && (millis() <= 1000))
;
}
void loop()
{
if (ts.touched())
{
TS_Point p = ts.getPoint();
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(1);
tft.setFont(&FreeMonoBoldOblique12pt7b);
tft.setCursor(0, 20);
tft.println(F("Touch Screen"));
tft.setTextColor(ILI9341_WHITE);
tft.setFont(NULL);
tft.setTextSize(2);
tft.print(F("Pressure = "));
tft.println(p.z);
tft.print(F("X = "));
tft.println(p.x);
tft.print(F("Y = "));
tft.println(p.y);
tft.println();
tft.setTextSize(1);
tft.setTextColor(ILI9341_YELLOW);
tft.setFont(&FreeMonoBoldOblique12pt7b);
tft.println(F("BME280"));
tft.setFont(NULL);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print(F("Temperature = "));
tft.print(bme.readTemperature());
tft.println(F(" C"));
tft.print(F("Pressure = "));
tft.print(bme.readPressure() / 100.0F);
tft.println(F(" hPa"));
tft.print(F("App. Altitude = "));
tft.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
tft.println(F(" m"));
tft.print(F("Humidity = "));
tft.setTextColor(ILI9341_CYAN);
tft.print(bme.readHumidity());
tft.println(F(" %"));
tft.setTextSize(1);
tft.println();
tft.println();
tft.setTextColor(ILI9341_GREENYELLOW);
tft.print(F("ARDUINO = "));
tft.println(ARDUINO);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment