mirror of
https://github.com/Xinyuan-LilyGO/TTGO-T-Display.git
synced 2024-09-21 01:47:29 +00:00
init
This commit is contained in:
commit
af162e7ba7
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
build
|
||||
.vscode
|
||||
other
|
28
README.MD
Normal file
28
README.MD
Normal file
@ -0,0 +1,28 @@
|
||||
# TTGO T-Display
|
||||
|
||||
## 1.Install the following dependency library files:
|
||||
- [TFT_eSPI](https://github.com/lewisxhe/TFT_eSPI)
|
||||
- [Button2](https://github.com/lewisxhe/Button2)
|
||||
|
||||
|
||||
## 2.TFT_eSPI settings
|
||||
- Move or copy `User_Setups/TTGO_T_Display.h` to `TFT_eSPI/User_Setups/`
|
||||
- Add `#include <User_Setups/TTGO_T_Display.h>` to `TFT_eSPI/User_Setup_Select.h`
|
||||
|
||||
|
||||
## Pinout
|
||||
| Name | V18 |
|
||||
| ---------- | ------ |
|
||||
| TFT Driver | ST7789 |
|
||||
| TFT_MISO | N/A |
|
||||
| TFT_MOSI | 19 |
|
||||
| TFT_SCLK | 18 |
|
||||
| TFT_CS | 5 |
|
||||
| TFT_DC | 16 |
|
||||
| TFT_RST | N/A |
|
||||
| TFT_BL | 14 |
|
||||
| I2C_SDA | 21 |
|
||||
| I2C_SCL | 22 |
|
||||
| ADC_IN | 34 |
|
||||
| BUTTON1 | 35 |
|
||||
| BUTTON2 | 0 |
|
156
TTGO-T-Display.h.ino
Normal file
156
TTGO-T-Display.h.ino
Normal file
@ -0,0 +1,156 @@
|
||||
#include <TFT_eSPI.h>
|
||||
#include <SPI.h>
|
||||
#include "WiFi.h"
|
||||
#include <Wire.h>
|
||||
#include <Button2.h>
|
||||
#include "esp_adc_cal.h"
|
||||
#include <Ticker.h>
|
||||
|
||||
#define TFT_MOSI 19
|
||||
#define TFT_SCLK 18
|
||||
#define TFT_CS 5
|
||||
#define TFT_DC 16
|
||||
#define TFT_RST 23
|
||||
|
||||
#define TFT_BL 14 // Dispaly backlight control pin
|
||||
#define ADC_PIN 34
|
||||
#define BUTTON_1 35
|
||||
#define BUTTON_2 0
|
||||
#define BUTTONS_MAP {BUTTON_1,BUTTON_2}
|
||||
|
||||
TFT_eSPI tft = TFT_eSPI(135, 240); // Invoke custom library
|
||||
|
||||
Button2 *pBtns = nullptr;
|
||||
uint8_t g_btns[] = BUTTONS_MAP;
|
||||
char buff[512];
|
||||
int vref = 1100;
|
||||
int btnCick = false;
|
||||
Ticker tick;
|
||||
|
||||
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";
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setTextDatum(MC_DATUM);
|
||||
tft.drawString(voltage, tft.width() / 2, tft.height() / 2 );
|
||||
}
|
||||
}
|
||||
|
||||
void button_init()
|
||||
{
|
||||
uint8_t args = sizeof(g_btns) / sizeof(g_btns[0]);
|
||||
pBtns = new Button2 [args];
|
||||
pBtns[0] = Button2(g_btns[0]);
|
||||
pBtns[1] = Button2(g_btns[1]);
|
||||
pBtns[0].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 );
|
||||
delay(6000);
|
||||
digitalWrite(TFT_BL, !r);
|
||||
esp_sleep_enable_ext1_wakeup(GPIO_SEL_35, ESP_EXT1_WAKEUP_ALL_LOW);
|
||||
esp_deep_sleep_start();
|
||||
});
|
||||
pBtns[0].setPressedHandler([](Button2 & b) {
|
||||
Serial.println("Detect Voltage..");
|
||||
btnCick = true;
|
||||
});
|
||||
|
||||
pBtns[1].setPressedHandler([](Button2 & b) {
|
||||
btnCick = false;
|
||||
Serial.println("btn press wifi scan");
|
||||
wifi_scan();
|
||||
});
|
||||
}
|
||||
|
||||
void button_loop()
|
||||
{
|
||||
for (int i = 0; i < sizeof(g_btns) / sizeof(g_btns[0]); ++i) {
|
||||
pBtns[i].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("Fount %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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
|
||||
tft.init();
|
||||
tft.setRotation(0);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setTextSize(2);
|
||||
tft.setTextColor(TFT_WHITE);
|
||||
tft.setCursor(0, 0);
|
||||
tft.setTextDatum(MC_DATUM);
|
||||
tft.drawString("TTGO", tft.width() / 2, tft.height() / 2 );
|
||||
tft.setTextSize(1);
|
||||
|
||||
if (TFT_BL > 0) {
|
||||
pinMode(TFT_BL, OUTPUT);
|
||||
digitalWrite(TFT_BL, HIGH);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
32
TTGO_T-Display.h
Normal file
32
TTGO_T-Display.h
Normal file
@ -0,0 +1,32 @@
|
||||
#define TFT_WIDTH 135
|
||||
#define TFT_HEIGHT 240
|
||||
|
||||
#define ST7789_DRIVER
|
||||
|
||||
#define TFT_MISO -1
|
||||
#define TFT_MOSI 19
|
||||
#define TFT_SCLK 18
|
||||
#define TFT_CS 5
|
||||
#define TFT_DC 16
|
||||
#define TFT_RST 23
|
||||
|
||||
// Non-standard screen, need to add XY coordinate offset
|
||||
#define TTGO_114_INC_DISPLAY
|
||||
|
||||
// #define SPI_FREQUENCY 1000000
|
||||
// #define SPI_FREQUENCY 5000000
|
||||
// #define SPI_FREQUENCY 10000000
|
||||
// #define SPI_FREQUENCY 20000000
|
||||
// #define SPI_FREQUENCY 27000000 // Actually sets it to 26.67MHz = 80/3
|
||||
// #define SPI_FREQUENCY 40000000 // Maximum to use SPIFFS
|
||||
#define SPI_FREQUENCY 80000000
|
||||
|
||||
#define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
|
||||
#define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
|
||||
#define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
|
||||
#define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
|
||||
#define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:.
|
||||
#define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
|
||||
#define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts
|
||||
#define SMOOTH_FONT
|
||||
|
BIN
schematic/TTGO-T-Display.h.pdf
Normal file
BIN
schematic/TTGO-T-Display.h.pdf
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user