GSL1680 touch screen problems

Status
Not open for further replies.

grease_lighting

Well-known member
I recently purchased a TFTM050A2 display form Buydisplay.com and am having problems getting the touch screen working. Just to be clear though the display part is functioning thanks to the examples in the IDE. I added the I2C scan bus example to my code and it finds the touch controller just fine. Since the touch screen example was not working, I turned on the debug bits in the touch chip initialization. My I2C is pulled up to 3.3v from the Teensy 3.5 via 4.7K-ohm resistors.

Code:
GSL1680: Start boot up sequence
Toggle Wake
Clear reg
i2c write error: 3 0
Reset chip
i2c write error: 3 0
i2c write error: 2 BC
GSL1680: Load FW
Reset chip 2
i2c write error: 3 0
i2c write error: 2 BC
Startup Chip
GSL1680: Boot up complete

I do notice I'm getting some I2C errors and have tried this code at various I2C bus speed settings and Teensy CPU speed settings with no joy, usually the same errors shown above.

I poked around and found that error codes decode into
0: success
1: data too long to fit in transmit buffer
2: received NACK on transmit of address
3: received NACK on transmit of data
4: other error

but I really don't know what causes them. The display is the only device on the I2C bus. Am I seeing these errors and wrongly assuming they are cause for alarm? Anyway the touch screen does not seem to be responding. I have seen this thread here https://forum.pjrc.com/threads/26256-Has-anyone-tried-running-the-GSL16880-capacitive-touchscreen-controller-with-Teensy3 .

This is my code
Code:
  //
  //  An example of the internal support for the capacitive touch screen
  //  that use FT5206.
  //  Using FT5206 instead resistive RA8875 one give more precision, don't need any calibration
  //  and you have max 5 concurrent touches plus gesture and more...
  //
  //
  //--------------------------------------------------------------------------------------------
  //                                    HISTORY
  //--------------------------------------------------------------------------------------------
  //  1   April   2020    Start with RA8875 -- FT5206 touch screen driver.
  //                      Discover touch screen is GSL1680F.
  //                      Add I2C scanner code from examples.
  //  2   April   2020    Change driver for display to GSL1680F
  //                      sileadinc.com is all chinese website.
  //                      https://linux-sunxi.org/GSL1680    has some info on this chip
  //                      I2C pulled to 3.3v via 4.7K resistors.
  //    https://forum.pjrc.com/threads/26256-Has-anyone-tried-running-the-GSL16880-capacitive-touchscreen-controller-with-Teensy3/page4
  //                      The default value for Wire.endTransmission() is TRUE (bus gets released) 
  //                        FALSE sends a restart message.
  //                      A status byte is returned:
  //                      0:success
  //                      1:data too long to fit in transmit buffer
  //                      2:received NACK on transmit of address
  //                      3:received NACK on transmit of data
  //                      4:other error 
  //  9   April   2020    display is functioning properly.   Cap touch is not.
  //
  //
  //
  //
  //
  //

#include <SPI.h>
#include <RA8875.h>
#include <Wire.h>
#include "GSL1680.h"
#include "gslX680firmware.h"


  #define RA8875_CS         9     //  not connected
  #define RA8875_RESET      25                 
  #define RA8875_INT        12     //  not connected
  
  #define RA8875_MISO 8           //  miso on pin#8 (alt)
  #define RA8875_MOSI 11          //  mosi on pin#11
  #define RA8875_SCLK 14           //  sclk on pin #14 (alt)
  #define RA8875_WAIT 24
  #define RA8875_BL_PWM 29
  #define RA8875_CTP_INT 30
  #define RA8875_CTP_SDA 34
  #define RA8875_CTP_SCL 33
  #define RA8875_CTP_RST 31

  #define MAXTOUCHLIMIT     5//1...5

  //  ------------  I2C scanner variables
  byte I2Cerror, address;
  int nDevices;
  //  ------------
  int x=0;
  int y;
  //  ------------

  //  RA8875 tft = RA8875(RA8875_CS, RA8875_RESET);
  //or
  //  RA8875 tft = RA8875(RA8875_CS);//Teensy (not using rst pin)
  //or (for audio board)
  //  RA8875 tft = RA8875(RA8875_CS,RA8875_RESET,RA8875_MOSI,RA8875_SCLK);//Teensy using alternative SPI pin
  //or
    RA8875 tft = RA8875(RA8875_CS,RA8875_RESET,RA8875_MOSI,RA8875_SCLK,RA8875_MISO);//Teensy using alternative SPI pin + alt miso

  //  ------------

  #define error 1
  #define info 1
  #define WAKE 4              //  teensy wake pin     DON'T UNDERSTAND USE OF THESE PINS
  #define INTRPT 30           //  teensy interrupt pin
  //  GSL1680 TS = GSL1680();
    GSL1680 TS = GSL1680(error, info);      // An other constructor is available to enable some debug on serial

