gemu2015 / Sonoff-Tasmota

Tasmota Fork TCS34725,PN532_i2,ccc1101 Moritz support,m5stack 4,7 epaper, hotplug drivers
GNU General Public License v3.0
24 stars 19 forks source link

Arduino_ST7789: 135*240 TFT #28

Closed jeroenvermeulen closed 3 years ago

jeroenvermeulen commented 3 years ago

Copy of Tasmota #10282 to discuss solution.

PROBLEM DESCRIPTION

A 135*240 ST7789 TFT is not working correct, caused by hard-coded _xstart and _ystart in Arduino_ST7789.cpp

REQUESTED INFORMATION

- [x] Provide the output of this command: `Status 0`:
```lua
  STATUS 0 output here:

00:32:36 MQT: stat/ttgo-garage/STATUS = {"Status":{"Module":1,"DeviceName":"ttgo-garage","FriendlyName":["TTGO Garage","Tasmota2"],"Topic":"ttgo-garage","ButtonTopic":"0","Power":3,"PowerOnState":3,"LedState":1,"LedMask":"FFFF","SaveData":1,"SaveState":1,"SwitchTopic":"0","SwitchMode":[0,0,0,0,0,0,0,0],"ButtonRetain":0,"SwitchRetain":0,"SensorRetain":0,"PowerRetain":0}}
00:32:36 MQT: stat/ttgo-garage/STATUS1 = {"StatusPRM":{"Baudrate":115200,"SerialConfig":"8N1","GroupTopic":"tasmotas","OtaUrl":"http://ota.tasmota.com/tasmota32/release/tasmota32.bin","RestartReason":"Vbat power on reset","Uptime":"0T00:09:31","StartupUTC":"2020-12-27T23:23:05","Sleep":50,"CfgHolder":4617,"BootCount":72,"BCResetTime":"2020-12-27T20:47:59","SaveCount":191}}
00:32:36 MQT: stat/ttgo-garage/STATUS2 = {"StatusFWR":{"Version":"9.2.0(tasmota)","BuildDateTime":"2020-12-27T23:51:58","Core":"1_0_4_2","SDK":"v3.3.4-232-g44ec7972b","CpuFrequency":80,"Hardware":"ESP32","CR":"449/699"}}
00:32:36 MQT: stat/ttgo-garage/STATUS3 = {"StatusLOG":{"SerialLog":2,"WebLog":2,"MqttLog":0,"SysLog":0,"LogHost":"","LogPort":514,"SSId":["GRS-IOT",""],"TelePeriod":300,"Resolution":"558180C0","SetOption":["00008009","2805C8000100060000005A00000000000000","00000000","00006000","00000000"]}}
00:32:37 MQT: stat/ttgo-garage/STATUS4 = {"StatusMEM":{"ProgramSize":1408,"Free":1984,"Heap":111,"PsrMax":0,"PsrFree":0,"ProgramFlashSize":4096,"FlashSize":4096,"FlashFrequency":40,"FlashMode":3,"Features":["00000809","8FFAC78F","001403A1","000000CF","010013C0","40000981","00004020","00000000"],"Drivers":"1,2,3,4,5,7,8,9,10,12,13,20,21,24,26,27,29","Sensors":"1,2,3,5,6,62"}}
00:32:37 MQT: stat/ttgo-garage/STATUS5 = {"StatusNET":{"Hostname":"ttgo-garage","IPAddress":"192.168.7.62","Gateway":"192.168.7.1","Subnetmask":"255.255.255.0","DNSServer":"192.168.7.1","Mac":"10:52:1C:66:D8:B0","Webserver":2,"WifiConfig":4,"WifiPower":17.0}}
00:32:37 MQT: stat/ttgo-garage/STATUS6 = {"StatusMQT":{"MqttHost":"192.168.7.2","MqttPort":1883,"MqttClientMask":"ttgo-garage_%06X","MqttClient":"ttgo-garage_66D8B0","MqttUser":"user","MqttCount":1,"MAX_PACKET_SIZE":1200,"KEEPALIVE":30}}
00:32:37 MQT: stat/ttgo-garage/STATUS7 = {"StatusTIM":{"UTC":"2020-12-27T23:32:37","Local":"2020-12-28T00:32:37","StartDST":"2020-03-29T02:00:00","EndDST":"2020-10-25T03:00:00","Timezone":"+01:00","Sunrise":"08:43","Sunset":"17:00"}}
00:32:37 MQT: stat/ttgo-garage/STATUS10 = {"StatusSNS":{"Time":"2020-12-28T00:32:37"}}
00:32:37 MQT: stat/ttgo-garage/STATUS11 = {"StatusSTS":{"Time":"2020-12-28T00:32:37","Uptime":"0T00:09:32","UptimeSec":572,"Heap":111,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":1,"POWER1":"ON","POWER2":"ON","Wifi":{"AP":1,"SSId":"GRS-IOT","BSSId":"02:9F:C2:2D:4C:FD","Channel":9,"RSSI":38,"Signal":-81,"LinkCount":1,"Downtime":"0T00:00:07"}}}

### TO REPRODUCE
_Steps to reproduce the behavior:_
Configure in [Arduino_ST7789.h](https://github.com/arendst/Tasmota/blob/development/lib/lib_display/Arduino_ST7789-gemu-1.0/Arduino_ST7789.h#L42-L46):

define ST7789_TFTWIDTH 135

define ST7789_TFTHEIGHT 240

define ST7789_240x240_XSTART 53

IMG_4501

define ST7789_240x240_YSTART 40

Compile `tasmota32`, flash.
Enter in console:

BackLog DisplayRotate 0; DisplayFont 1; DisplayCols 19; DisplayRows 20; DisplayMode 0 DisplayText [zl1c1]Hello, World!


### EXPECTED BEHAVIOUR
A black display with only the text `Hello World!`

### SCREENSHOTS
![IMG_4500](https://user-images.githubusercontent.com/658024/103181882-877fc200-48a6-11eb-88d5-872ef4da578b.jpg)

### ADDITIONAL CONTEXT
Next step would be to make the width, height, xstart and ystart configurable.
When I undo the two hard-coded overrides in  [Arduino_ST7789.cpp](https://github.com/arendst/Tasmota/blob/83b3aa576da923748e33df154922e1fa2caa980b/lib/lib_display/Arduino_ST7789-gemu-1.0/Arduino_ST7789.cpp#L338-L347), and with my custom settings in [Arduino_ST7789.h](https://github.com/arendst/Tasmota/blob/development/lib/lib_display/Arduino_ST7789-gemu-1.0/Arduino_ST7789.h#L42-L46) it works fine:
![IMG_4501](https://user-images.githubusercontent.com/658024/103182014-ded26200-48a7-11eb-96f4-18b3177bdf38.jpg)

**(Please, remember to close the issue when the problem has been addressed)**
gemu2015 commented 3 years ago

ok did you load my last commit? you need only the driver file (Arduino_ST7789.cpp) do not change anything in the driver, just report what is happening you should only set display width in console to 135

the offset should now be set by the driver automatically to 40, 52

i will adjust things when it goes wrong

jeroenvermeulen commented 3 years ago

I have tested 403dc9ba, I just build your development branch. It is almost right! I suspect you need to change the 52 to 53 but I did not study your changes.

Rotation 0 is one pixel too far to the left: IMG_4513

Rotation 1 is one pixel too far to the top: IMG_4514

Rotation 2 looks perfect but I suspect it is also one pixel off: IMG_4516

Rotation 3 is one pixel too far to the top: IMG_4514

gemu2015 commented 3 years ago

i am bit confused about where to set 52 or 53

there are 3 places to check

please iterate the 52,53 at these places and check the result.

we then can fix the remaining rotations.

if (width==240 && height==240) { _colstart = ST7789_240x240_XSTART; _rowstart = ST7789_240x240_YSTART; } else { _colstart = 40; _rowstart = 52; }

void Arduino_ST7789::setRotation(uint8_t m) {

writecommand(ST7789_MADCTL); rotation = m % 4; // can't be higher than 3 switch (rotation) { case 0: writedata(ST7789_MADCTL_MX | ST7789_MADCTL_MY | ST7789_MADCTL_RGB);

 _xstart = _colstart;
// _ystart = _rowstart;
  if (_width==240 && _height==240) {
    _ystart = 80;
  } else {
    _ystart = 53;
  }
 break;

case 1: writedata(ST7789_MADCTL_MY | ST7789_MADCTL_MV | ST7789_MADCTL_RGB);

 _ystart = _colstart;
// _xstart = _rowstart;
 if (_width==240 && _height==240) {
   _xstart = 80;
 } else {
   _xstart = 53;
 }
 break;

case 2: writedata(ST7789_MADCTL_RGB);

 _xstart = _colstart;
 _ystart = _rowstart;
 break;

case 3: writedata(ST7789_MADCTL_MX | ST7789_MADCTL_MV | ST7789_MADCTL_RGB);

 _ystart = _colstart;
 _xstart = _rowstart;
 break;

} }

jeroenvermeulen commented 3 years ago

I think my previous message was based on the firmware, I am sorry. Your dev branch seems to output build.bin instead of tasmota32.bin Currently testing further.

gemu2015 commented 3 years ago

you can use original tasmota and only take the driver file from my fork

jeroenvermeulen commented 3 years ago

Why don't you merge from upstream?

gemu2015 commented 3 years ago

i want to take control what i merge and keep my own project with some special settings.

gemu2015 commented 3 years ago

ok try my very last version.

i copied the rotation settings from a working driver. it has a different coding of rotations but i think i reordered it right

jeroenvermeulen commented 3 years ago

Maybe you can check if my version still works on 240*240. It is based on your version dd9567a

jeroenvermeulen commented 3 years ago

This are my test commands:

BackLog  DisplayRotate 0; DisplayWidth 135; DisplayHeight 240; DisplayFont 0; DisplayCols 22; DisplayRows 29;
BackLog  DisplayText [zs1l1c1]# Hello how are you? #; DisplayText [s1l29c1]1234567890123456789012

BackLog  DisplayRotate 1; DisplayWidth 240; DisplayHeight 135; DisplayFont 0; DisplayCols 40; DisplayRows 16;
BackLog  DisplayText [zs1l1c1]########## Hello how are you? ##########; DisplayText [s1l16c1]1234567890123456789012345678901234567890

BackLog  DisplayRotate 2; DisplayWidth 135; DisplayHeight 240; DisplayFont 0; DisplayCols 22; DisplayRows 29;
BackLog  DisplayText [zs1l1c1]# Hello how are you? #; DisplayText [s1l29c1]1234567890123456789012

BackLog  DisplayRotate 3; DisplayWidth 240; DisplayHeight 135; DisplayFont 0; DisplayCols 40; DisplayRows 17;
BackLog  DisplayText [zs1l1c1]########## Hello how are you? ##########; DisplayText [s1l16c1]1234567890123456789012345678901234567890
gemu2015 commented 3 years ago

are you sure about your modifications? there is a discussion in a driver forum with a sample driver that definitely has also offsets of 53 ?

gemu2015 commented 3 years ago

https://github.com/Bodmer/TFT_eSPI/issues/379

jeroenvermeulen commented 3 years ago

I have just built your universal branch, commit ebfb6a21 This is Tasmota 9.1.0.2

IMG_4517

IMG_4518

IMG_4521

IMG_4522

gemu2015 commented 3 years ago

probably you won't see 1 pixel offsets with text. you should draw rectangles with full size to test like in the link

jeroenvermeulen commented 3 years ago

You are right, I found 1 pixel off in Rotate 1 using a rectangle. Working on a fix.

gemu2015 commented 3 years ago

2 rotates should have 53 and 2 52

jeroenvermeulen commented 3 years ago

Test universal branch with PR #30 changes, Tasmota 9.1.0.2

BackLog  DisplayRotate 0; DisplayWidth 135; DisplayHeight 240; DisplayFont 0; DisplayCols 22; DisplayRows 29;
DisplayText [zr135:240s2l2c2] Tasmota [s1l7c2] IPS ST7789V 1.14" [l9c2] 135 x 240 [l11c2] Rotate 0

BackLog  DisplayRotate 1; DisplayWidth 240; DisplayHeight 135; DisplayFont 0; DisplayCols 40; DisplayRows 16;
DisplayText [zr240:135s2l2c7] Tasmota [s1l7c2] IPS ST7789V 1.14" 135 x 240 [l9c2] Rotate 1

BackLog  DisplayRotate 2; DisplayWidth 135; DisplayHeight 240; DisplayFont 0; DisplayCols 22; DisplayRows 29;
DisplayText [zr135:240s2l2c2] Tasmota [s1l7c2] IPS ST7789V 1.14" [l9c2] 135 x 240 [l11c2] Rotate 2

BackLog  DisplayRotate 3; DisplayWidth 240; DisplayHeight 135; DisplayFont 0; DisplayCols 40; DisplayRows 17;
DisplayText [zr240:135s2l2c7] Tasmota [s1l7c2] IPS ST7789V 1.14" 135 x 240 [l9c2] Rotate 3

IMG_4525

IMG_4526

IMG_4528

IMG_4524

gemu2015 commented 3 years ago

ok well done, had to change one define for my display but now it works for my display too. i also removed some unnecessary code

please test again and then you can make a pr to tasmota.

jeroenvermeulen commented 3 years ago

Thanks, will do it this evening (in Belgium)

jeroenvermeulen commented 3 years ago

@gemu2015 Can you maybe take a look at the compiler errors? https://github.com/gemu2015/Sonoff-Tasmota/pull/30#issuecomment-751878988 To repeat the warning you need to remove the .cache and .pio dirs and compile.

jeroenvermeulen commented 3 years ago

Never mind, I see you already fixed it

blakadder commented 3 years ago

I have version using

backlight_pin: GPIO5
cs_pin: GPIO22
dc_pin: GPIO21
reset_pin: GPIO18
clk_pin: GPIO19
mosi_pin: GPIO23
miso_pin: GPIO25
TFT_WIDTH=240
TFT_HEIGHT=320
TFT_INVERSION_OFF     ; for normal colors
TFT_RGB_ORDER=TFT_BGR ; Colour order Blue-Green-Red

with an FT6336U touch chip

jeroenvermeulen commented 3 years ago

@blakadder Can you test my PR https://github.com/arendst/Tasmota/pull/10310 ?

blakadder commented 3 years ago

couldn't even get it to display anything

jeroenvermeulen commented 3 years ago

@blakadder Do you have a link to the product you have?

blakadder commented 3 years ago

https://blakadder.com/lanbon-L8/

gemu2015 commented 3 years ago

@blakadder did you use the very last dev version from today ?

and how did you connect your pins ? i use SSPI on both devices i have and did not test with spi (spi should work also i assume).

then in console type display and check if the driver was found.

if found, set the width to 320 for your display

since your display is the max possible resolution of the chip the zero offsets should work.

at least you should be able to switch backlight On and Off and see partial pictures

blakadder commented 3 years ago

pins are not changeable and are as follows

backlight_pin: GPIO5
cs_pin: GPIO22
dc_pin: GPIO21
reset_pin: GPIO18
clk_pin: GPIO19
mosi_pin: GPIO23
miso_pin: GPIO25
gemu2015 commented 3 years ago

i meant what was your pin function selection in Tasmota ?

i would suggest:

backlight_pin: GPIO5 Backlight cs_pin: GPIO22 ST7789_CS dc_pin: GPIO21 ST7789_DC reset_pin: GPIO18 OLED_Reset clk_pin: GPIO19 SSPI_SCLK mosi_pin: GPIO23 SSPI_MOSI miso_pin: GPIO25 not needed for display

blakadder commented 3 years ago

ok got it working with that config... looks fine out of the box

gemu2015 commented 3 years ago

nice to hear

gemu2015 commented 3 years ago

to get the touch screen working you need to (only with scripting)

define USE_FT5206

define USE_TOUCH_BUTTONS

you then in a script can define touch buttons directly linked with relays or virtual buttons

blakadder commented 3 years ago

one more hiccup: my display has inverted colors

gemu2015 commented 3 years ago

this driver inverts your display (if width or height == 320)

Arduino_ST7789.cpp.zip

virtualizer-ham commented 3 years ago

Hello gemu2015, respect for your work, just came along since I bought the same device and am trying to get something drawn/written to this nice little board with display! But I'm going nearly crazy, I already checked out your Repo and compiled it, checked also the dev-repo from tasmota / Theo Arends out and compiled it (9.2.0.3), tried to use the nightly esp32 builds provided by Theo Arends and tried also nearly each combination of gpio setup for this device, only thing that works: Switching backlight on/off !

I don't know what I'm doing wrong, but trying to write out some text, also using your examples above, ends up with no output at all. Also playing with the fore- and background colours makes no difference.

When the device freshly powers up you see some kind of initialization (white stripes going down), then it goes to black screen and stays there. Playing with DisplayDimmer only makes the background look brighter or darker, that's it.

Actual configuration: GPIO4: Backlight GPIO5: ST7789CS GPIO16: ST7789DC GPIO18: SSPI SCLK GPIO19: SSPI MOSI GPIO23: OLED Reset

Program Version 9.2.0.3(display) Core/SDK Version 1_0_5_RC4/v3.3.4-286-gb4c075169

But trying out all other combinations with SPI, SSPI etc. only lead to no recognition of the display. Please shed some light on me...

Greetings joe

gemu2015 commented 3 years ago

what hardware do you have ? if you have the 135x240 board you should ask @jeroenvermeulen

virtualizer-ham commented 3 years ago

Hi, I also have the TTGO T-Display Dev-Board with 1.14" TFT. OK, so now my question goes to jeroenvermeulen :-)

jeroenvermeulen commented 3 years ago

These are my notes:

GPIO19 = SSPI MOSI/SID
GPIO18 = SSPI SCLK
GPIO5  = ST7789 CS
GPIO16 = ST7789 DC
GPIO23 = OLED Reset
GPIO4  = Backlight

Template for Software SPI:

{"NAME":"TTGO T-Display v1.1","GPIO":[1,1,1,1,992,6592,1,1,1,1,1,1,6624,1,896,864,0,640,608,1024,0,1,1,1,0,0,0,0,1,1,1,1,1,0,0,1],"FLAG":0,"BASE":1}

To test I enter in console:

BackLog  DisplayModel 12; DisplayRotate 0; DisplayWidth 135; DisplayHeight 240; DisplayFont 0; DisplayCols 22; DisplayRows 29;
DisplayText [zr135:240s2C63488l2c2] Tasmota [s1C31l7c2] IPS ST7789V 1.14" [l9c2] 135 x 240 [l11c2] Rotate 0

Does this help?

virtualizer-ham commented 3 years ago

Hi Jeroenvermeulen, thank you for your very fast reply also! It seems, the Template did the trick!!! I was using before the standard ESP32DEV template and had the GPIO's configured same like you (and all other combinations...), without success, now I activated the template and copy/pasted your test strings: That's it! Works!

Thank you so much! I was already going crazy about no succes even doing (nearly) everything like stated in this thread and all others I found on the Net.

Have a nice evening and thank you again for your help, also to Gemu2015! Greetings Joe

jeroenvermeulen commented 3 years ago

You're welcome. To make this help complete:

I build tasmota32, this should be possible using the current development branch. You need to have PlatformIO Core and esptool installed.

I use these settings in tasmota/user_config_override.h:

#define USE_DISPLAY
#define USE_DISPLAY_ST7789
#define USE_SPI
#define SHOW_SPLASH

Build command:

platformio run -e tasmota32

Flash command:

BINDIR="build_output/firmware"
SERIAL="/dev/tty.usbserial-01F93A32"
wget https://github.com/arendst/Tasmota/raw/firmware/firmware/tasmota32/ESP32_needed_files/bootloader_dout_40m.bin -O $BINDIR/bootloader_dout_40m.bin
wget https://github.com/arendst/Tasmota/raw/firmware/firmware/tasmota32/ESP32_needed_files/partitions.bin -O $BINDIR/partitions.bin
wget https://github.com/arendst/Tasmota/raw/firmware/firmware/tasmota32/ESP32_needed_files/boot_app0.bin -O $BINDIR/boot_app0.bin
esptool.py \
  --chip esp32 \
  --port $SERIAL \
  --baud 921600 \
  --before default_reset \
  --after hard_reset \
  write_flash \
  -z \
  --flash_mode dout \
  --flash_freq 40m \
  --flash_size detect \
  0x1000 $BINDIR/bootloader_dout_40m.bin \
  0x8000 $BINDIR/partitions.bin \
  0xe000 $BINDIR/boot_app0.bin \
  0x10000 $BINDIR/tasmota32.bin
virtualizer-ham commented 3 years ago

OK, thank you very much for this information, PlatformIO is already setup, GIT and ESPTOOL also, but since I'm quite new to this I was already wondering how to not build the whole platforms and derivates, flashing was no problem, using Tasmota already some time longer, but selfcompiling was the challenge...will try your settings! Thank's a lot!

no-Legend commented 2 years ago

Hi together is there still the need to compile by my self? Or is the Ttgo display already in the stable branch or the development branch?

Cheers Robert

jeroenvermeulen commented 2 years ago

On https://tasmota.github.io/docs/Firmware-Builds/#available-features-and-sensors you can search for USE_DISPLAY_ST7789. You will see it is not included by default in any build.

There is a Universal Display Driver, the file is here. The last time I have worked with a universal display driver it did not work as good as a compiled driver. It can also be quite a hassle to get it working.

no-Legend commented 2 years ago

So at the moment I got some information on the display. Could it be that I nee first to Set the Displaymode to 0 (DisplayText)?

jeroenvermeulen commented 2 years ago

Can you send a photo?

no-Legend commented 2 years ago

I just figured out, that I need to to configure a button. An after I pushed the button, the display shows something. A second push let the display turn off. Is this behaviour correct? Edit: No correct, you need to activate the Backlight by using the Toggle Switch on the WebGui

jeroenvermeulen commented 2 years ago

Yes, kind of. You can also use the Tasmota web interface. When there is a pin configured for the Display Background / Led, the last 'Toggle' button can be used to switch the display on/off. If you wish you can connect a physical button to this toggle.

no-Legend commented 2 years ago

I did not understand the button behaviour. When I configure a button in "Configure Module" should it normaly appears in on the first page of the webgui? It looks like every button number I choose is for turning the display on or off. I also didn't do any rules.

jeroenvermeulen commented 2 years ago

Can you maybe try to not configure a pin for Backlight? If you need a button to switch something else you can add a Relay with the same number.