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);
}

