From 83ecdbda7d5cf04c0cec919eddd3afb103acb0a4 Mon Sep 17 00:00:00 2001 From: John La Rooy Date: Tue, 11 Jul 2023 16:38:54 +1000 Subject: [PATCH 1/2] Correct the alignment of the data in the rx_buf The first bit of the result bytes is not used. So, for a 12 bit result, the high 7 bits come from rx_buf[1] and 5 low bits come from rx_buf[0]. --- xpt2046.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xpt2046.py b/xpt2046.py index b1e8751..9fe28be 100644 --- a/xpt2046.py +++ b/xpt2046.py @@ -132,4 +132,4 @@ def send_command(self, command): self.spi.write_readinto(self.tx_buf, self.rx_buf) self.cs(1) - return (self.rx_buf[1] << 4) | (self.rx_buf[2] >> 4) + return (self.rx_buf[1] << 5) | (self.rx_buf[2] >> 3) From a2d0fa5def7abdb75dd0b9cf817a8a6b44df66d6 Mon Sep 17 00:00:00 2001 From: John La Rooy Date: Mon, 3 Aug 2026 11:02:43 +1000 Subject: [PATCH 2/2] Update xpt2046.py The fixed bitshift means we should double the defaults for x_max and x_min --- xpt2046.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xpt2046.py b/xpt2046.py index 9fe28be..7f8c0bc 100644 --- a/xpt2046.py +++ b/xpt2046.py @@ -17,7 +17,7 @@ class Touch(object): def __init__(self, spi, cs, int_pin=None, int_handler=None, width=240, height=320, - x_min=100, x_max=1962, y_min=100, y_max=1900): + x_min=100, x_max=3924, y_min=100, y_max=3800): """Initialize touch screen controller. Args: