{"id":2598,"date":"2019-08-06T14:20:09","date_gmt":"2019-08-06T05:20:09","guid":{"rendered":"http:\/\/research.itplants.com\/?p=2598"},"modified":"2019-08-08T08:05:57","modified_gmt":"2019-08-07T23:05:57","slug":"ttgo","status":"publish","type":"post","link":"https:\/\/research.itplants.com\/?p=2598","title":{"rendered":"TTGO-T-Display"},"content":{"rendered":"<p>TTGO\u306f\u3001OLED\u4ed8\u304d\u306eESP32\u3067\u3059\u30021000\u5186\u4ee5\u4e0b\u3067\u8cfc\u5165\u3067\u304d\u307e\u3059\u3002OLED\u306f\u3001ST7789V 1.14inch\u306e\u30c7\u30a3\u30b9\u30d7\u30ec\u30a3\u304cSPI\u3067\u3064\u306a\u304c\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/www.banggood.com\/LILYGO-TTGO-T-Display-ESP32-CP2104-WiFi-bluetooth-Module-1_14-Inch-LCD-Development-Board-For-Arduino-p-1522925.html?rmmds=myorder&amp;cur_warehouse=CN\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-2599\" src=\"https:\/\/research.itplants.com\/wp\/wp-content\/uploads\/2019\/08\/75ef21821e214c3f847895e740484fd4.jpg\" alt=\"\" width=\"373\" height=\"368\" srcset=\"https:\/\/research.itplants.com\/wp\/wp-content\/uploads\/2019\/08\/75ef21821e214c3f847895e740484fd4.jpg 373w, https:\/\/research.itplants.com\/wp\/wp-content\/uploads\/2019\/08\/75ef21821e214c3f847895e740484fd4-300x296.jpg 300w, https:\/\/research.itplants.com\/wp\/wp-content\/uploads\/2019\/08\/75ef21821e214c3f847895e740484fd4-320x316.jpg 320w\" sizes=\"(max-width: 373px) 100vw, 373px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/github.com\/Xinyuan-LilyGO\/TTGO-T-Display\/blob\/master\/TTGO-T-Display.ino\">TTGO-T-Display<\/a>\u3068\u3044\u3046\u30e9\u30a4\u30d6\u30e9\u30ea\u30fc\u3067\u8868\u793a\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u4ed6\u306b\u3082\uff12\u3064\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u30fc\u3082\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/lewisxhe\/TFT_eSPI\">TFT_eSPI<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/lewisxhe\/Button2\">Button2<\/a><\/li>\n<\/ul>\n<h2><a id=\"user-content-2tft_espi-settings\" class=\"anchor\" href=\"https:\/\/github.com\/Xinyuan-LilyGO\/TTGO-T-Display#2tft_espi-settings\" aria-hidden=\"true\"><\/a>2.TFT_eSPI settings<\/h2>\n<ul>\n<li>Move or copy <code>User_Setups\/TTGO_T_Display.h<\/code> to <code>TFT_eSPI\/User_Setups\/<\/code><\/li>\n<li>Add <code>#include &lt;User_Setups\/TTGO_T_Display.h&gt;<\/code> to <code>TFT_eSPI\/User_Setup_Select.h<\/code><\/li>\n<\/ul>\n<p>\u3068\u3042\u308a\u307e\u3059\u304c\u3001<code>TFT_eSPI\/User_Setup_Select.h<\/code>\u5185\u306e<\/p>\n<p>#include &lt;User_Setup.h&gt; \/\/ Default setup is root library folder<\/p>\n<p>\u306f\u3001\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\u3057\u307e\u3059\u3002<\/p>\n<p>Arduino IDE\u3067\u306f\u3001Preferences &gt; \u8ffd\u52a0\u306e\u30dc\u30fc\u30c9\u30de\u30cd\u30fc\u30b8\u30e3\u306eURL\u306b\u3001<\/p>\n<p>https:\/\/docs.heltec.cn\/download\/package_heltec_esp32_index.json<\/p>\n<p>\u3092\u8ffd\u52a0\u3057\u3066\u3001\u30dc\u30fc\u30c9\u30de\u30cd\u30fc\u30b8\u30e3\u3067Heltec\u00a0 WiFi Kit 32\u3092\u9078\u629e\u3057\u307e\u3059\u3002<\/p>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u66f8\u304d\u8fbc\u307f\u6642\u306b\u306f\u3001TTGO\u306e\u53f3\u30dc\u30bf\u30f3\u3092\u62bc\u3059\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>TFT_eSPI tft = TFT_eSPI(<span class=\"pl-c1\">135<\/span>, <span class=\"pl-c1\">240<\/span>); <span class=\"pl-c\">\/\/ Invoke custom library<\/span><\/p>\n<p>\u3092<\/p>\n<p><span class=\"pl-c\">TFT_eSPI tft = TFT_eSPI(240, 320); \/\/ ST7789V<\/span><\/p>\n<p>\u306b\u5909\u66f4\u3057\u306a\u3044\u3068\u3001\u5168\u753b\u9762\u8868\u793a\u3055\u308c\u307e\u305b\u3093\u3002OLED\u306e\u89e3\u50cf\u5ea6\u304c\u4e0a\u304c\u3063\u3066\u3044\u308b\u307f\u305f\u3044\u3067\u3059\u3002<\/p>\n<p>tft.drawString(&#8220;WORD&#8221;, tft.width() \/ 2, tft.height() \/ 2 );<\/p>\n<p>\u3067\u753b\u9762\u4e2d\u592e\u306b\u6587\u5b57\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>tft.setRotation(1);<\/p>\n<p>\u3067\u753b\u9762\u306e\u9577\u3044\u65b9\u5411\u306b\u6587\u5b57\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>tft.pushImage(x_disp_offset, y_disp_offset, 240, 135, ttgo);<\/p>\n<p>tft.drawString(buff, x_disp_offset, y_disp_offset+i*10);<\/p>\n<p>\u306e\u3088\u3046\u306b\u3001x_disp_offset, y_disp_offset\u3092\u4ed8\u3051\u306a\u3044\u3068\u6b63\u78ba\u306a\u4f4d\u7f6e\u306b\u6587\u5b57\u3084\u753b\u50cf\u304c\u8868\u793a\u3055\u308c\u307e\u305b\u3093\u3002<\/p>\n<p>#define x_disp_offset 40<br \/>\n#define y_disp_offset 55<\/p>\n<p>\u307b\u3069\u3067\u6b63\u78ba\u306a\u4f4d\u7f6e\u306b\u8868\u793a\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>TTGO-T-Display.ino<\/p>\n<p>#include &lt;TFT_eSPI.h&gt;<br \/>\n#include &lt;SPI.h&gt;<br \/>\n#include &#8220;WiFi.h&#8221;<br \/>\n#include &lt;Wire.h&gt;<br \/>\n#include &lt;Button2.h&gt;<br \/>\n#include &#8220;esp_adc_cal.h&#8221;<br \/>\n#include &lt;Ticker.h&gt;<br \/>\n#include &#8220;bmp.h&#8221;<\/p>\n<p>#define TFT_MOSI 19<br \/>\n#define TFT_SCLK 18<br \/>\n#define TFT_CS 5<br \/>\n#define TFT_DC 16<br \/>\n#define TFT_RST 23<\/p>\n<p>#define TFT_BL 4 \/\/ Display backlight control pin<br \/>\n#define ADC_EN 14<br \/>\n#define ADC_PIN 34<br \/>\n#define BUTTON_1 35<br \/>\n#define BUTTON_2 0<br \/>\n#define BUTTONS_MAP {BUTTON_1,BUTTON_2}<\/p>\n<p>#define x_disp_offset 40<br \/>\n#define y_disp_offset 55<\/p>\n<p>\/\/TFT_eSPI tft = TFT_eSPI(135, 240); \/\/ Invoke custom library<br \/>\nTFT_eSPI tft = TFT_eSPI(240, 320); \/\/ ST7789V<\/p>\n<p>Button2 *pBtns = nullptr;<br \/>\nuint8_t g_btns[] = BUTTONS_MAP;<br \/>\nchar buff[320];<br \/>\nint vref = 1100;<br \/>\nint btnCick = false;<br \/>\nTicker tick;<\/p>\n<p>void showVoltage()<br \/>\n{<br \/>\nstatic uint64_t timeStamp = 0;<br \/>\nif (millis() &#8211; timeStamp &gt; 1000) {<br \/>\ntimeStamp = millis();<br \/>\nuint16_t v = analogRead(ADC_PIN);<br \/>\nfloat battery_voltage = ((float)v \/ 4095.0) * 2.0 * 3.3 * (vref \/ 1000.0);<br \/>\nString voltage = &#8220;Voltage :&#8221; + String(battery_voltage) + &#8220;V&#8221;;<br \/>\nSerial.println(voltage);<br \/>\ntft.fillScreen(TFT_BLACK);<br \/>\n\/\/tft.setTextDatum(MC_DATUM);<br \/>\ntft.setTextDatum(TC_DATUM);<br \/>\ntft.drawString(voltage, tft.width() \/ 2, tft.height() \/ 2 );<br \/>\n}<br \/>\n}<\/p>\n<p>void button_init()<br \/>\n{<br \/>\nuint8_t args = sizeof(g_btns) \/ sizeof(g_btns[0]);<br \/>\npBtns = new Button2 [args];<br \/>\npBtns[0] = Button2(g_btns[0]);<br \/>\npBtns[1] = Button2(g_btns[1]);<br \/>\npBtns[0].setLongClickHandler([](Button2 &amp; b) {<br \/>\nbtnCick = false;<br \/>\nint r = digitalRead(TFT_BL);<br \/>\ntft.fillScreen(TFT_BLACK);<br \/>\ntft.setTextColor(TFT_GREEN, TFT_BLACK);<br \/>\ntft.setTextDatum(MC_DATUM);<br \/>\ntft.drawString(&#8220;Press again to wake up&#8221;, tft.width() \/ 2, tft.height() \/ 2 );<br \/>\ndelay(3000);<br \/>\ndigitalWrite(TFT_BL, !r);<br \/>\ntft.writecommand(TFT_DISPOFF);<br \/>\ntft.writecommand(TFT_SLPIN);<br \/>\nesp_sleep_enable_ext1_wakeup(GPIO_SEL_35, ESP_EXT1_WAKEUP_ALL_LOW);<br \/>\nesp_deep_sleep_start();<br \/>\n});<br \/>\npBtns[0].setPressedHandler([](Button2 &amp; b) {<br \/>\nSerial.println(&#8220;Detect Voltage..&#8221;);<br \/>\nbtnCick = true;<br \/>\n});<\/p>\n<p>pBtns[1].setPressedHandler([](Button2 &amp; b) {<br \/>\nbtnCick = false;<br \/>\nSerial.println(&#8220;btn press wifi scan&#8221;);<br \/>\nwifi_scan();<br \/>\n});<br \/>\n}<\/p>\n<p>void button_loop()<br \/>\n{<br \/>\nfor (int i = 0; i &lt; sizeof(g_btns) \/ sizeof(g_btns[0]); ++i) {<br \/>\npBtns[i].loop();<br \/>\n}<br \/>\n}<\/p>\n<p>void wifi_scan()<br \/>\n{<br \/>\ntft.setTextColor(TFT_GREEN, TFT_BLACK);<br \/>\ntft.fillScreen(TFT_BLACK);<br \/>\ntft.setTextDatum(MC_DATUM);<br \/>\ntft.setTextSize(1);<\/p>\n<p>tft.drawString(&#8220;Scan Network&#8221;, tft.width() \/ 2, tft.height() \/ 2);<\/p>\n<p>WiFi.mode(WIFI_STA);<br \/>\nWiFi.disconnect();<br \/>\ndelay(100);<\/p>\n<p>int16_t n = WiFi.scanNetworks();<br \/>\ntft.fillScreen(TFT_BLACK);<br \/>\nif (n == 0) {<br \/>\ntft.drawString(&#8220;no networks found&#8221;, tft.width() \/ 2, tft.height() \/ 2);<br \/>\n} else {<br \/>\ntft.setTextDatum(TL_DATUM);<br \/>\ntft.setCursor(0, 0);<br \/>\nSerial.printf(&#8220;Found \nfor (int i = 0; i &lt; n; ++i) {<br \/>\nsprintf(buff,<br \/>\n&#8220;[\ni + 1,<br \/>\nWiFi.SSID(i).c_str(),<br \/>\nWiFi.RSSI(i));<br \/>\n\/\/tft.println(buff);<br \/>\ntft.drawString(buff, x_disp_offset, y_disp_offset+i*10);<br \/>\n}<br \/>\n}<br \/>\nWiFi.mode(WIFI_OFF);<br \/>\n}<\/p>\n<p>void setup()<br \/>\n{<br \/>\nSerial.begin(115200);<br \/>\ndelay(1000);<\/p>\n<p>Serial.println(&#8220;Start&#8221;);<br \/>\n\/\/Serial.println( tft.width());<br \/>\n\/\/Serial.println( tft.height());<br \/>\ntft.init();<br \/>\ntft.setRotation(1);<br \/>\ntft.fillScreen(TFT_BLACK);<br \/>\ntft.setTextSize(2);<br \/>\ntft.setTextColor(TFT_WHITE);<br \/>\ntft.setCursor(0, 0);<br \/>\ntft.setTextDatum(MC_DATUM);<br \/>\ntft.drawString(&#8220;TTGO&#8221;, tft.width() \/ 2, tft.height() \/ 2 );<br \/>\ntft.setTextSize(1);<\/p>\n<p>if (TFT_BL &gt; 0) {<br \/>\npinMode(TFT_BL, OUTPUT);<br \/>\ndigitalWrite(TFT_BL, HIGH);<br \/>\n}<\/p>\n<p>tft.setRotation(1);<br \/>\ntft.pushImage(x_disp_offset, y_disp_offset, 240, 135, ttgo);<br \/>\ndelay(5000);<br \/>\ntft.setRotation(1);<br \/>\nint i = 1;<br \/>\nwhile (i&#8211;) {<br \/>\ntft.fillScreen(TFT_RED);<br \/>\ndelay(1000);<br \/>\ntft.fillScreen(TFT_BLUE);<br \/>\ndelay(1000);<br \/>\ntft.fillScreen(TFT_GREEN);<br \/>\ndelay(200);<br \/>\n}<\/p>\n<p>button_init();<\/p>\n<p>esp_adc_cal_characteristics_t adc_chars;<br \/>\nesp_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, &amp;adc_chars);<br \/>\n\/\/Check type of calibration value used to characterize ADC<br \/>\nif (val_type == ESP_ADC_CAL_VAL_EFUSE_VREF) {<br \/>\nSerial.printf(&#8220;eFuse Vref:\nvref = adc_chars.vref;<br \/>\n} else if (val_type == ESP_ADC_CAL_VAL_EFUSE_TP) {<br \/>\nSerial.printf(&#8220;Two Point &#8211;&gt; coeff_a:\n} else {<br \/>\nSerial.println(&#8220;Default Vref: 1100mV&#8221;);<br \/>\n}<br \/>\n}<\/p>\n<p>void loop()<br \/>\n{<br \/>\nif (btnCick) {<br \/>\nshowVoltage();<br \/>\n}<br \/>\nbutton_loop();<br \/>\n}<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>TTGO\u306f\u3001OLED\u4ed8\u304d\u306eESP32\u3067\u3059\u30021000\u5186\u4ee5\u4e0b\u3067\u8cfc\u5165\u3067\u304d\u307e\u3059\u3002OLED\u306f\u3001ST7789V 1.14inch\u306e\u30c7\u30a3\u30b9\u30d7\u30ec\u30a3\u304cSPI\u3067\u3064\u306a\u304c\u3063\u3066\u3044\u307e\u3059\u3002 TTGO-T-Display\u3068\u3044\u3046\u30e9\u30a4\u30d6\u30e9\u30ea\u30fc\u3067\u8868\u793a\u3067\u304d\u307e\u3059&#8230;<\/p>\n<p><a class=\"more\" href=\"https:\/\/research.itplants.com\/?p=2598\"> Read more &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":2599,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/research.itplants.com\/index.php?rest_route=\/wp\/v2\/posts\/2598"}],"collection":[{"href":"https:\/\/research.itplants.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/research.itplants.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/research.itplants.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/research.itplants.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2598"}],"version-history":[{"count":9,"href":"https:\/\/research.itplants.com\/index.php?rest_route=\/wp\/v2\/posts\/2598\/revisions"}],"predecessor-version":[{"id":2608,"href":"https:\/\/research.itplants.com\/index.php?rest_route=\/wp\/v2\/posts\/2598\/revisions\/2608"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/research.itplants.com\/index.php?rest_route=\/wp\/v2\/media\/2599"}],"wp:attachment":[{"href":"https:\/\/research.itplants.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/research.itplants.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2598"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/research.itplants.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}