# Help Getting X and Y coordinates from Touch Sensor GT9271

**URL:** <https://forum.arduino.cc/t/help-getting-x-and-y-coordinates-from-touch-sensor-gt9271/1239467>\
**Category:** General Guidance\
**Created:** [March 24, 2024, 10:59pm UTC](https://forum.arduino.cc/t/help-getting-x-and-y-coordinates-from-touch-sensor-gt9271/1239467 "2024-03-24T22:59:55Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![jee\_n](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@jee\_n](https://forum.arduino.cc/u/jee_n)\
**Post date:** [March 24, 2024, 10:59pm UTC](https://forum.arduino.cc/t/help-getting-x-and-y-coordinates-from-touch-sensor-gt9271/1239467/1 "2024-03-24T22:59:55Z")

</div>

Hello,

I'd like to preface that this is one of my first projects using i2c and may not understand it fully yet.

I recently got a touch panel with the chip GT9271 from an old device ([Datasheet](https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.buydisplay.com%2Fdownload%2Fic%2FGT9271.pdf&psig=AOvVaw3khuXCagZuRznmgaUsORNh&ust=1711405310210000&source=images&cd=vfe&opi=89978449&ved=0CBUQ3YkBahcKEwioyvrd942FAxUAAAAAHQAAAAAQCQ)).

So far I have been able to connect the device via I2C, scan the address (0x5D), and even been able to change the address to 0x14.

My ultimate goal is to detect a ball on the surface of the screen, I've used codes from online tutorials as a template to write mine (attached) to access the coordinates but every time I get (x = 0, y = 0).

I am not quite sure what I am doing wrong and any help would be greatly appreciated.

```arduino
#include <Wire.h>

int GT9271Address = 0x14; // Device address in which is also included the 8th bit for selecting the mode, read in this case.

#define X_Axis_L_Register 0x8048
#define X_Axis_H_Register 0x8049
#define Y_Axis_L_Register 0x804A
#define Y_Axis_H_Register 0x804B

//#define X_Axis_Register 0x8057
//#define Y_Axis_Register 0x8058

// Command Register 0: Read coordinates status; 1: Read diff data or raw data; 2: Read diff data or raw data;
#define Command 0x8040

int X, Y;
byte error;

void setup() {
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  digitalWrite(3, LOW);
  digitalWrite(2, LOW);
  delayMicroseconds(100);
  digitalWrite(2, HIGH);
  delayMicroseconds(101);
  digitalWrite(3, HIGH);
  delay(6);
  digitalWrite(2, LOW);
  delay(55);
  pinMode(2, INPUT);
  Wire.begin(); // Initiate the Wire library
  Serial.begin(9600);
  // pinMode(2, OUTPUT);
  // pinMode(3, OUTPUT);
  // digitalWrite(2, LOW);
  // digitalWrite(3, HIGH);

  // Enable measurement
  Wire.beginTransmission(GT9271Address);
  //Wire.write(Command);
  Wire.write(0x00);
  error = Wire.endTransmission();
  Serial.println(error);
  delay(500);
}

void loop() {
  Wire.beginTransmission(GT9271Address); // Begin transmission to the Sensor
  //Ask the particular registers for data
    Wire.write(X_Axis_L_Register);
    Wire.write(X_Axis_H_Register);
    Wire.write(Y_Axis_L_Register);
    Wire.write(Y_Axis_H_Register);
// Wire.write(X_Axis_Register);
// Wire.write(Y_Axis_Register);
    Wire.requestFrom(GT9271Address, 4, true); // Request the transmitted two bytes from 4 registers

  if (Wire.available() <= 4) { //
        X = Wire.read() << 8 | Wire.read(); // Reads the data from the register
        Y = Wire.read() << 8 | Wire.read();
// X = Wire.read(); // Reads the data from the register
// Y = Wire.read();
    Serial.print("X= ");
    Serial.print(X);
    Serial.print(" Y= ");
    Serial.println(Y);
  }
  error = Wire.endTransmission();
  Serial.println(error);
}

```

![Screenshot 2024-03-24 155837](https://europe1.discourse-cdn.com/arduino/original/4X/7/e/0/7e0c992fcbe9bdad1b63283a4580c49e039dac02.png)  
 ![Screenshot 2024-03-24 155902](https://europe1.discourse-cdn.com/arduino/original/4X/e/d/6/ed6c8c33e32bb48e72a6eedace356be39b448684.png)

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [March 25, 2024, 2:53am UTC](https://forum.arduino.cc/t/help-getting-x-and-y-coordinates-from-touch-sensor-gt9271/1239467/2 "2024-03-25T02:53:12Z")

</div>

> [@jee\_n](#):
>
> change the address to 0x14.

If the IIC scanner sees 0x5D, why did you change the sketch to 0x14?

---

<div class="post-metadata">

**Author:** ![jee\_n](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@jee\_n](https://forum.arduino.cc/u/jee_n)\
**Post date:** [March 25, 2024, 5:53am UTC](https://forum.arduino.cc/t/help-getting-x-and-y-coordinates-from-touch-sensor-gt9271/1239467/3 "2024-03-25T05:53:22Z")

</div>

I was playing around with the code, to make sure I was connected to the device and could interact with it.

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [March 25, 2024, 2:18pm UTC](https://forum.arduino.cc/t/help-getting-x-and-y-coordinates-from-touch-sensor-gt9271/1239467/4 "2024-03-25T14:18:13Z")

</div>

Verify your wiring is correct and post a wiring diagram. You should correct your sketch to reflect the correct I2C device address.

---

<div class="post-metadata">

**Author:** ![jee\_n](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@jee\_n](https://forum.arduino.cc/u/jee_n)\
**Post date:** [March 26, 2024, 12:46am UTC](https://forum.arduino.cc/t/help-getting-x-and-y-coordinates-from-touch-sensor-gt9271/1239467/5 "2024-03-26T00:46:32Z")

</div>

Thank you, I have updated the code back to:

```arduino
int GT9271Address = 0x5D;

```

And removed the lines changing the address.

The circuit is fairly simple the ribbon cable from the chip goes into a 10 PIN Board connected to the arduino like so:

| Arduino | Chip |
| --- | --- |
| SDA | SDA (2k Resistor) |
| SCL | SCL (2k Resistor) |
| 3.3v | VDD |
| GND | GND |
| Pin2 | INT |
| Pin3 | RST |

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [March 26, 2024, 1:14am UTC](https://forum.arduino.cc/t/help-getting-x-and-y-coordinates-from-touch-sensor-gt9271/1239467/6 "2024-03-26T01:14:01Z")

</div>

Your I2C bus scanner shows 0x5D

---

<div class="post-metadata">

**Author:** ![jee\_n](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@jee\_n](https://forum.arduino.cc/u/jee_n)\
**Post date:** [March 26, 2024, 1:27am UTC](https://forum.arduino.cc/t/help-getting-x-and-y-coordinates-from-touch-sensor-gt9271/1239467/7 "2024-03-26T01:27:08Z")

</div>

Sorry I fixed my previous comment.

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [March 26, 2024, 2:42am UTC](https://forum.arduino.cc/t/help-getting-x-and-y-coordinates-from-touch-sensor-gt9271/1239467/8 "2024-03-26T02:42:26Z")

</div>

That should confuse readers...

The screens are either resistive or capacitive, and need a path to ground. This example and the accompanying video might help you with your project...

> **[Touchscreen Display with Arduino | DroneBot Workshop](https://dronebotworkshop.com/touchscreen-arduino/)**
>
> Let’s start using touchscreens with an Arduino! Learn the differences between resistive and capacitive screens, and how to use a common touchscreen shield.

---

<div class="post-metadata">

**Author:** ![jee\_n](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@jee\_n](https://forum.arduino.cc/u/jee_n)\
**Post date:** [March 26, 2024, 3:57am UTC](https://forum.arduino.cc/t/help-getting-x-and-y-coordinates-from-touch-sensor-gt9271/1239467/9 "2024-03-26T03:57:17Z")

</div>

Thank you I believe my issue is more likely related to the initialization/setup. Considering another sensor, the pad I have is capacitive and won't recognize a ball I think. Got it from an old/unused display and thought it could be repurposed for a cool project, not a huge loss 👍

---

<div class="post-metadata">

**Author:** ![ianvand](https://avatars.discourse-cdn.com/v4/letter/i/51bf81/32.png) [@ianvand](https://forum.arduino.cc/u/ianvand)\
**Post date:** [September 21, 2024, 1:22pm UTC](https://forum.arduino.cc/t/help-getting-x-and-y-coordinates-from-touch-sensor-gt9271/1239467/10 "2024-09-21T13:22:53Z")

</div>

I think It would be a better Idea to use a pressure sensor matrix for this problem.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 20, 2025, 1:22pm UTC](https://forum.arduino.cc/t/help-getting-x-and-y-coordinates-from-touch-sensor-gt9271/1239467/11 "2025-03-20T13:22:54Z")

</div>

Closed on March 20, 2025, 1:22pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
