2 Mega 2560 R3 + 2 2.8" TFT breakouts

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
UMEnterprise
 
Posts: 4
Joined: Thu Sep 13, 2018 8:43 pm

2 Mega 2560 R3 + 2 2.8" TFT breakouts

Post by UMEnterprise »

I am working on a project using multiple micro controllers that receive I2C signals from one Arduino Uno R3 that reads sensor status (motion sensor, tilt sensor, & switch). That Uno then sends a simple interger to the 6 other controllers to indicate state of those sensors. Everything works fine with each controller using Wire and individual I2C IDs. My problem stems from the two Megas with the 2.8" TFT attached. The FT6x06 Capacitive Touch Screens are set to use ID 38 for the I2C communication. With two of them connected to the system when one is touched the other also reacts if the coordinates touched on the one are in the same area as a button on the other. Is there a way to change one of the FT6X06 IDs? Tried going into the Adafruit_FT6206.h and changing the address there to 39 and saving it as Adafruit_FT6206_alt.h and putting that into the program that is being uploaded to one of the Megas attached to the touchscreen. But no luck when a I2C scan was run on master I2C arduino uno still only showed ID 38 and no ID 39. Any help would be greatly appreciated.

User avatar
Franklin97355
 
Posts: 23903
Joined: Mon Apr 21, 2008 2:33 pm

Re: 2 Mega 2560 R3 + 2 2.8" TFT breakouts

Post by Franklin97355 »

Did you change the name of the #define?

Code: Select all

#define FT62XX_ADDR           0x38
If you include both .h files they will be confused when they have the same name for different values.

UMEnterprise
 
Posts: 4
Joined: Thu Sep 13, 2018 8:43 pm

Re: 2 Mega 2560 R3 + 2 2.8" TFT breakouts

Post by UMEnterprise »

I created an alternate .h file with the new I2C ID 39 and changed the name of the #include to that alternate .h file in the Adafruit_FT6206.cpp. Which was duplicated first and original saved outside the arduino/library/ folder so the original would not be used.

Thank you

UMEnterprise
 
Posts: 4
Joined: Thu Sep 13, 2018 8:43 pm

Re: 2 Mega 2560 R3 + 2 2.8" TFT breakouts

Post by UMEnterprise »

Here is altered .cpp file

Code: Select all

/*************************************************** 
  This is a library for the Adafruit Capacitive Touch Screens

  ----> http://www.adafruit.com/products/1947
 
  Check out the links above for our tutorials and wiring diagrams
  This chipset uses I2C to communicate

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
 ****************************************************/


#include "Arduino.h"
#include <Wire.h>
#include <alt_FT6206.h>

#if defined(__SAM3X8E__)
    #define Wire Wire1
#endif

//#define FT6206_DEBUG
//#define I2C_DEBUG


/**************************************************************************/
/*! 
    @brief  Instantiates a new FT6206 class
*/
/**************************************************************************/
// I2C, no address adjustments or pins
Adafruit_FT6206::Adafruit_FT6206() {
  touches = 0;
}


/**************************************************************************/
/*! 
    @brief  Setups the I2C interface and hardware, identifies if chip is found
    @param  thresh Optional threshhold-for-touch value, default is FT6206_DEFAULT_THRESSHOLD but you can try changing it if your screen is too/not sensitive.
    @returns True if an FT6206 is found, false on any failure
*/
/**************************************************************************/
boolean Adafruit_FT6206::begin(uint8_t thresh) {
  Wire.begin();

#ifdef FT6206_DEBUG
  Serial.print("Vend ID: 0x"); 
  Serial.println(readRegister8(FT62XX_REG_VENDID), HEX);
  Serial.print("Chip ID: 0x"); 
  Serial.println(readRegister8(FT62XX_REG_CHIPID), HEX);
  Serial.print("Firm V: "); Serial.println(readRegister8(FT62XX_REG_FIRMVERS));
  Serial.print("Point Rate Hz: "); 
  Serial.println(readRegister8(FT62XX_REG_POINTRATE));
  Serial.print("Thresh: "); 
  Serial.println(readRegister8(FT62XX_REG_THRESHHOLD));

  // dump all registers
  for (int16_t i=0; i<0x10; i++) {
    Serial.print("I2C $"); Serial.print(i, HEX);
    Serial.print(" = 0x"); Serial.println(readRegister8(i), HEX);
  }
#endif

  // change threshhold to be higher/lower
  writeRegister8(FT62XX_REG_THRESHHOLD, thresh);
  
  if (readRegister8(FT62XX_REG_VENDID) != FT62XX_VENDID) {
    return false;
  }
  uint8_t id = readRegister8(FT62XX_REG_CHIPID);
  if ((id != FT6206_CHIPID) && (id != FT6236_CHIPID) && (id != FT6236U_CHIPID)) {
    return false;
  }

  return true;
}

