I have been working several days to get a working demo sketch for the MATouch 2.1" Rotary Touchscreen to function via platformIO. I have tried numerous configurations, versions of libraries, various board.build options, and each time I end up with a backlit screen.
Per their Wiki, Arduino IDE 1.8 must be utilized when working with the arduino IDE, ESP32 arduino core 2.0.6, and GFX for Arduino v1.3.1 or 1.3.6-1.3.8.
The latest attempted uploaded code is this:
/********************Requires Espressive core 6.0.1 to get arduino esp32 @ 2.0.6 *****************/
#include <arduino.h>
#include <Arduino_GFX_Library.h>
#include <Wire.h>
#include "touch.h"
#define I2C_SDA_PIN 17
#define I2C_SCL_PIN 18
#define TOUCH_RST -1 // 38
#define TOUCH_IRQ -1 // 0
#define TFT_BL 38
#define BUTTON_PIN 14
#define ENCODER_CLK 13 // CLK
#define ENCODER_DT 10 // DT
int counter = 0;
int State;
int old_State;
int move_flag = 0;
int button_flag = 0;
int flesh_flag = 1;
int x = 0, y = 0;
#define COLOR_NUM 5
int ColorArray[COLOR_NUM] = {WHITE, BLUE, GREEN, RED, YELLOW};
// #define COLOR_NUM 18
// int ColorArray[18] = {BLUE, GREEN, WHITE, RED, ORANGE, NAVY, DARKGREEN, DARKCYAN, MAROON, PURPLE, OLIVE, LIGHTGREY, DARKCYAN, DARKGREY, MAGENTA, YELLOW, GREENYELLOW, PINK};
#if 0 //for Arduino_GFX_Library v1.3.1
Arduino_ESP32RGBPanel *bus = new Arduino_ESP32RGBPanel(
1 /* CS */, 46 /* SCK */, 0 /* SDA */,
2 /* DE */, 42 /* VSYNC */, 3 /* HSYNC */, 45 /* PCLK */,
11 /* R0 */, 15 /* R1 */, 12 /* R2 */, 16 /* R3 */, 21 /* R4 */,
39 /* G0/P22 */, 7 /* G1/P23 */, 47 /* G2/P24 */, 8 /* G3/P25 */, 48 /* G4/P26 */, 9 /* G5 */,
4 /* B0 */, 41 /* B1 */, 5 /* B2 */, 40 /* B3 */, 6 /* B4 */
);
// Uncomment for 2.1" round display
Arduino_ST7701_RGBPanel *gfx = new Arduino_ST7701_RGBPanel(
bus, GFX_NOT_DEFINED /* RST */, 0 /* rotation */,
false /* IPS */, 480 /* width */, 480 /* height */,
st7701_type5_init_operations, sizeof(st7701_type5_init_operations),
true /* BGR */,
10 /* hsync_front_porch */, 8 /* hsync_pulse_width */, 50 /* hsync_back_porch */,
10 /* vsync_front_porch */, 8 /* vsync_pulse_width */, 20 /* vsync_back_porch */);
#endif //end of for Arduino_GFX_Library v1.3.1
#if 1 //for Arduino_GFX_Library v1.3.6/v1.3.8
Arduino_DataBus *bus = new Arduino_SWSPI(
GFX_NOT_DEFINED /* DC */, 1 /* CS */,
46 /* SCK */, 0 /* MOSI */, GFX_NOT_DEFINED /* MISO */);
Arduino_ESP32RGBPanel *rgbpanel = new Arduino_ESP32RGBPanel(
2 /* DE */, 42/* VSYNC */, 3 /* HSYNC */, 45 /* PCLK */,
4 /* R0 */, 41 /* R1 */, 5 /* R2 */, 40 /* R3 */, 6 /* R4 */,
39 /* G0/P22 */, 7 /* G1/P23 */, 47 /* G2/P24 */, 8 /* G3/P25 */, 48 /* G4/P26 */, 9 /* G5 */,
11 /* B0 */, 15 /* B1 */, 12 /* B2 */, 16 /* B3 */, 21 /* B4 */,
1 /* hsync_polarity */, 10 /* hsync_front_porch */, 8 /* hsync_pulse_width */, 50 /* hsync_back_porch */,
1 /* vsync_polarity */, 10 /* vsync_front_porch */, 8 /* vsync_pulse_width */, 20 /* vsync_back_porch */);
Arduino_RGB_Display *gfx = new Arduino_RGB_Display(
480 /* width */, 480 /* height */, rgbpanel, 0 /* rotation */, true /* auto_flush */,
bus, GFX_NOT_DEFINED /* RST */, st7701_type5_init_operations, sizeof(st7701_type5_init_operations));
#endif //End of for Arduino_GFX_Library v1.3.6/v1.3.8
void setup()
{
USBSerial.begin(115200);
pin_init();
delay(1000);
Serial.println("Test V1.1");
Wire.begin(I2C_SDA_PIN, I2C_SCL_PIN);
// Init Display
gfx->begin();
}
void loop()
{
if (read_touch(&x, &y) == 1)
{
USBSerial.print("Touch ");
USBSerial.print(x);
USBSerial.print("\t");
USBSerial.println(y);
flesh_flag = 1;
}
if (digitalRead(BUTTON_PIN) == 0)
{
if (button_flag != 1)
{
button_flag = 1;
flesh_flag = 1;
}
USBSerial.println("Button Press");
}
else
{
if (button_flag != 0)
{
button_flag = 0;
flesh_flag = 1;
}
}
if (move_flag == 1)
{
USBSerial.print("Position: ");
USBSerial.println(counter);
move_flag = 0;
flesh_flag = 1;
}
if (flesh_flag == 1)
page_1();
delay(100);
}
void pin_init()
{
pinMode(TFT_BL, OUTPUT);
digitalWrite(TFT_BL, HIGH);
pinMode(ENCODER_CLK, INPUT_PULLUP);
pinMode(ENCODER_DT, INPUT_PULLUP);
old_State = digitalRead(ENCODER_CLK);
attachInterrupt(ENCODER_CLK, encoder_irq, CHANGE);
}
void encoder_irq()
{
State = digitalRead(ENCODER_CLK);
if (State != old_State)
{
if (digitalRead(ENCODER_DT) == State)
{
counter++;
}
else
{
counter--;
}
}
old_State = State; // the first position was changed
move_flag = 1;
}
void page_1()
{
String temp = "";
gfx->fillScreen(ColorArray[((unsigned)counter / 2 % COLOR_NUM)]);
gfx->setTextSize(4);
gfx->setTextColor(BLACK);
gfx->setCursor(120, 100);
gfx->println(F("Makerfabs"));
gfx->setTextSize(3);
gfx->setCursor(30, 160);
gfx->println(F("2.1inch TFT with Touch "));
gfx->setTextSize(4);
gfx->setCursor(60, 200);
temp = temp + "Encoder: " + counter;
gfx->println(temp);
gfx->setTextSize(4);
gfx->setCursor(60, 240);
temp = "";
temp = temp + "BUTTON: " + button_flag;
gfx->println(temp);
gfx->setTextSize(4);
gfx->setCursor(60, 280);
temp = "";
temp = temp + "Touch X: " + x;
gfx->println(temp);
gfx->setTextSize(4);
gfx->setCursor(60, 320);
temp = "";
temp = temp + "Touch Y: " + y;
gfx->println(temp);
// gfx->fillRect(240, 400, 30, 30, ColorArray[(((unsigned)counter / 2 + 1) % COLOR_NUM)]);
flesh_flag = 0;
}
Which yields this from terminal:
Processing esp32-s3-devkitc-1 (platform: espressif32@6.0.1; board: esp32-s3-devkitc-1; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32-s3-devkitc-1.html
PLATFORM: Espressif 32 (6.0.1) > Espressif ESP32-S3-DevKitC-1-N8 (8 MB QD, No PSRAM)
HARDWARE: ESP32S3 240MHz, 320KB RAM, 8MB Flash
DEBUG: Current (esp-builtin) On-board (esp-builtin) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
- framework-arduinoespressif32 @ 3.20006.221224 (2.0.6)
- tool-esptoolpy @ 1.40400.0 (4.4.0)
- tool-mkfatfs @ 2.0.1
- tool-mklittlefs @ 1.203.210628 (2.3)
- tool-mkspiffs @ 2.230.0 (2.30)
- toolchain-riscv32-esp @ 8.4.0+2021r2-patch5
- toolchain-xtensa-esp32s3 @ 8.4.0+2021r2-patch5
Converting fw_test.ino
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 34 compatible libraries
Scanning dependencies...
Dependency Graph
|-- GFX Library for Arduino @ 1.3.8
|-- Wire @ 2.0.0
Building in release mode
Compiling .pio\build\esp32-s3-devkitc-1\src\fw_test.ino.cpp.o
Retrieving maximum program size .pio\build\esp32-s3-devkitc-1\firmware.elf
Checking size .pio\build\esp32-s3-devkitc-1\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [= ] 6.3% (used 20740 bytes from 327680 bytes)
Flash: [= ] 9.2% (used 307033 bytes from 3342336 bytes)
Configuring upload protocol...
AVAILABLE: cmsis-dap, esp-bridge, esp-builtin, esp-prog, espota, esptool, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa
CURRENT: upload_protocol = esptool
Looking for upload port...
Auto-detected: COM5
Uploading .pio\build\esp32-s3-devkitc-1\firmware.bin
esptool.py v4.4
Serial port COM5
Connecting...
Chip is ESP32-S3 (revision v0.2)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 80:65:99:bd:15:10
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Flash will be erased from 0x00000000 to 0x00003fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x00010000 to 0x0005bfff...
Compressed 14768 bytes to 10149...
Writing at 0x00000000... (100 %)
Wrote 14768 bytes (10149 compressed) at 0x00000000 in 0.3 seconds (effective 419.1 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 146...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (146 compressed) at 0x00008000 in 0.1 seconds (effective 406.6 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 47...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.1 seconds (effective 483.4 kbit/s)...
Hash of data verified.
Compressed 307424 bytes to 173952...
Writing at 0x00010000... (9 %)
Writing at 0x0001b32b... (18 %)
Writing at 0x0002417a... (27 %)
Writing at 0x00029c48... (36 %)
Writing at 0x0002f1bb... (45 %)
Writing at 0x000347df... (54 %)
Writing at 0x00039f27... (63 %)
Writing at 0x0004250f... (72 %)
Writing at 0x0004c309... (81 %)
Writing at 0x00051ef7... (90 %)
Writing at 0x000576bd... (100 %)
Wrote 307424 bytes (173952 compressed) at 0x00010000 in 2.5 seconds (effective 976.6 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
=========================================================== [SUCCESS] Took 9.58 seconds ===========================================================
* Terminal will be reused by tasks, press any key to close it.
Last attempted platform.ini:
[env:esp32-s3-devkitc-1]
platform = espressif32@6.0.1
board = esp32-s3-devkitc-1
framework = arduino
lib_deps = moononournation/GFX Library for Arduino@1.3.8
Something that does stand out to me is that the configuration detailed toward the bottom of the wiki for utilizing platformIO specifies a verison of the board with no PSRAM, although the arduino board configuration specifies it.
The chip itself is an R8, which I think has no psram?
I attempted to utilize the esp32 dev board and configure the board.build in the ini file, but I succeeded in boot looping the MATouch. I became frustrated and deleted all of the projects, so it would take me a few minutes to reference board.txt and figure out what I had done.
I am very curious about board_build.partitions as it should be 16M per the board.txt and arduino board selection. I have noticed that the addresses are different when the board is being flashed in pio or arduino ide.
I can flash from pio, get a blank screen, alt-tab to the arduino IDE and flash, and have a functioning user interface.
I have several threads I have referenced but I’m a new user and cannot post them.
I need help with what I am missing please. I am a novice and work on this in my spare time. My plan was to utilize a UI generated in Squareline Studio, but I cannot get it or any of the demos to successfully flash through pio.