ESP32-2432S028 - 2.8" LCD ILI9341 XPT2046 Resistive Touch screen - rotation / x y mirror swap / colors / ... issues #7507
Replies: 1 comment
-
Posted at 2025-01-27 by @MaBecker Same same but different.... When starting with LCD_SPI_UNBUF LCD Library Gordon recommend not to include the display initialisation into firmware because things like this can happen easily. To be honest, I am very happy that you Gordon implemented the ESP32_CYD board, because it is a perfect example howto integrated a display with touch into firmware. Posted at 2025-01-27 by @MaBecker @allObjects I guess there are two settings that need to be adapted
Posted at 2025-01-27 by @MaBecker some quick hack for additional lcd functions for ESP32_CYD
https://cdn-shop.adafruit.com/datasheets/ILI9341.pdf Chapter 8. Command and Chapter 9.3. MCU to memory write/read direction Posted at 2025-01-27 by @gfwilliams Hopefully @MaBecker's code will work? So you're running with the ESP32_CYD build @allObjects? It's really strange - I've tried on both the micro usb and USB-C variants and it works great for me. I wonder if maybe the display library should just be waiting a bit longer after power on before it initialised the display in your case? Posted at 2025-01-27 by @allObjects @gfwilliams, 2V25.40... good point, that the display setup could kick in too early... so far I have no application code that is drawing immediately... What you see is what is flashed... only the rectangle is custom drawn with a delay of 1000ms and 250ms (both delays show same result). Did not rerun the init with different values yet - as @MaBecker's suggested. Posted at 2025-01-27 by @MaBecker lcd init sequence from firmware
0x20/* ILI_INVERS_OFF */ is missing Power on and this is what you get Attachments: Posted at 2025-01-27 by @allObjects Just applied the definitions from espruino.com/modules with delay after power cycle reset of the hardware, ESP32 'os', Espruino 2v25.40 init:
and attached is what I get: Note the text is reversed (screen colors too... but not relevant). Attachments: Posted at 2025-01-28 by @MaBecker @gfwilliams Is there a way to Posted at 2025-01-28 by @allObjects Did some more work. Took espruino.com/module in pieces as app into IDE, supplied SPI and port info, ran the initialization, rotated and displayed rectangles, text and touch coordinates - with the results shown in attached picture and I can conclude a workable version. Colors still need a look and touch raw values as well as processing rage needs adjustment. The upper line of coordinates shows the expected coordinates for the left top corner of the bottom large right rectangle. Touching there shows an average error of 7+. Touching in the 0/0 - top left - and 320/240 - bottom right - corner shows significant errors too that need adjustment in a module... and a damper/tamer on the event ratio... In the next post I will show the code and the differences in initialization of flashed Espruino 2v25.40 version vs. module's verison. Attachments: Posted at 2025-01-28 by @allObjects The code I used to play around with a better initialization and the touch information:
Since the colors do not look right yet, I'm comparing the initialization values from both module and source of flashed version. There are definitively differences between the values and the sequence, and also definitively also between the underlaying hw/sw, because my device initializes portrait w/ upside down - ESP32module on the bottom - and incorrectly vs other people's device that initialize landscape w/ ESP32 module on the left. I'm curious what the cause might be... also that the colors are still not right. Because of (almost always wrapping in forum format), I also attache the comparison as text file. For best UX viewing experience, you may need to find the sweet spot of browser window width so that not even the longest lines wrap... (may though still do depending on font size settings for accessibility in your browser); narrower window / smaller witdth is - counter-intuitively - better, because the two column post layout css break delivers widest text / code / image attachment box; 3rd column content becomes right-slide-in, accessible w/ forum menu [...] button) :\
Attachments: Posted at 2025-01-28 by @allObjects As @MaBecker pointed out to me, command
Attachments: Posted at 2025-01-28 by @gfwilliams I think the display can be read, yes - miso seems to be connected. In the spilcd code we have this hard-coded init code as you noted @MaBecker: https://github.com/espruino/Espruino/blob/672e95948d9e1a74f739d6b1cda1c12cdab78aaa/libs/graphics/lcd_spilcd_info.h#L22-L49 But in LCD_FSMC (the code used for the older STM32-based 320x240 LCD dev boards) we have some code that actually reads back the LCD model number and then applies the correct initialisation code based on that: https://github.com/espruino/Espruino/blob/672e95948d9e1a74f739d6b1cda1c12cdab78aaa/libs/graphics/lcd_fsmc.c#L679 I guess it might be we need to do something similar here - it'd be very interesting if you could read back the device code: https://github.com/espruino/Espruino/blob/672e95948d9e1a74f739d6b1cda1c12cdab78aaa/libs/graphics/lcd_fsmc.c#L662-L677 Posted at 2025-01-28 by @allObjects interesting, and thank you for providing this insight. I'll give that a shot later today. There is anyway a layer needed that handles the raw touch data and synchronizes rotation of display and touch, and this code an include an optional function to take care of eventual differences. I also noticed differences in the GAMSET / PGAMCTRL / NGAMCTRL that are gmma / color corrections, not impacting general functionality, but calibration of color, color tones... which for the newer of my LCDs are so much more blue-ish (it is of course also a different phone / camera with which I took the pics then and now). Posted at 2025-01-29 by @gfwilliams
It should provide an Posted at 2025-01-29 by @allObjects Yes, it does deliver nicely the touch (and untouch events) with x and y in both touch and untouch event. - The XPT2046 standalone module delivered only x and y with defined values for a touch and x and y with undefined values for an untouch (and no boolean/0|1 for touch/untouch status. Touch status has to be derived from value presence of x and/or y.) Since all is integrated, it is pretty fast and the event rate is pretty high on touch, even with no movement: the jitter by +-1...few pixels has to be filtered out / tamed, so that events with relevant moves show thru (its a bit more elaborate than just looking for a move of a number of pixel). I have built something and will show in a bit. This piece of code can become an umbrella module for both display and touch screen to provide rotational synchronization and touch calibration. Rotation calls would go thru that module to the Graphics object as well as to an (included) wrapper for the touch event. The wrapper takes takes care of touch coordinates for rotated displays an delivers the proper x and y with a tamed rate without loosing precision (small or slow movement / drag). |
Beta Was this translation helpful? Give feedback.
-
Posted at 2025-01-26 by @allObjects
Trying to update the https://espruino.com/ui, I noticed this integrated device - no wiring needed on my part - and was also told that there is an Espruino build out there that could work... sorts of, for me...
Flashing did go well, but on restart, the display initialization is either missing or off... and so are the colors
g.setColor(r,g,b)
. Touch though -built-in too - works perfect (E.on("touch",(t)=>console.log(t.x, t.y, (t.b) ? "touched" : "untouched"));
).Right after flashing and reset by esptool.py without power cycle, the Espruino uninitialized area shows content from before, horizontally mirrored - see attached shot showing Shop, FPS - frames/s - and CPU % horizontally mirrored. After power cycle, same display initialization and random noise in at the uninitialized area. Playing around with
.setRotation(...)
- and drawing a filled rectangle for visualization - did not yield results - see 2nd attachment. Originally loaded demo is landscape.Since this is the first time venturing into ESP32 and more so an integrated one, I need some shoehorning about pins, SPIs - to do a setup and initialized ILI9341 correctly. The device seems to be a newer version, because it has next to micro USB also a USB-C.
Since touch is integrated it delivers a lot of events, and because even staying at a point with the pen, a constant barrage goes on and is detrimental to the use w/ javascript. So I came up with a touch tamer - like a tiller tamer in sailing - about which I will have another conversation.
Attachments:
Beta Was this translation helpful? Give feedback.
All reactions