[SOLVED] SPI Sharing ILI9341 and Touch XPT2046

Anything not related to STM32
Post Reply
hyperion
Posts: 9
Joined: Wed Nov 29, 2017 8:37 am

[SOLVED] SPI Sharing ILI9341 and Touch XPT2046

Post by hyperion » Thu Dec 21, 2017 4:22 am

Hi. Try share spi for touch and tft like this screen
Image
discribed here
http://nailbuster.com/?page_id=341
init string like this

Code: Select all

Adafruit_ILI9341_STM tft = Adafruit_ILI9341_STM(TFT_CS, TFT_DC);
XPT2046 touch(/*cs=*/ 4, /*irq=*/ 5);
result touch working, but screen not work.

there is some way to make it work touch and tft on same spi bus?

zmemw16
Posts: 1685
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: SPI Sharing ILI9341 and Touch XPT2046

Post by zmemw16 » Thu Dec 21, 2017 5:09 am

apart from mentioning those esp8266 things in an 'Arduino for STM32' forum; i'd duck if i were you :D

try reading this thread viewtopic.php?f=44&t=2026#p27136

stephen

stevestrong
Posts: 2070
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: SPI Sharing ILI9341 and Touch XPT2046

Post by stevestrong » Thu Dec 21, 2017 8:22 am

I am not quite sure, but it may be an issue with the CS remaining active after some of the TFT functions, which I have corrected in my repo: https://github.com/stevstrong/Arduino_S ... LI9341_STM
You could maybe give it a try.

And please always use PXY (e.g. PA3) notation to reference GPIO pins, not just raw numbers (deprecated ex: 3, 5...).

User avatar
RogerClark
Posts: 7693
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: SPI Sharing ILI9341 and Touch XPT2046

Post by RogerClark » Thu Dec 21, 2017 10:34 am

Steve

They don't seem to be using a STM32

If it is just a ESP8266, I'm think this thread should be closed (and probably deleted), as there are plenty of other forums dedicated to ES8266 and its just going to confuse matters discussing issues on on STM32 hardware libraries etc

stevestrong
Posts: 2070
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: SPI Sharing ILI9341 and Touch XPT2046

Post by stevestrong » Thu Dec 21, 2017 12:14 pm

Well, @hyperion mentioned to use Adafruit_ILI9341_STM lib, so I though it is STM32 related, the picture is just to say that his setup is "like this".

hyperion
Posts: 9
Joined: Wed Nov 29, 2017 8:37 am

Re: SPI Sharing ILI9341 and Touch XPT2046

Post by hyperion » Thu Dec 21, 2017 2:45 pm

yes, i found this wiring and want know, can i use 2 devices on same SPI bus? :)
Photo esp8266 only for reference. I use maple mini clone.
@stevestrong, thanks, i try this repo.

victor_pv
Posts: 1871
Joined: Mon Apr 27, 2015 12:12 pm

Re: SPI Sharing ILI9341 and Touch XPT2046

Post by victor_pv » Thu Dec 21, 2017 5:32 pm

Hyperion it you stil have problems after trying Steve's library, add more information to your post indicating with pins you are using for each line.
You don't need to draw a diagram, but just something like this:
LCD_CS - Pin 1
LCD_Reset - pin 2
Touch_CS - Pin 3
...

User avatar
RogerClark
Posts: 7693
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: SPI Sharing ILI9341 and Touch XPT2046

Post by RogerClark » Thu Dec 21, 2017 7:56 pm

Doesnt the Pig-O-Scope use the display and the touch screen

why not use that wiring and test with that software first

hyperion
Posts: 9
Joined: Wed Nov 29, 2017 8:37 am

Re: SPI Sharing ILI9341 and Touch XPT2046

Post by hyperion » Sat Dec 23, 2017 8:23 pm

ohh. I can not get my touch to work properly
wiring

Code: Select all

ILI9341 on SPI1 
#define TFT_CS         PA4
#define TFT_DC         PC15
Adafruit_ILI9341_STM tft = Adafruit_ILI9341_STM(TFT_CS, TFT_DC); // Use hardware SPI
TFT work fine.

Touch connected to SPI2
all wiring are correct. triple check.

try URTouch
URTouch Touch( PB13, PB3, PB15, PB14, PA8);

It work, i finished calibration, but result - large offsets and X axis is inverted.

try XPT2046_touch.h

Code: Select all

#define CS_PIN PB3 // Chip Select pin
SPIClass mySPI(2); //Create an SPI instance on SPI 2 port.
XPT2046_touch ts(CS_PIN, mySPI); // Chip Select pin, SPI port
demo sketch not work :(



hooooray!

problem was in this piece of code. Now work correct. I am happy :)

Code: Select all

if (Touch.dataAvailable())
  {
    Touch.read();
    // Note: This is corrected to account for different orientation of screen origin (x=0,y=0) in Adafruit lib from UTouch lib
    uint32_t touchY = myHeight -  Touch.getX();
    uint32_t touchX = myWidth - Touch.getY();
    //

Post Reply