Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Cross
#44823 Based on Paul's repo (https://github.com/PaulStoffregen/XPT2046_Touchscreen) I have tried to get the XPT2046 to work with an ESP8266 chipset. It looks like the data is there- but not arriving in the order I would expect. I understand that SPI reads are delayed and arrive with the next read but that does not match the results below.

My code to get x/y/z values is below
Code: Select all#define SPI_SETTING     SPISettings(2000000, MSBFIRST, SPI_MODE0)
void XPT2046_Touchscreen::update()
{
    SPI.beginTransaction(SPI_SETTING);
    digitalWrite(csPin, LOW);
    SPI.transfer(               0b10110001); //z1
    int16_t z1 = SPI.transfer16(0b11000001) >> 3; //z2
    int16_t z2 = SPI.transfer16(0b11010001) >> 3; //x
    int16_t  x = SPI.transfer16(0b11010001) >> 3; //x
    int16_t  x2= SPI.transfer16(0b10010001) >> 3; //y
    int16_t  y = SPI.transfer16(0b10010001) >> 3; //y
    int16_t  y2= SPI.transfer16(0) >> 3;
    digitalWrite(csPin, HIGH);
    SPI.endTransaction();

    Serial.printf("z1,z2, x,x, y,y = %d,%d,  %d,%d, %d,%d", z1, z2, x, x2, y, y2);
}


Typical output looks like this:
z1,z2, x,x, y,y = 2579,2342, 2431,1559, 1512,16

The z2 and x1 values are always close to each other, as are x2 and y1. The y2 value remains orders of magnitudes off.

Any ideas what's going wrong?
User avatar
By Cross
#44840 For reference, this is what the SPI capture looks like:
spi.png
You do not have the required permissions to view the files attached to this post.
User avatar
By schufti
#44852 did you try this XPT2046 library?
since it is based on the same spi lib and gives (most of the time*) plausible results, it would be worth a look.
* when the stylus is moved to fast, "ghost" points appear in tpdraw