//  --------------------------------------  SETUP
void setup(){
  
  Serial.begin(9600);
  long unsigned debug_start = millis ();
  while (!Serial && ((millis () - debug_start) <= 5000)) ;

  pinMode(13, OUTPUT);

  pinMode(RA8875_RESET, OUTPUT);
  digitalWrite(RA8875_RESET, HIGH);
  pinMode(RA8875_CS, OUTPUT);
  digitalWrite(RA8875_CS, HIGH);
  pinMode(RA8875_WAIT, INPUT);
  pinMode(RA8875_INT, INPUT);
  pinMode(RA8875_CTP_RST, OUTPUT);
  digitalWrite(RA8875_CTP_RST, HIGH);     //  these pins may also be defined in the driver file
  pinMode(RA8875_CTP_INT, INPUT);         //  
  
  Wire.setSDA(RA8875_CTP_SDA);    //  use alternate I2c for touch screen
  Wire.setSCL(RA8875_CTP_SCL);

  SPI.setSCK(RA8875_SCLK);     //  use alternate SPI pins
  SPI.setMISO(RA8875_MISO);
  SPI.setMOSI(RA8875_MOSI);

  analogWrite(RA8875_BL_PWM,200);     //  0 is dark  256 is bright
  delay(100);
  
  //  begin display: Choose from: RA8875_480x272, RA8875_800x480, RA8875_800x480ALT, Adafruit_480x272, Adafruit_800x480
  tft.begin(RA8875_800x480);
  Serial.print("TFT: ");Serial.println(x);
  tft.fillWindow(RA8875_BLACK);
  tft.setTextColor(RA8875_WHITE,RA8875_BLACK);
  tft.setFontScale(1);      //font x1
  tft.setCursor(0, 0);
  tft.print("Hello World!0");
 

  Wire.setClock(100000);    //  100khz bus speed
  scanBus();                //  must scanbus BEFORE touch screen initialization

  TS.begin(RA8875_CTP_RST, RA8875_CTP_INT);
  


}
//  --------------------------------------  LOOP
void loop(){

  delay(500);
  digitalWrite(13,!(digitalRead(13)));    //  blink LED
  
  readTS();
  
}       //  end loop
//  --------------------------------------  I2C scanner
void scanBus() {

  Serial.println(F("Scanning..."));

  nDevices = 0;
  for (address = 1; address < 127; address++) {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    I2Cerror = Wire.endTransmission();

    if (I2Cerror == 0) {
      Serial.print(F("Device found at address 0x"));
      if (address < 16) {
        Serial.print("0");
      }
      Serial.print(address,HEX);
      Serial.print("  (");
      printKnownChips(address);
      Serial.println(")");

      nDevices++;
    } else if (I2Cerror==4) {
      Serial.print(F("Unknown error at address 0x"));
      if (address < 16) {
        Serial.print("0");
      }
      Serial.println(address,HEX);
    }
  }
  if (nDevices == 0) {
    Serial.println(F("No I2C devices found\n"));
  } else {
    Serial.println(F("done\n"));
  }
  delay(5000);           // wait 5 seconds for next scan
}       //  end scanner

