Use PlatformIO to ease user experience

pull/15/head
Sylvain Mougenot 2020-01-04 23:21:43 +01:00
rodzic 38deab2036
commit f905b6c854
6 zmienionych plików z 2291 dodań i 2239 usunięć

5
.gitignore vendored
Wyświetl plik

@ -1,3 +1,6 @@
build
.vscode
other
.pioenvs
.clang_complete
.gcc-flags.json
.pio

Wyświetl plik

@ -1,21 +1,26 @@
# TTGO T-Display
![image](https://github.com/Xinyuan-LilyGO/TTGO-T-Display/blob/master/image/pinmap.jpg)
## 1.Install the following dependency library files:
## 1.Uses the following dependency libraries:
For more informations see the sources
- [TFT_eSPI](https://github.com/Bodmer/TFT_eSPI)
- [Button2](https://github.com/LennartHennigs/Button2)
## 2.TFT_eSPI settings
- Install TFT_eSPI, in `TFT_eSPI/User_Setup_Select.h`, comment out the default settings `#include <User_Setup.h>` , select `#include <User_Setups/Setup25_TTGO_T_Display.h>` , Save Settings.
Settings are managed by the build tooling PlatformIO
- [TFT_eSPI settings](https://github.com/Bodmer/TFT_eSPI/blob/master/Tools/PlatformIO/Configuring%20options.txt)
- based on TFT_eSPI provided values in [User_Setups/Setup25_TTGO_T_Display.h](https://github.com/Bodmer/TFT_eSPI/blob/master/User_Setups/Setup25_TTGO_T_Display.h)
* Like the picture below
![2.png](image/2.png)
## 3.Board choose
- The board can choose `ESP32 Dev Module`, other settings can keep the default
## 3.Install
- [Install PlateformIO](https://docs.platformio.org/en/latest/installation.html#python-package-manager)
- PlatformIO will manage all required software for building (aka: plateform like esp32, dependencies like the above TFT_eSPI)
## 3.Build
- go to the directory of this project
- open a terminal
- build with : `pio run` (first time is long because it needs to download all the requirements)
- upload to the board (needs the borad connected using USB + appropriate user settings see installation) : `pio run --target upload`
- See th e`Serial` output : `pio device monitor --baud 115200`
## Pinout
| Name | V18 |
@ -34,6 +39,3 @@
| BUTTON1 | 35 |
| BUTTON2 | 0 |
| ADC Power | 14 |
2019/08/06:
* The TFT_eSPI and Button2 libraries have been synchronized to the main branch

Plik binarny nie jest wyświetlany.

Przed

Szerokość:  |  Wysokość:  |  Rozmiar: 146 KiB

44
platformio.ini 100644
Wyświetl plik

@ -0,0 +1,44 @@
;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-display]
platform = espressif32@1.11.1
framework = arduino
board = esp32dev
monitor_speed = 115200
build_flags =
-Os
-DUSER_SETUP_LOADED=1
-DST7789_DRIVER=1
-DTFT_WIDTH=135
-DTFT_HEIGHT=240
-DCGRAM_OFFSET=1 ; Library will add offsets required
-DTFT_MOSI=19
-DTFT_SCLK=18
-DTFT_CS=5
-DTFT_DC=16
-DTFT_RST=23
-DTFT_BL=4 ; Display backlight control pin
-DTFT_BACKLIGHT_ON=1 ; HIGH or LOW are options
-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 ; Maximum for ILI9341
-DSPI_READ_FREQUENCY=6000000 ; 6 MHz is the maximum SPI read speed for the ST7789V
lib_deps =
TFT_eSPI@1.4.21
Button2@1.0.0

Wyświetl plik

@ -1,184 +1,187 @@
#include <TFT_eSPI.h>
#include <SPI.h>
#include "WiFi.h"
#include <Wire.h>
#include <Button2.h>
#include "esp_adc_cal.h"
#include "bmp.h"
#ifndef TFT_DISPOFF
#define TFT_DISPOFF 0x28
#endif
#ifndef TFT_SLPIN
#define TFT_SLPIN 0x10
#endif
#define TFT_MOSI 19
#define TFT_SCLK 18
#define TFT_CS 5
#define TFT_DC 16
#define TFT_RST 23
#define TFT_BL 4 // Display backlight control pin
#define ADC_EN 14
#define ADC_PIN 34
#define BUTTON_1 35
#define BUTTON_2 0
TFT_eSPI tft = TFT_eSPI(135, 240); // Invoke custom library
Button2 btn1(BUTTON_1);
Button2 btn2(BUTTON_2);
char buff[512];
int vref = 1100;
int btnCick = false;
//! Long time delay, it is recommended to use shallow sleep, which can effectively reduce the current consumption
void espDelay(int ms)
{
esp_sleep_enable_timer_wakeup(ms * 1000);
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH,ESP_PD_OPTION_ON);
esp_light_sleep_start();
}
void showVoltage()
{
static uint64_t timeStamp = 0;
if (millis() - timeStamp > 1000) {
timeStamp = millis();
uint16_t v = analogRead(ADC_PIN);
float battery_voltage = ((float)v / 4095.0) * 2.0 * 3.3 * (vref / 1000.0);
String voltage = "Voltage :" + String(battery_voltage) + "V";
Serial.println(voltage);
tft.fillScreen(TFT_BLACK);
tft.setTextDatum(MC_DATUM);
tft.drawString(voltage, tft.width() / 2, tft.height() / 2 );
}
}
void button_init()
{
btn1.setLongClickHandler([](Button2 & b) {
btnCick = false;
int r = digitalRead(TFT_BL);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.setTextDatum(MC_DATUM);
tft.drawString("Press again to wake up", tft.width() / 2, tft.height() / 2 );
espDelay(6000);
digitalWrite(TFT_BL, !r);
tft.writecommand(TFT_DISPOFF);
tft.writecommand(TFT_SLPIN);
esp_sleep_enable_ext1_wakeup(GPIO_SEL_35, ESP_EXT1_WAKEUP_ALL_LOW);
esp_deep_sleep_start();
});
btn1.setPressedHandler([](Button2 & b) {
Serial.println("Detect Voltage..");
btnCick = true;
});
btn2.setPressedHandler([](Button2 & b) {
btnCick = false;
Serial.println("btn press wifi scan");
wifi_scan();
});
}
void button_loop()
{
btn1.loop();
btn2.loop();
}
void wifi_scan()
{
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.fillScreen(TFT_BLACK);
tft.setTextDatum(MC_DATUM);
tft.setTextSize(1);
tft.drawString("Scan Network", tft.width() / 2, tft.height() / 2);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
int16_t n = WiFi.scanNetworks();
tft.fillScreen(TFT_BLACK);
if (n == 0) {
tft.drawString("no networks found", tft.width() / 2, tft.height() / 2);
} else {
tft.setTextDatum(TL_DATUM);
tft.setCursor(0, 0);
Serial.printf("Found %d net\n", n);
for (int i = 0; i < n; ++i) {
sprintf(buff,
"[%d]:%s(%d)",
i + 1,
WiFi.SSID(i).c_str(),
WiFi.RSSI(i));
tft.println(buff);
}
}
WiFi.mode(WIFI_OFF);
}
void setup()
{
Serial.begin(115200);
Serial.println("Start");
tft.init();
tft.setRotation(1);
tft.fillScreen(TFT_BLACK);
tft.setTextSize(2);
tft.setTextColor(TFT_WHITE);
tft.setCursor(0, 0);
tft.setTextDatum(MC_DATUM);
tft.setTextSize(1);
if (TFT_BL > 0) { // TFT_BL has been set in the TFT_eSPI library in the User Setup file TTGO_T_Display.h
pinMode(TFT_BL, OUTPUT); // Set backlight pin to output mode
digitalWrite(TFT_BL, TFT_BACKLIGHT_ON); // Turn backlight on. TFT_BACKLIGHT_ON has been set in the TFT_eSPI library in the User Setup file TTGO_T_Display.h
}
tft.setSwapBytes(true);
tft.pushImage(0, 0, 240, 135, ttgo);
espDelay(5000);
tft.setRotation(0);
int i = 5;
while (i--) {
tft.fillScreen(TFT_RED);
espDelay(1000);
tft.fillScreen(TFT_BLUE);
espDelay(1000);
tft.fillScreen(TFT_GREEN);
espDelay(1000);
}
button_init();
esp_adc_cal_characteristics_t adc_chars;
esp_adc_cal_value_t val_type = esp_adc_cal_characterize((adc_unit_t)ADC_UNIT_1, (adc_atten_t)ADC1_CHANNEL_6, (adc_bits_width_t)ADC_WIDTH_BIT_12, 1100, &adc_chars);
//Check type of calibration value used to characterize ADC
if (val_type == ESP_ADC_CAL_VAL_EFUSE_VREF) {
Serial.printf("eFuse Vref:%u mV", adc_chars.vref);
vref = adc_chars.vref;
} else if (val_type == ESP_ADC_CAL_VAL_EFUSE_TP) {
Serial.printf("Two Point --> coeff_a:%umV coeff_b:%umV\n", adc_chars.coeff_a, adc_chars.coeff_b);
} else {
Serial.println("Default Vref: 1100mV");
}
}
void loop()
{
if (btnCick) {
showVoltage();
}
button_loop();
}
#include <TFT_eSPI.h>
#include <SPI.h>
#include "WiFi.h"
#include <Wire.h>
#include <Button2.h>
#include "esp_adc_cal.h"
#include "bmp.h"
#ifndef TFT_DISPOFF
#define TFT_DISPOFF 0x28
#endif
#ifndef TFT_SLPIN
#define TFT_SLPIN 0x10
#endif
#define ADC_EN 14
#define ADC_PIN 34
#define BUTTON_1 35
#define BUTTON_2 0
TFT_eSPI tft = TFT_eSPI(135, 240); // Invoke custom library
Button2 btn1(BUTTON_1);
Button2 btn2(BUTTON_2);
char buff[512];
int vref = 1100;
int btnCick = false;
//! Long time delay, it is recommended to use shallow sleep, which can effectively reduce the current consumption
void espDelay(int ms)
{
esp_sleep_enable_timer_wakeup(ms * 1000);
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH,ESP_PD_OPTION_ON);
esp_light_sleep_start();
}
void showVoltage()
{
static uint64_t timeStamp = 0;
if (millis() - timeStamp > 1000) {
timeStamp = millis();
uint16_t v = analogRead(ADC_PIN);
float battery_voltage = ((float)v / 4095.0) * 2.0 * 3.3 * (vref / 1000.0);
String voltage = "Voltage :" + String(battery_voltage) + "V";
Serial.println(voltage);
tft.fillScreen(TFT_BLACK);
tft.setTextDatum(MC_DATUM);
tft.drawString(voltage, tft.width() / 2, tft.height() / 2 );
}
}
void button_init()
{
btn1.setLongClickHandler([](Button2 & b) {
btnCick = false;
int r = digitalRead(TFT_BL);
tft.fillScreen(TFT_BLACK);
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.setTextDatum(MC_DATUM);
tft.drawString("Press again to wake up", tft.width() / 2, tft.height() / 2 );
espDelay(6000);
digitalWrite(TFT_BL, !r);
tft.writecommand(TFT_DISPOFF);
tft.writecommand(TFT_SLPIN);
esp_sleep_enable_ext1_wakeup(GPIO_SEL_35, ESP_EXT1_WAKEUP_ALL_LOW);
esp_deep_sleep_start();
});
btn1.setPressedHandler([](Button2 & b) {
Serial.println("Detect Voltage..");
btnCick = true;
});
btn2.setPressedHandler([](Button2 & b) {
btnCick = false;
Serial.println("btn press wifi scan");
wifi_scan();
});
}
void button_loop()
{
btn1.loop();
btn2.loop();
}
void wifi_scan()
{
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.fillScreen(TFT_BLACK);
tft.setTextDatum(MC_DATUM);
tft.setTextSize(1);
tft.drawString("Scan Network", tft.width() / 2, tft.height() / 2);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
int16_t n = WiFi.scanNetworks();
tft.fillScreen(TFT_BLACK);
if (n == 0) {
tft.drawString("no networks found", tft.width() / 2, tft.height() / 2);
} else {
tft.setTextDatum(TL_DATUM);
tft.setCursor(0, 0);
Serial.printf("Found %d net\n", n);
for (int i = 0; i < n; ++i) {
sprintf(buff,
"[%d]:%s(%d)",
i + 1,
WiFi.SSID(i).c_str(),
WiFi.RSSI(i));
tft.println(buff);
}
}
WiFi.mode(WIFI_OFF);
}
void setup()
{
Serial.begin(115200);
Serial.println("Start");
Serial.println("tft init");
tft.init();
tft.setRotation(1);
Serial.println("tft to black");
tft.fillScreen(TFT_BLACK);
Serial.println("tft text");
tft.setTextSize(2);
tft.setTextColor(TFT_WHITE);
tft.setCursor(0, 0);
tft.setTextDatum(MC_DATUM);
tft.setTextSize(1);
Serial.println("tft backlight");
if (TFT_BL > 0) { // TFT_BL has been set in the TFT_eSPI library in the User Setup file TTGO_T_Display.h
pinMode(TFT_BL, OUTPUT); // Set backlight pin to output mode
digitalWrite(TFT_BL, TFT_BACKLIGHT_ON); // Turn backlight on. TFT_BACKLIGHT_ON has been set in the TFT_eSPI library in the User Setup file TTGO_T_Display.h
}
Serial.println("tft swap bytes");
tft.setSwapBytes(true);
Serial.println("tft push image");
tft.pushImage(0, 0, 240, 135, ttgo);
espDelay(5000);
Serial.println("tft colors");
tft.setRotation(0);
int i = 5;
while (i--) {
tft.fillScreen(TFT_RED);
espDelay(1000);
tft.fillScreen(TFT_BLUE);
espDelay(1000);
tft.fillScreen(TFT_GREEN);
espDelay(1000);
}
Serial.println("button init");
button_init();
esp_adc_cal_characteristics_t adc_chars;
esp_adc_cal_value_t val_type = esp_adc_cal_characterize((adc_unit_t)ADC_UNIT_1, (adc_atten_t)ADC1_CHANNEL_6, (adc_bits_width_t)ADC_WIDTH_BIT_12, 1100, &adc_chars);
//Check type of calibration value used to characterize ADC
if (val_type == ESP_ADC_CAL_VAL_EFUSE_VREF) {
Serial.printf("eFuse Vref:%u mV", adc_chars.vref);
vref = adc_chars.vref;
} else if (val_type == ESP_ADC_CAL_VAL_EFUSE_TP) {
Serial.printf("Two Point --> coeff_a:%umV coeff_b:%umV\n", adc_chars.coeff_a, adc_chars.coeff_b);
} else {
Serial.println("Default Vref: 1100mV");
}
}
void loop()
{
if (btnCick) {
showVoltage();
}
button_loop();
}

Plik diff jest za duży Load Diff