/**************************************************************************/
/*! 
    @brief  Determines if there are any touches detected
    @returns Number of touches detected, can be 0, 1 or 2
*/
/**************************************************************************/
uint8_t Adafruit_FT6206::touched(void) {
  uint8_t n = readRegister8(FT62XX_REG_NUMTOUCHES);
  if (n > 2) {
    n = 0;
  }
  return n;
}

/**************************************************************************/
/*! 
    @brief  Queries the chip and retrieves a point data
    @param  n The # index (0 or 1) to the points we can detect. In theory we can detect 2 points but we've found that you should only use this for single-touch since the two points cant share the same half of the screen.
    @returns {@link TS_Point} object that has the x and y coordinets set. If the z coordinate is 0 it means the point is not touched. If z is 1, it is currently touched.
*/
/**************************************************************************/
TS_Point Adafruit_FT6206::getPoint(uint8_t n) {
  readData();
  if ((touches == 0) || (n > 1)) {
    return TS_Point(0, 0, 0);
  } else {
    return TS_Point(touchX[n], touchY[n], 1);
  }
}

/************ lower level i/o **************/

/**************************************************************************/
/*! 
    @brief  Reads the bulk of data from captouch chip. Fill in {@link touches}, {@link touchX}, {@link touchY} and {@link touchID} with results
*/
/**************************************************************************/
void Adafruit_FT6206::readData(void) {

  uint8_t i2cdat[16];
  Wire.beginTransmission(FT62BB_ADDR);
  Wire.write((byte)0);  
  Wire.endTransmission();

  Wire.requestFrom((byte)FT62BB_ADDR, (byte)16);
  for (uint8_t i=0; i<16; i++)
    i2cdat[i] = Wire.read();

#ifdef FT6206_DEBUG
  for (int16_t i=0; i<16; i++) {
    Serial.print("I2C $"); Serial.print(i, HEX); 
    Serial.print(" = 0x"); Serial.println(i2cdat[i], HEX);
  }
#endif

  touches = i2cdat[0x02];
  if ((touches > 2) || (touches == 0)) {
    touches = 0;
  }

#ifdef FT6206_DEBUG
  Serial.print("# Touches: "); Serial.println(touches);

  for (uint8_t i=0; i<16; i++) {
    Serial.print("0x"); Serial.print(i2cdat[i], HEX); Serial.print(" ");
  }
  Serial.println();
  if (i2cdat[0x01] != 0x00) {
    Serial.print("Gesture #"); 
    Serial.println(i2cdat[0x01]);
  }
#endif

  for (uint8_t i=0; i<2; i++) {
    touchX[i] = i2cdat[0x03 + i*6] & 0x0F;
    touchX[i] <<= 8;
    touchX[i] |= i2cdat[0x04 + i*6]; 
    touchY[i] = i2cdat[0x05 + i*6] & 0x0F;
    touchY[i] <<= 8;
    touchY[i] |= i2cdat[0x06 + i*6];
    touchID[i] = i2cdat[0x05 + i*6] >> 4;
  }

#ifdef FT6206_DEBUG
  Serial.println();
  for (uint8_t i=0; i<touches; i++) {
    Serial.print("ID #"); Serial.print(touchID[i]); 
    Serial.print("\t("); Serial.print(touchX[i]);
    Serial.print(", "); Serial.print(touchY[i]);
    Serial.print (") ");
  }
  Serial.println();
#endif
}

uint8_t Adafruit_FT6206::readRegister8(uint8_t reg) {
  uint8_t x ;
  // use i2c
  Wire.beginTransmission(FT62BB_ADDR);
  Wire.write((byte)reg);
  Wire.endTransmission();
  
  Wire.requestFrom((byte)FT62BB_ADDR, (byte)1);
  x = Wire.read();

#ifdef I2C_DEBUG
  Serial.print("$"); Serial.print(reg, HEX); 
  Serial.print(": 0x"); Serial.println(x, HEX);
#endif

  return x;
}

void Adafruit_FT6206::writeRegister8(uint8_t reg, uint8_t val) {
  // use i2c
  Wire.beginTransmission(FT62BB_ADDR);
  Wire.write((byte)reg);
  Wire.write((byte)val);
  Wire.endTransmission();
}