//  --------------------------------------  I2C Chip Decoder
void printKnownChips(byte address)
{
  // Is this list missing part numbers for chips you use?
  // Please suggest additions here:
  // https://github.com/PaulStoffregen/Wire/issues/new
  switch (address) {
    case 0x00: Serial.print(F("AS3935")); break;
    case 0x01: Serial.print(F("AS3935")); break;
    case 0x02: Serial.print(F("AS3935")); break;
    case 0x03: Serial.print(F("AS3935")); break;
    case 0x0A: Serial.print(F("SGTL5000")); break; // MCLK required
    case 0x0B: Serial.print(F("SMBusBattery?")); break;
    case 0x0C: Serial.print(F("AK8963")); break;
    case 0x10: Serial.print(F("CS4272")); break;
    case 0x11: Serial.print(F("Si4713")); break;
    case 0x13: Serial.print(F("VCNL4000,AK4558")); break;
    case 0x18: Serial.print(F("LIS331DLH")); break;
    case 0x19: Serial.print(F("LSM303,LIS331DLH")); break;
    case 0x1A: Serial.print(F("WM8731")); break;
    case 0x1C: Serial.print(F("LIS3MDL")); break;
    case 0x1D: Serial.print(F("LSM303D,LSM9DS0,ADXL345,MMA7455L,LSM9DS1,LIS3DSH")); break;
    case 0x1E: Serial.print(F("LSM303D,HMC5883L,FXOS8700,LIS3DSH")); break;
    case 0x20: Serial.print(F("MCP23017,MCP23008,PCF8574,FXAS21002,SoilMoisture")); break;
    case 0x21: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x22: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x23: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x24: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x25: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x26: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x27: Serial.print(F("MCP23017,MCP23008,PCF8574,LCD16x2,DigoleDisplay")); break;
    case 0x28: Serial.print(F("BNO055,EM7180,CAP1188")); break;
    case 0x29: Serial.print(F("TSL2561,VL6180,TSL2561,TSL2591,BNO055,CAP1188")); break;
    case 0x2A: Serial.print(F("SGTL5000,CAP1188")); break;
    case 0x2B: Serial.print(F("CAP1188")); break;
    case 0x2C: Serial.print(F("MCP44XX ePot")); break;
    case 0x2D: Serial.print(F("MCP44XX ePot")); break;
    case 0x2E: Serial.print(F("MCP44XX ePot")); break;
    case 0x2F: Serial.print(F("MCP44XX ePot")); break;
    case 0x33: Serial.print(F("MAX11614,MAX11615")); break;
    case 0x34: Serial.print(F("MAX11612,MAX11613")); break;
    case 0x35: Serial.print(F("MAX11616,MAX11617")); break;
    case 0x38: Serial.print(F("RA8875,FT6206,MAX98390")); break;
    case 0x39: Serial.print(F("TSL2561, APDS9960")); break;
    case 0x3C: Serial.print(F("SSD1306,DigisparkOLED")); break;
    case 0x3D: Serial.print(F("SSD1306")); break;
    case 0x40: Serial.print(F("PCA9685,Si7021,MS8607, GSL1680F")); break;
    case 0x41: Serial.print(F("STMPE610,PCA9685")); break;
    case 0x42: Serial.print(F("PCA9685")); break;
    case 0x43: Serial.print(F("PCA9685")); break;
    case 0x44: Serial.print(F("PCA9685, SHT3X")); break;
    case 0x45: Serial.print(F("PCA9685, SHT3X")); break;
    case 0x46: Serial.print(F("PCA9685")); break;
    case 0x47: Serial.print(F("PCA9685")); break;
    case 0x48: Serial.print(F("ADS1115,PN532,TMP102,LM75,PCF8591")); break;
    case 0x49: Serial.print(F("ADS1115,TSL2561,PCF8591")); break;
    case 0x4A: Serial.print(F("ADS1115,Qwiic Keypad")); break;
    case 0x4B: Serial.print(F("ADS1115,TMP102,BNO080,Qwiic Keypad")); break;
    case 0x50: Serial.print(F("EEPROM,FRAM")); break;
    case 0x51: Serial.print(F("EEPROM")); break;
    case 0x52: Serial.print(F("Nunchuk,EEPROM")); break;
    case 0x53: Serial.print(F("ADXL345,EEPROM")); break;
    case 0x54: Serial.print(F("EEPROM")); break;
    case 0x55: Serial.print(F("EEPROM")); break;
    case 0x56: Serial.print(F("EEPROM")); break;
    case 0x57: Serial.print(F("EEPROM")); break;
    case 0x58: Serial.print(F("TPA2016,MAX21100")); break;
    case 0x5A: Serial.print(F("MPR121")); break;
    case 0x60: Serial.print(F("MPL3115,MCP4725,MCP4728,TEA5767,Si5351")); break;
    case 0x61: Serial.print(F("MCP4725,AtlasEzoDO")); break;
    case 0x62: Serial.print(F("LidarLite,MCP4725,AtlasEzoORP")); break;
    case 0x63: Serial.print(F("MCP4725,AtlasEzoPH")); break;
    case 0x64: Serial.print(F("AtlasEzoEC")); break;
    case 0x66: Serial.print(F("AtlasEzoRTD")); break;
    case 0x68: Serial.print(F("DS1307,DS3231,MPU6050,MPU9050,MPU9250,ITG3200,ITG3701,LSM9DS0,L3G4200D")); break;
    case 0x69: Serial.print(F("MPU6050,MPU9050,MPU9250,ITG3701,L3G4200D")); break;
    case 0x6A: Serial.print(F("LSM9DS1")); break;
    case 0x6B: Serial.print(F("LSM9DS0")); break;
    case 0x6F: Serial.print(F("Qwiic Button")); break;
    case 0x70: Serial.print(F("HT16K33")); break;
    case 0x71: Serial.print(F("SFE7SEG,HT16K33")); break;
    case 0x72: Serial.print(F("HT16K33")); break;
    case 0x73: Serial.print(F("HT16K33")); break;
    case 0x76: Serial.print(F("MS5607,MS5611,MS5637,BMP280")); break;
    case 0x77: Serial.print(F("BMP085,BMA180,BMP280,MS5611")); break;
    case 0x7C: Serial.print(F("FRAM_ID")); break;
    default: Serial.print(F("unknown chip"));
  }
}     //  end magic decoder ring


  //  --------------------------------------  
  void readTS() {
    if(digitalRead(INTRPT) == HIGH) {
      Serial.println("Touch");
      int NBFinger = TS.dataread();
      for(int i=0; i<NBFinger; i++){
        Serial.print(TS.readFingerID(i));
        Serial.print(" ");
        Serial.print(TS.readFingerX(i));
        Serial.print(" ");
        Serial.print(TS.readFingerY(i));
        Serial.println("");
      }
      Serial.println("---");
    }
  }         //  end readTS
  //  --------------------------------------  
  void basics() {
    if (digitalRead(RA8875_CTP_INT) == HIGH)  {Serial.println("Touched");}
    if (digitalRead(RA8875_CTP_RST) == LOW)  {Serial.println("reset");}
  }

//  --------------------------------------  


//  --------------------------------------  


//  --------------------------------------
 
Status
Not open for further replies.
Back
Top