Go Down

Topic: Graphics library for NodeMCU (ESP8266), ESP32 and serial+parallel TFT displays (Read 47108 times) previous topic - next topic

Stan_S

Try the attached version. It is not perfect (some text position issues) but it should work OK. It is for a 480x320 screen.

Hi Bodmer,
It works great! Your the best!

Thanks,
Stan

Mac_che

After figuring out the wiring (Thanx) and using your planespotter repo (and did the same modifications actually) to make it work with your graphics repo driver the display works.

Then I found out that Daniel silently updated his Planespotter repo and added touch.
Tested it, no modifications, works and ofcourse no screen but that wasn't important for testing
So I did some modifications to the Graphics library (Added some missing functions Planespotter uses like getTextBounds and a few others, lazy copied from Adafruit ) modified the sketch to make use of the Graphics library, changed some code like getWidth > widt and getHeight > height and compiled.
It compiles but when started it reboots due to some stack error.

So I took Bodmer repo, hacked in the touch part from Daniel,
That works but when touched it restarts. (TP_CS on D2 and without T_IRQ connected)
So, wired T_IRQ to D4 but didn't made any difference.


I think it's related to the touch screen since testing with only touch examples fails.
(XPT2046 touch screen according to the PCB)

To be continued

bodmer

I think it's related to the touch screen since testing with only touch examples fails.
(XPT2046 touch screen according to the PCB)

I had not noticed Daniel's update to use the touch screen, so that is interesting.

I have a screen with a XPT2046 connected so I tried Paul's library here. The example worked fine on an ESP8266 (NodeMCU) without problems when the pins are setup. Here is the sketch I used:

Code: [Select]

#include <XPT2046_Touchscreen.h>
#include <SPI.h>

// These are the pins for all ESP8266 boards
#define PIN_D0 16
#define PIN_D1  5
#define PIN_D2  4
#define PIN_D3  0
#define PIN_D4  2
#define PIN_D5 14 // SCLK
#define PIN_D6 12 // MISO
#define PIN_D7 13 // MOSI
#define PIN_D8 15
#define PIN_D9  3
#define PIN_D10 1

#define CS_PIN  PIN_D1 // XPT2046 chip select
#define TFT_CS  PIN_D8 // TFT chip select

XPT2046_Touchscreen ts(CS_PIN);

void setup() {
  Serial.begin(38400);
  digitalWrite(TFT_CS, 1); // Disable TFT for test only
  ts.begin();
  while (!Serial && (millis() <= 1000));
}

void loopB() {
  TS_Point p = ts.getPoint();
  Serial.print("Pressure = ");
  Serial.print(p.z);
  if (ts.touched()) {
    Serial.print(", x = ");
    Serial.print(p.x);
    Serial.print(", y = ");
    Serial.print(p.y);
  }
  Serial.println();
  //  delay(100);
  delay(30);
}

void loop() {
  if (ts.touched()) {
    TS_Point p = ts.getPoint();
    Serial.print("Pressure = ");
    Serial.print(p.z);
    Serial.print(", x = ");
    Serial.print(p.x);
    Serial.print(", y = ");
    Serial.print(p.y);
    delay(30);
    Serial.println();
  }
}



Note that MISO needs to be connected up as well as MOSI.  To play safe for the test I have made sure the TFT cannot respond and upset the MISO data by setting TFT chip select high in setup. Don't try amd use the touch IRQ line as that will not work with an ESP8266.
Formerly Rowboteer (now a broken user profile!)

Mac_che

Yes! Touch is working!

Now, with your Planespotter when pressed, I see a menu and it's no longer crashing.
And now it also know more about coding Arduino sketches so it wasn't a waste of time
It seems no commands are defined so I going to dive into the world of buttons and touch and commands.
Let's see if I can merge PS and WS together.

 



bodmer

Yes! Touch is working!

Now, with your Planespotter when pressed, I see a menu and it's no longer crashing.
And now it also know more about coding Arduino sketches so it wasn't a waste of time
It seems no commands are defined so I going to dive into the world of buttons and touch and commands.
Let's see if I can merge PS and WS together.

OK, good to hear it is working.  I had a look a Daniel's code and it is a "work in progress" as there the touch response code is incomplete and commented out.

The WS code uses a lot of SPIFFS memory (more than 1 Mbyte) so allocate 3 MBytes.

The output of the touch library could be calibrated and scaled into pixel units, that would help identify different screen areas.
Formerly Rowboteer (now a broken user profile!)

Mac_che

Does that mean that we cannot use something like this or wouldn't that only be inaccurate?

Code: [Select]