/*

// DONT DO THIS - REALLY - IT DOESNT WORK
void Adafruit_FT6206::autoCalibrate(void) {
 writeRegister8(FT06_REG_MODE, FT6206_REG_FACTORYMODE);
 delay(100);
 //Serial.println("Calibrating...");
 writeRegister8(FT6206_REG_CALIBRATE, 4);
 delay(300);
 for (uint8_t i = 0; i < 100; i++) {
   uint8_t temp;
   temp = readRegister8(FT6206_REG_MODE);
   Serial.println(temp, HEX);
   //return to normal mode, calibration finish 
   if (0x0 == ((temp & 0x70) >> 4))
     break;
 }
 delay(200);
 //Serial.println("Calibrated");
 delay(300);
 writeRegister8(FT6206_REG_MODE, FT6206_REG_FACTORYMODE);
 delay(100);
 writeRegister8(FT6206_REG_CALIBRATE, 5);
 delay(300);
 writeRegister8(FT6206_REG_MODE, FT6206_REG_WORKMODE);
 delay(300);
}
*/

/****************/

TS_Point::TS_Point(void) {
  x = y = 0;
}

TS_Point::TS_Point(int16_t x0, int16_t y0, int16_t z0) {
  x = x0;
  y = y0;
  z = z0;
}

bool TS_Point::operator==(TS_Point p1) {
  return  ((p1.x == x) && (p1.y == y) && (p1.z == z));
}

bool TS_Point::operator!=(TS_Point p1) {
  return  ((p1.x != x) || (p1.y != y) || (p1.z != z));
}



and here is altered .h

Code: Select all

/*************************************************** 
  This is a library for the Adafruit Capacitive Touch Screens

  ----> http://www.adafruit.com/products/1947
 
  Check out the links above for our tutorials and wiring diagrams
  This chipset uses I2C to communicate

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
 ****************************************************/

#ifndef ADAFRUIT_FT6206_LIBRARY
#define ADAFRUIT_FT6206_LIBRARY

#include "Arduino.h"
#include <Wire.h>

#define FT62BB_ADDR           0x42
#define FT62XX_G_FT5201ID     0xA8
#define FT62XX_REG_NUMTOUCHES 0x02

#define FT62XX_NUM_X             0x33
#define FT62XX_NUM_Y             0x34

#define FT62XX_REG_MODE 0x00
#define FT62XX_REG_CALIBRATE 0x02
#define FT62XX_REG_WORKMODE 0x00
#define FT62XX_REG_FACTORYMODE 0x40
#define FT62XX_REG_THRESHHOLD 0x80
#define FT62XX_REG_POINTRATE 0x88
#define FT62XX_REG_FIRMVERS 0xA6
#define FT62XX_REG_CHIPID 0xA3
#define FT62XX_REG_VENDID 0xA8

#define FT62XX_VENDID 0x11
#define FT6206_CHIPID 0x06
#define FT6236_CHIPID 0x36
#define FT6236U_CHIPID 0x64 // mystery!

// calibrated for Adafruit 2.8" ctp screen
#define FT62XX_DEFAULT_THRESHOLD 128

class TS_Point {
 public:
  TS_Point(void);
  TS_Point(int16_t x, int16_t y, int16_t z);
  
  bool operator==(TS_Point);
  bool operator!=(TS_Point);

  int16_t x, y, z;
};

class Adafruit_FT6206 {
 public:

  Adafruit_FT6206(void);
  boolean begin(uint8_t thresh = FT62XX_DEFAULT_THRESHOLD);  
  uint8_t touched(void);
  TS_Point getPoint(uint8_t n = 0);

  //void autoCalibrate(void); 

 private:
  void writeRegister8(uint8_t reg, uint8_t val);
  uint8_t readRegister8(uint8_t reg);

  void readData(void);
  uint8_t touches;
  uint16_t touchX[2], touchY[2], touchID[2];

};

#endif //ADAFRUIT_FT6206_LIBRARY

UMEnterprise
 
Posts: 4
Joined: Thu Sep 13, 2018 8:43 pm

Re: 2 Mega 2560 R3 + 2 2.8" TFT breakouts

Post by UMEnterprise »

It seems that any ID other than 38 does not allow the Cap Touch to start. Tried putting back ID 38 on the new header and .ccp files and it worked fine again. Try changing only the ID to 39 and stops working again. I am stumped.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”