Help Getting X and Y coordinates from Touch Sensor GT9271

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).

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.

#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
Screenshot 2024-03-24 155902

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

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

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

Thank you, I have updated the code back to:

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

Your I2C bus scanner shows 0x5D

Sorry I fixed my previous comment.

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...

1 Like

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 :+1:

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

1 Like

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