I purchased a ESP32-2432S028R which has an ESP32-wroom_32, 2.8" display with ILI9341 driver, resistive touch screen with xpt2046 driver and a sdcard slot. Sounds perfect right. They all use separate mosi, miso and clk pins. I am using it on https://github.com/mstrens/grbl_controller_esp32 which uses TFT_eSPI and I cannot get the touch to work (tft and sd are working). I think this is due to the 3 separate pins and the sd is messing up the touch. I am using both VSPI and HSPI. Is there a way to get all three devices working in their current config or I am going to have to cut traces and rewire the MOSI,MISO and clk on the sdcard to the touch pins and use the CS to to id them? The unit comes with multiple example files but I cannot get any of them running that require touch even with their supplied user_set.h. The only thing I can get working is their demo file that is a bin so I cannot see how they did it.
here are the pins #define ILI9341_2_DRIVER // Alternative ILI9341 driver, see Bodmer/TFT_eSPI#1172 #define TFT_WIDTH 240 #define TFT_HEIGHT 320 #define TFT_BL 21 // LED back-light control pin #define TFT_BACKLIGHT_ON HIGH // Level to turn ON back-light (HIGH or LOW) #define TFT_MOSI 13 // In some display driver board, it might be written as "SDA" and so on. #define TFT_SCLK 14 #define TFT_CS 15 // Chip select control pin #define TFT_DC 2 // Data Command control pin #define TFT_RST 12 // Reset pin (could connect to Arduino RESET pin) #define TFT_BL 21 // LED back-light #define SPI_FREQUENCY 55000000 // STM32 SPI1 only (SPI2 maximum is 27MHz)
// Optional reduced SPI frequency for reading TFT #define SPI_READ_FREQUENCY 20000000
Touch Screen: #define XPT2046_IRQ 36 #define XPT2046_MOSI 32 #define XPT2046_MISO 39 #define XPT2046_CLK 25 #define XPT2046_CS 33
// The XPT2046 requires a lower SPI clock rate of 2.5MHz so we define that here: #define SPI_TOUCH_FREQUENCY 2500000
Why can't you put the SPI devices onto 1 SPI bus?
Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination
Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination
You do know that using portB for I/O will cause issue? PortB is optimized for A:D and is INPUT only pins.
Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination
What issue are you having that you can't you post your code in code tags?
Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination
Why are you trying to define 3 SPI ports? The ESP32 only has 2 SPI hardware ports. Each SPI hardware port on the ESP32 can drive 3 SPI devices each.
Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination
I understand that there are only the 2 useable spi ports. The wiring is from the factory and cannot be changed on this unit. I am new at programming but I have been learning what I can. What I have seen is that it would be best to have either all three devices share the miso, misi, and sclk pins and use each devise CS pin or or have the TFT on HSPI and the Touch and sdcard on VSPI but in either case would require cutting traces and use jumper wires or using an external SDcard board wired to share the touch . I don't know why the manufacturer designed it this way. I am just seeing if there is a software solution for a hardware issue.
Ok, I hardwired the mosi, miso and clk from the touch chip to the mosi, mosi and clk pins on the sdard and was able to get tft, touch and sdcard working. I lifted the pins on the xpt2046 and soldered wires from them to the pins on the sdcard. I then edited the user_setup.h in the TFT_eSPI to use Hspi. The tft uses the hspi and the touch and sd use the vspi. Crude but it got the job done.
I had the same problem so, instead of lifting the XPT2046 pins and loosing compatibility with the existing code for this board, I simply soldered 1K resistors to the IO39 (TP_DO), IO32 (TP_DI) and IO25 (TP_CLK) pins and connected them to the corresponding TFT pins (respectively IO12, IO13 and IO14) with enameled wire.
I had the same problem of you, same board and unable to run prg example with touch funtions.
the only example that works apart from the one that is initially integrated into the esp32 is this one:
2.8inch_ESP32\1-Demo\Demo_Arduino\7_1_Touch_button_ILI9341_LovyanGFX\Touch_button_ILI9341_LovyanGFX
but you must first replace your User_setup.h by the one present in:
2.8inch_ESP32\1-Demo\Demo_Arduino\7_1_Touch_button_ILI9341_LovyanGFX\TFT_eSPI bottom layer replacement file.
form my it works but, but not yet analysed
I gave up on this screen after spending way too much time on it. I ended up just getting a 3.2" tft touch screen and using a esp32 dev board to get the project going. I had things working to a point that the calibration for the touch and sd access working but once that was done, the screen would just go blank and I think it was a problem with the reset pin assignment but again, no easy fix on this board.
After playing with both TFT_eSPI and lovyanGFX libraries on this board, I changed the 3 x 1K Ohms resistors I previously added for 2K2 Ohms ones.
I'm currently working on a Web Radio based on: Web Radio ESP32-2432S028-I2S | macsbug
Like dudley1001, I have spent way too much time trying to get the touch to work. I suspect the easiest way would be to add a software interface as the pins to the 2046 are not connected to either SPI bus.
Cutting tracks and re-wiring is not an elegant solution.
Anyone got any suggestions?
Perhaps a sketch using a software I/F to the TP.
Just follow the instructions inside the .ino file, the most critical aspect was the lv_conf.h that needed a change on the tick per seconds. The included version has those changes made.
WOW first posting on the forum posting a link to a solution of a problem that requires a lot of knowledge and deep analysis to solve.
This example-code demonstrates the touch-function.
If I understood right there is a problem with how the SPI-busses are wired on the PCB.
This wiring seems to give trouble to use the touch-function and SD-Card at the same time.
Did you do a test if your code is able to use the SD-cards at the same time with the touch-functionality?
Have not yet been able to test SD, it was failing to compile in Arduino because of multiple libraries conflicting. Arduino IDE is good for its simplicity but then complicated for me to understand why those strange things happen.
I have got this resolved.
The fundemental problem is that the TFT and touch busses are on different pins. Cutting tracks is a bit desperate, a software solution to live with the existing hardware is better.
I thought about trying to open up seperate instances of the library but given 'C' of any flavour is not my bag, that didn't last long.
In the end, I have tweaked Bodmers library - specifically Touch.cpp and setup.h - to include banging the touch screen lines in software.
I'm sure you 'C' gurus will find it quite horrible but it works.
If someone can give me a cretins guide as to how to post the resulting files on here I'll do just that.
Typically you'd put the text here under the tag in this example Use code tags to format code for the forum
The simplest way is to create an account on github and upload your code over there. If you are not familiar with git, then try using their desktop tool: https://desktop.github.com/ that should be straightforward. I'd be interested to look into your solution, I'm still running in circles myself trying to solve that issue.
Here's the mmodified part of Touch.cpp and setup.h. Don't forget you'll need to set up the IO pins.
This is my new Touch.cpp from the first line although only from Sspixfer has changed
There's a section for User_setup.h at the end
// The following touch screen support code by maxpautsch was merged 1/10/17
// https://github.com/maxpautsch
// Define TOUCH_CS is the user setup file to enable this code
// A demo is provided in examples Generic folder
// Additions by Bodmer to double sample, use Z value to improve detection reliability
// and to correct rotation handling
// See license in root directory.
/***************************************************************************************
** Function name: begin_touch_read_write - was spi_begin_touch
** Description: Start transaction and select touch controller
***************************************************************************************/
// The touch controller has a low SPI clock rate
inline void TFT_eSPI::begin_touch_read_write(void){
DMA_BUSY_CHECK;
CS_H; // Just in case it has been left low
#if defined (SPI_HAS_TRANSACTION) && defined (SUPPORT_TRANSACTIONS)
if (locked) {locked = false; spi.beginTransaction(SPISettings(SPI_TOUCH_FREQUENCY, MSBFIRST, SPI_MODE0));}
#else
spi.setFrequency(SPI_TOUCH_FREQUENCY);
#endif
SET_BUS_READ_MODE;
T_CS_L;
}
/***************************************************************************************
** Function name: end_touch_read_write - was spi_end_touch
** Description: End transaction and deselect touch controller
***************************************************************************************/
inline void TFT_eSPI::end_touch_read_write(void){
T_CS_H;
#if defined (SPI_HAS_TRANSACTION) && defined (SUPPORT_TRANSACTIONS)
if(!inTransaction) {if (!locked) {locked = true; spi.endTransaction();}}
#else
spi.setFrequency(SPI_FREQUENCY);
#endif
//SET_BUS_WRITE_MODE;
}
uint16_t SPIdout;
uint16_t SPIdin;
//uint16_t dout;
/**************************************************************************************
** Function name: Legacy - deprecated
** Description: Start/end transaction
***************************************************************************************/
void TFT_eSPI::spi_begin_touch() {begin_touch_read_write();}
void TFT_eSPI::spi_end_touch() { end_touch_read_write();}
/***************************************************************************************
** Function name: Sspixfer
** Description: software SPI transfer.
***************************************************************************************/
void Sspixfer (uint16_t dout) // Exchange 8 bits of data over SPI
{
// uint16_t tmp; // Data in
uint16_t SPImask = 0x80; // Set bit mask
SPIdout = dout; // Set data to go
for (uint8_t lpcnt = 0; lpcnt < 8; lpcnt ++) // Do 8 bits
{
digitalWrite (TOUCH_MOSI, ((SPIdout & SPImask) ? HIGH:LOW)); // Set up data out
SPImask = (SPImask >> 1); // Mask for next bit
digitalWrite(TOUCH_CLK,1); // CLK = 1
//tmp = (tmp << 1); // Shift existing data along
SPIdin = (SPIdin << 1); // Shift existing data along
digitalWrite(TOUCH_CLK,0); // CLK = 0
ets_delay_us(1); // Delay
// tmp |= digitalRead(TOUCH_MISO); // Shift data in
SPIdin |= digitalRead(TOUCH_MISO); // Shift data in
} // Go round again
} // All done
/***************************************************************************************
** Function name: getTouchRaw
** Description: read raw touch position. Always returns true.
***************************************************************************************/
uint8_t TFT_eSPI::getTouchRaw(uint16_t *x, uint16_t *y){
uint16_t tmp;
#ifdef SOFTSPI
digitalWrite(TOUCH_CS,0);
Sspixfer(0xD0); // Start new YP conversion
Sspixfer(0); // Read first 8 bits
Sspixfer(0xD0); // Read last 8 bits and start new YP conversion
Sspixfer(0); // Read first 8 bits
Sspixfer(0xD0); // Read last 8 bits and start new YP conversion
Sspixfer(0); // Read first 8 bits
Sspixfer(0xD0); // Read last 8 bits and start new YP conversion
Sspixfer(0); // Read first 8 bits
Sspixfer(0x90); // Read last 8 bits and start new XP conversion
*x = SPIdin >>4; // Transfer and re-align data
Sspixfer(0); // Read first 8 bits
Sspixfer(0x90); // Read last 8 bits and start new XP conversion
Sspixfer(0); // Read first 8 bits
Sspixfer(0x90); // Read last 8 bits and start new XP conversion
Sspixfer(0); // Read first 8 bits
Sspixfer(0x90); // Read last 8 bits and start new XP conversion
Sspixfer(0); // Read first 8 bits
Sspixfer(0); // Read last 8 bits
*y = SPIdin >>4; // Transfer and re-align data
digitalWrite(TOUCH_CS,1);
#else
begin_touch_read_write();
// Start YP sample request for x position, read 4 times and keep last sample
spi.transfer(0xd0); // Start new YP conversion
spi.transfer(0); // Read first 8 bits
spi.transfer(0xd0); // Read last 8 bits and start new YP conversion
spi.transfer(0); // Read first 8 bits
spi.transfer(0xd0); // Read last 8 bits and start new YP conversion
spi.transfer(0); // Read first 8 bits
spi.transfer(0xd0); // Read last 8 bits and start new YP conversion
tmp = spi.transfer(0); // Read first 8 bits
tmp = tmp <<5;
tmp |= 0x1f & (spi.transfer(0x90)>>3); // Read last 8 bits and start new XP conversion
*x = tmp;
// Start XP sample request for y position, read 4 times and keep last sample
spi.transfer(0); // Read first 8 bits
spi.transfer(0x90); // Read last 8 bits and start new XP conversion
spi.transfer(0); // Read first 8 bits
spi.transfer(0x90); // Read last 8 bits and start new XP conversion
spi.transfer(0); // Read first 8 bits
spi.transfer(0x90); // Read last 8 bits and start new XP conversion
tmp = spi.transfer(0); // Read first 8 bits
tmp = tmp <<5;
tmp |= 0x1f & (spi.transfer(0)>>3); // Read last 8 bits
*y = tmp;
end_touch_read_write();
#endif
return true;
}
/***************************************************************************************
** Function name: getTouchRawZ
** Description: read raw pressure on touchpad and return Z value.
***************************************************************************************/
uint16_t TFT_eSPI::getTouchRawZ(void){
#if defined SOFTSPI
int16_t tz = 0xFFF;
digitalWrite(TOUCH_CS,0);
Sspixfer(0xb0); // Start new Z1 conversion
Sspixfer(0); // Read first 8 bits
Sspixfer(0xc0); // Read last 8 bits and start Z2 conversion
tz += (SPIdin >>4);
Sspixfer(0); // Read first 8 bits
Sspixfer(0); // Read last 8 bits
tz -= (SPIdin >>4);
digitalWrite(TOUCH_CS,1);
// tz += Sspixfer16(0xc0) >> 3; // Read Z1 and start Z2 conversion
// tz -= Sspixfer16(0x00) >> 3; // Read Z2
#else
begin_touch_read_write();
// Z sample request
int16_t tz = 0xFFF;
spi.transfer(0xb0); // Start new Z1 conversion
tz += spi.transfer16(0xc0) >> 3; // Read Z1 and start Z2 conversion
tz -= spi.transfer16(0x00) >> 3; // Read Z2
#endif
end_touch_read_write();
if (tz == 4095) tz = 0;
return (uint16_t)tz;
}
/***************************************************************************************
** Function name: validTouch
This part into User_setup.h
// For ESP32 Dev board (only tested with ILI9341 display)
// The hardware SPI can be mapped to any pins
// #define TFT_MISO -1
// #define TFT_MOSI 14
// #define TFT_SCLK 33
// #define TFT_CS -1 // Chip select control pin
// #define TFT_DC 13 // Data Command control pin
// #define TFT_RST 12 // Reset pin (could connect to RST pin)
//#define TFT_RST -1 // Set TFT_RST to -1 if display RESET is connected to ESP32 board RST
// For ESP32 Dev board (only tested with GC9A01 display)
// The hardware SPI can be mapped to any pins
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Working display pins
#define TFT_MOSI 13 // Might be written as "SDA" and so on.
#define TFT_MISO 12
#define TFT_SCLK 14
#define TFT_CS 15 // Chip select control pin
#define TFT_DC 2 // Data Command control pin
#define TFT_RST -1 // 12 Reset pin (could connect to Arduino RESET pin)
#define TFT_BL 21 // LED back-light
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//#define TFT_MOSI 32
//#define TFT_SCLK 25
//#define TFT_CS 33
//#define TFT_DC 2
//#define TFT_RST 39
//#define TFT_BL 21
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#define TOUCH_CS 33 // Chip select pin (T_CS) of touch screen
#define SOFTSPI // Uncomment for software SPI
#define TOUCH_MOSI 32
#define TOUCH_MISO 39
#define TOUCH_CLK 25
//#define TFT_WR 22 // Write strobe for modified Raspberry Pi TFT only