if ((pt.x>=420) && (pt.x<=480) && (pt.y>=0) && (pt.y<=40)) {


I already created a menu with up down, left right and zoom + - on the right upper side.
The part works, short press brings that menu up, longer press brings up MainMenu.


The commands for Zoom in and zoom out are quite easy to create I think. It requires to grab the currentzoomlevel and do a i++ or i--  for every touch, download that map and display that map.


I was thinking of something like this:
Code: [Select]

if ((pt.x>=420) && (pt.x<=480) && (pt.y>=0) && (pt.y<=40)) {
if (currentPage == '0'){
// Page 0 PanAndZoom, page 1 MainMenu, Page 2  manual update, based on presstime
         tft.fillScreen(TFT_BLACK);
Serial.println("Zoom IN pressed") ;
currentZoomlevel =  geoMap.getCurrentZoomlevel(); //added in geomap.h
 for (int i =  currentZoomlevel; i++;){
    delay(500);
  geoMap.downloadMap(mapCenter, i, _downloadCallback);
  geoMap.convertToCoordinates({0,0});
  geoMap.convertToCoordinates({MAP_WIDTH, MAP_HEIGHT});
  tft.fillRect(0, geoMap.getMapHeight(), tft.width(), tft.height() - geoMap.getMapHeight(), TFT_BLACK);


You can find the (probably not compiling version due to missing brackets to close the loop) code here
https://github.com/Ierlandfan/esp8266-plane-spotter-color

bodmer

Does that mean that we cannot use something like this or wouldn't that only be inaccurate?
If you run the code in post #122 you will see in the Serial Monitor window that the coordinates are in raw ADC values. These could be used but are likely to be in the range 0 - 4095. Also the coordinate origin of the touch screen may not be in the same place as the origin of the screen.
Formerly Rowboteer (now a broken user profile!)

Mac_che

How hard would it be to write (just for debug purposes) an Adafruit compatible driver using ILI9431 as a template. Tried myself but cannot get the init to work (Used your init and notro's init, screen stays white)
Any idea's?



Nevermind, it wasn't that :o.  After setting a few print statements I saw that it crashed on setFreeFont
Setting it to setTextFont(2); worked.

Have to change a few settings to make it fit the 480*320. It even works on 160MHZ.


I had to use the JPEGDecoder version from FredericPlante. Yours gave me everything but no Google Maps background.  

Stan_S

Mac_Che were you able to get the latest plane spotter working? if so what did you do?

Mac_che

Hi Stan, yes I am.

it takes a few changes. (I'll save you the trouble, i'll upload a working sketch) I made a few changes to a few libraries so it's easier to upload it and attach it here since Github is kinda new. (TODO, upload to Github)
I changed a lot to make it fit my screen (320*240) and my wishes. Still working on the touch,  I am close.
It sometimes reset and lines (heading) aren't drawn, which it dit initially, have to look in to that.
I want bigger font and more space between the text but hey, I came this far :-)

I took me a while to figure it all out but I managed. Experience in c++ or Arduino code is still below any average. It took a steap learning curve and mostly some time,coffee & perseverance
As always, it wasn't that hard if you know what you're doing (I have some clues what I am doing) but I liked the leaning course. I tried to make as much comments as possible while changing things.

I also included the library's I modified (TFT_eSPi)  in the next post (Due to upload size). Read the original readme by Daniel for the others)
fredericplante's Jpegdecoder changed names due to recovery and is now called JPEG_CODEC, old one will work also.
You can find it here
Huge thanx to Bodmer for the liTFT brary and the responses!

By the way, you need this for touch: XPT2046_Touchscreen PaulStoffregen
And ofcourse credits to Daniel Eichhorn who made the whole Planespotter sketch in the first place.
See blog
His Github for Planespotter: esp8266-plane-spotter-color

The sketch is as is, I did not gave myself credits in this one. Free to use.
If you cannot open the zip, it's actually a renamed rar file  (due to forum limitations)

Mac_che

Modified TFT_eSPI (Added some functions)
Only cpp and .h are modified, Download Bodmer original library here and copy them over.
(Forum limitations and things like that)

Mac_che

Nailed the code for touch and Zoom (working), now need to calibrate the screen because touch seems reversed

afox

sorrry I am new to this....I am using a st7735 display and a nodemcu esp32

I modified the User_Setup.h file and uncommented the following lines:

#define ST7735_DRIVER
#define TFT_WIDTH 128
#define TFT_HEIGHT 160
#define ST7735_INITB
#define TFT_CS PIN_D5 // Chip select control pin
#define TFT_DC PIN_D2 // Data Command control pin
#define TFT_RST PIN_D4 // Reset pin (could connect to RST pin)
#define SPI_FREQUENCY 27000000

and connected:
CS pin on the st7735 to NODEMCU pin D5
DC on the st7735 to NODEMCU pin D2
RST on the st7735 to NODEMCU pin D4

and ran one of the examples but the display is blank !

what am I doing wrong ?



bodmer

sorrry I am new to this....I am using a st7735 display and a nodemcu esp32

You need to use numeric numbers for the I/O pins with an ESP32, for example use:

#define TFT_MISO 19
#define TFT_MOSI 23
#define TFT_SCLK 18
#define TFT_CS    15  // Chip select control pin
#define TFT_DC    2  // Data Command control pin
#define TFT_RST   4  // Reset pin (could connect to RST pin)

On an ESP32 the hardware SPI port can be mapped to almost any pin, but those are the ones I use and work fine.

Formerly Rowboteer (now a broken user profile!)

afox

thanks so much it finally worked !!!

I used the following pins:

#define TFT_MISO 19
#define TFT_MOSI 23
#define TFT_SCLK 18
#define TFT_CS    5
#define TFT_DC    2
#define TFT_RST   4

even if MISO to pin 19 is not connected !



Go Up