Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Touch not working #2

Closed
videobuff opened this issue Jan 30, 2022 · 20 comments
Closed

Touch not working #2

videobuff opened this issue Jan 30, 2022 · 20 comments

Comments

@videobuff
Copy link

Really happy to find your repo, but i still can't make it work.

This is what i did
First removed original Adafruit_FT6206.h library and installed the one you pointed out.
When first compiled, I got an error that TFT_BL was not defined.

No wonder since the serial port showed the following output:

09:56:56.804 -> Couldn't start touchscreen controller

This comes from this subroutine:

if (!ts.begin(18, 19, 40)) {
Serial.println("Couldn't start touchscreen controller");
while (true);
}

What is the TFT_BL pin you defined ?

Many thanks

Erik

@elgerg
Copy link

elgerg commented Jan 30, 2022

Hi Erik,

Did you use the user setup? The TFT_BL is here:

#define TFT_BL 23

Regards

@videobuff
Copy link
Author

videobuff commented Jan 30, 2022

Sorry to stay on, on the Bodmer repo.
Yes I have used everything as described in the repo you advised from Sowbug. Added the specific user_select file, installed the forked Adafruit library for the touchscreen. Got even rid of al the the notices about redefining TFT_WIDTH & HEIGHT.

My question: The touchscreen is supposed to work with I2C as the Pins SDA & SCL are defined. However, if i run an Arduino i2c discovery script, it tells me no i2c device detected. Whereas it does detect my temp sensor and compass if i connect them.
So i am still at loss.

@videobuff videobuff changed the title TFT_BL not defined Touch not working Jan 30, 2022
@elgerg
Copy link

elgerg commented Jan 30, 2022

Looks and sounds like a faulty screen..

Can you post the link to the device you bought?

Also, remember that the i2c pins might be different from the adafruit scanner... IE 18 & 19

ie try:

#include "Wire.h"

void setup() {
  Serial.begin(115200);
  Wire.begin(18, 19);
}

void loop() {
  byte error, address;
  int nDevices = 0;

  delay(5000);

  Serial.println("Scanning for I2C devices ...");
  for(address = 0x01; address < 0x7f; address++){
    Wire.beginTransmission(address);
    error = Wire.endTransmission();
    if (error == 0){
      Serial.printf("I2C device found at address 0x%02X\n", address);
      nDevices++;
    } else if(error != 2){
      Serial.printf("Error %d at address 0x%02X\n", error, address);
    }
  }
  if (nDevices == 0){
    Serial.println("No I2C devices found");
  }
}

Or so...

@Fischkopppp
Copy link

Fischkopppp commented Jan 31, 2022

Hi elgerg, I have the same problem with my screen. I believe it is because the Adafruit library expects only one argument in:

if (!ts.begin(18, 19, 40))

so we have to adjust this?
boolean Adafruit_FT6206::begin(uint8_t thresh) { Wire.begin();

@Fischkopppp
Copy link

Fischkopppp commented Jan 31, 2022

I changed in the FT6206 library:

boolean Adafruit_FT6206::begin(uint8_t thresh) { 
   Wire.begin();

to:

boolean Adafruit_FT6206::begin(uint8_t thresh) {
  Wire.begin(18,19);

this worked for me.

@elgerg
Copy link

elgerg commented Jan 31, 2022

Hi elgerg, I have the same problem with my screen. I believe it is because the Adafruit library exprects only one argument in:

if (!ts.begin(18, 19, 40))

so we have to adjust this? boolean Adafruit_FT6206::begin(uint8_t thresh) { Wire.begin();

I would assume that you didnt install the forked library that supports pin override?

IE:

In your Arduino libraries directory, clone a fork of Adafruit_FT6206_Library that allows overriding the I2C GPIO pins in the Arduino Wire library.

From:
https://github.com/sowbug/Adafruit_FT6206_Library

Glad to hear you got it working though.

@elgerg
Copy link

elgerg commented Feb 1, 2022

My question: The touchscreen is supposed to work with I2C as the Pins SDA & SCL are defined. However, if i run an Arduino i2c discovery script, it tells me no i2c device detected. Whereas it does detect my temp sensor and compass if i connect them.
So i am still at loss.

Hi Erik,

What Wire test sketch did you try?

Can you post the sketch and link to the device you bought?

Thanks

@videobuff
Copy link
Author

Here is the sketch. I bought it from Aliexpress couple of months ago.
Note, i have tried it with the original library and the revised one by sowbug as mentioned above.
Your i2c test gives me this output with the following pins Wire.begin(18, 19);
Scanning for I2C devices ...
I2C device found at address 0x38
Which is very promising.

//  Source>>    https://how2electronics.com/measure-wind-speed-with-anemometer-on-esp32-tft-display/
#include "alert.h" // Out of range alert icon
#include <TFT_eSPI.h> // Hardware-specific library
#include <SPI.h>
#include <Adafruit_FT6206.h>
 
// Meter colour schemes
#define RED2RED 0
#define GREEN2GREEN 1
#define BLUE2BLUE 2
#define BLUE2RED 3
#define GREEN2RED 4
#define RED2GREEN 5
 
#define TFT_GREY 0x2104 // Dark grey 16 bit colour
 
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library with default width and height

Adafruit_FT6206 ts = Adafruit_FT6206();  // Touch screen definition
uint16_t fill_color = TFT_BLACK;

 
uint32_t runTime = -99999; // time for next update
int d = 0;       // Variable used for the sinewave test waveform
boolean range_error = 0;
 
 
void setup(void)
{
  Serial.begin(115200);


// Pins 18/19 are SDA/SCL for touch sensor on this device
  // 40 is a touch threshold
  if (!ts.begin(18, 19, 40)) {
    Serial.println("Couldn't start touchscreen controller");
    while (true);
  }




 
  tft.begin();

///  Modification for WT32-SC01 screen  ///////////////////////////////////////////////////
 // tft.init();
  // Thanks to https://github.com/seaniefs/WT32-SC01-Exp
  // for figuring this out
 // pinMode(TFT_BL, OUTPUT);
 // digitalWrite(TFT_BL, 128);
///////////////////////////////////////////////////////////////////////////////////////////
  
  tft.setRotation(1);
  tft.fillScreen(TFT_BLACK);
 
  tft.setTextColor(TFT_WHITE, TFT_BLACK);
  tft.drawString("Wind Speed", 10, 10, 4);
  tft.drawString("PE1-DYM", 10, 35, 4);
}

void loop()
{
    if (ts.touched()) {
    TS_Point p = ts.getPoint();
    Serial.printf("%d %d\n", p.x, p.y);
    tft.fillScreen(fill_color);
    if (fill_color == TFT_BLACK) {
      fill_color = TFT_BLUE;
    } else {
      fill_color = TFT_BLACK;      
    }
  }

  float sensorValue = analogRead(35);
  float voltage = (sensorValue / 4095) * 5;
  float wind_speed = mapfloat(voltage, 0.4, 2, 0, 32.4);
  float speed_mph = ((wind_speed * 3600) / 1609.344);
  //Serial.print(speed_mph);
  //Serial.println("km/h");
  
  // Test with a slowly changing value from a Sine function
  //d += 4; if (d >= 360) d = 0;
 
  // Set the the position, gap between meters, and inner radius of the meters
  int xpos = 0, ypos = 5, gap = 4, radius = 52;
 
  // Draw a large meter
  xpos = 480 / 2 - 160, ypos = 0, gap = 15, radius = 170;
  // Comment out above meters, then uncomment the next line to show large meter
  ringMeter(speed_mph, 0, 12, xpos, ypos, radius, "km/h", BLUE2RED); // Draw analogue meter
 
}
 
// #########################################################################
//  Draw the meter on the screen, returns x coord of righthand side
// #########################################################################
int ringMeter(int value, int vmin, int vmax, int x, int y, int r, const char *units, byte scheme)
{
  // Minimum value of r is about 52 before value text intrudes on ring
  // drawing the text first is an option
 
  x += r;
  y += r; // Calculate coords of centre of ring
 
  int w = r / 3; // Width of outer ring is 1/4 of radius
 
  int angle = 150; // Half the sweep angle of meter (300 degrees)
 
  int v = map(value, vmin, vmax, -angle, angle); // Map the value to an angle v
 
  byte seg = 3; // Segments are 3 degrees wide = 100 segments for 300 degrees
  byte inc = 6; // Draw segments every 3 degrees, increase to 6 for segmented ring
 
  // Variable to save "value" text colour from scheme and set default
  int colour = TFT_BLUE;
 
  // Draw colour blocks every inc degrees
  for (int i = -angle + inc / 2; i < angle - inc / 2; i += inc)
  {
    // Calculate pair of coordinates for segment start
    float sx = cos((i - 90) * 0.0174532925);
    float sy = sin((i - 90) * 0.0174532925);
    uint16_t x0 = sx * (r - w) + x;
    uint16_t y0 = sy * (r - w) + y;
    uint16_t x1 = sx * r + x;
    uint16_t y1 = sy * r + y;
 
    // Calculate pair of coordinates for segment end
    float sx2 = cos((i + seg - 90) * 0.0174532925);
    float sy2 = sin((i + seg - 90) * 0.0174532925);
    int x2 = sx2 * (r - w) + x;
    int y2 = sy2 * (r - w) + y;
    int x3 = sx2 * r + x;
    int y3 = sy2 * r + y;
 
    if (i < v)
    { // Fill in coloured segments with 2 triangles
      switch (scheme)
      {
        case 0:
          colour = TFT_RED;
          break; // Fixed colour
        case 1:
          colour = TFT_GREEN;
          break; // Fixed colour
        case 2:
          colour = TFT_BLUE;
          break; // Fixed colour
        case 3:
          colour = rainbow(map(i, -angle, angle, 0, 127));
          break; // Full spectrum blue to red
        case 4:
          colour = rainbow(map(i, -angle, angle, 70, 127));
          break; // Green to red (high temperature etc)
        case 5:
          colour = rainbow(map(i, -angle, angle, 127, 63));
          break; // Red to green (low battery etc)
        default:
          colour = TFT_BLUE;
          break; // Fixed colour
      }
      tft.fillTriangle(x0, y0, x1, y1, x2, y2, colour);
      tft.fillTriangle(x1, y1, x2, y2, x3, y3, colour);
      //text_colour = colour; // Save the last colour drawn
    }
    else // Fill in blank segments
    {
      tft.fillTriangle(x0, y0, x1, y1, x2, y2, TFT_GREY);
      tft.fillTriangle(x1, y1, x2, y2, x3, y3, TFT_GREY);
    }
  }
  // Convert value to a string
  char buf[10];
  byte len = 3;
  if (value > 999)
    len = 5;
  dtostrf(value, len, 0, buf);
  buf[len] = ' ';
  buf[len + 1] = 0; // Add blanking space and terminator, helps to centre text too!
  // Set the text colour to default
  tft.setTextSize(1);
 
  if (value < vmin || value > vmax)
  {
    drawAlert(x, y + 90, 50, 1);
  }
  else
  {
    drawAlert(x, y + 90, 50, 0);
  }
 
  tft.setTextColor(TFT_WHITE, TFT_BLACK);
  // Uncomment next line to set the text colour to the last segment value!
  tft.setTextColor(colour, TFT_BLACK);
  tft.setTextDatum(MC_DATUM);
  // Print value, if the meter is large then use big font 8, othewise use 4
  if (r > 84)
  {
    tft.setTextPadding(55 * 3);   // Allow for 3 digits each 55 pixels wide
    tft.drawString(buf, x, y, 8); // Value in middle
  }
  else
  {
    tft.setTextPadding(3 * 14);   // Allow for 3 digits each 14 pixels wide
    tft.drawString(buf, x, y, 4); // Value in middle
  }
  tft.setTextSize(1);
  tft.setTextPadding(0);
  // Print units, if the meter is large then use big font 4, othewise use 2
  tft.setTextColor(TFT_WHITE, TFT_BLACK);
  if (r > 84)
    tft.drawString(units, x, y + 60, 4); // Units display
  else
    tft.drawString(units, x, y + 15, 2); // Units display
 
  // Calculate and return right hand side x coordinate
  return x + r;
}
 
void drawAlert(int x, int y, int side, boolean draw)
{
  if (draw && !range_error)
  {
    drawIcon(alert, x - alertWidth / 2, y - alertHeight / 2, alertWidth, alertHeight);
    range_error = 1;
  }
  else if (!draw)
  {
    tft.fillRect(x - alertWidth / 2, y - alertHeight / 2, alertWidth, alertHeight, TFT_BLACK);
    range_error = 0;
  }
}
 
// #########################################################################
// Return a 16 bit rainbow colour
// #########################################################################
unsigned int rainbow(byte value)
{
  // Value is expected to be in range 0-127
  // The value is converted to a spectrum colour from 0 = blue through to 127 = red
 
  byte red = 0;   // Red is the top 5 bits of a 16 bit colour value
  byte green = 0; // Green is the middle 6 bits
  byte blue = 0;  // Blue is the bottom 5 bits
 
  byte quadrant = value / 32;
 
  if (quadrant == 0)
  {
    blue = 31;
    green = 2 * (value % 32);
    red = 0;
  }
  if (quadrant == 1)
  {
    blue = 31 - (value % 32);
    green = 63;
    red = 0;
  }
  if (quadrant == 2)
  {
    blue = 0;
    green = 63;
    red = value % 32;
  }
  if (quadrant == 3)
  {
    blue = 0;
    green = 63 - 2 * (value % 32);
    red = 31;
  }
  return (red << 11) + (green << 5) + blue;
}
 
// #########################################################################
// Return a value in range -1 to +1 for a given phase angle in degrees
// #########################################################################
float sineWave(int phase)
{
  return sin(phase * 0.0174532925);
}
 
//====================================================================================
// This is the function to draw the icon stored as an array in program memory (FLASH)
//====================================================================================
 
// To speed up rendering we use a 64 pixel buffer
#define BUFF_SIZE 64
 
// Draw array "icon" of defined width and height at coordinate x,y
// Maximum icon size is 255x255 pixels to avoid integer overflow
 
void drawIcon(const unsigned short *icon, int16_t x, int16_t y, int8_t width, int8_t height)
{
 
  uint16_t pix_buffer[BUFF_SIZE]; // Pixel buffer (16 bits per pixel)
 
  tft.startWrite();
 
  // Set up a window the right size to stream pixels into
  tft.setAddrWindow(x, y, width, height);
 
  // Work out the number whole buffers to send
  uint16_t nb = ((uint16_t)height * width) / BUFF_SIZE;
 
  // Fill and send "nb" buffers to TFT
  for (int i = 0; i < nb; i++)
  {
    for (int j = 0; j < BUFF_SIZE; j++)
    {
      pix_buffer[j] = pgm_read_word(&icon[i * BUFF_SIZE + j]);
    }
    tft.pushColors(pix_buffer, BUFF_SIZE);
  }
 
  // Work out number of pixels not yet sent
  uint16_t np = ((uint16_t)height * width) % BUFF_SIZE;
 
  // Send any partial buffer left over
  if (np)
  {
    for (int i = 0; i < np; i++)
      pix_buffer[i] = pgm_read_word(&icon[nb * BUFF_SIZE + i]);
    tft.pushColors(pix_buffer, np);
  }
 
  tft.endWrite();
}
 
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

Yesterday I got a replay from WT telling me to use TFT_eSPI for the display and the FT6336U for the touch. To be honest it worked one time when using one of their samples to test the touch, but i could not reproduce it. And I use the ESP32WROVER as device.
Here is the link to their advised touch library

https://github.com/aselectroworks/Arduino-FT6336U
Erik

@videobuff
Copy link
Author

With the FT6336U and the pins 18 and 19, there is live in their samples. (ScanMultiTouch)

FT6336U Firmware Version: 3
FT6336U Device Mode: 0
FT6336U Device Mode: 0
FT6336U Threshold: 0x16
FT6336U Filter Coefficient: 0xFA
FT6336U Control Mode: 0x1
FT6336U Time Period for enter to Monitor Mode: 0x1E
FT6336U Active Rate: 0xA
FT6336U Monitor Rate: 0x28
FT6336U LIB Ver: 0xA
FT6336U Chip ID: 0x64
FT6336U G Mode: 0x1
FT6336U POWER Mode: 0x0
FT6336U Firm ID: 0x3
FT6336U Focal Tehc ID: 0x11
FT6336U Release Code ID: 0x1
FT6336U State: 0x1
FT6336U TD Count 1 / TD1 (1,  156,  289) / TD2 (2,    0,    0)

FT6336U TD Count 1 / TD1 (1,  156,  289) / TD2 (2,    0,    0)
FT6336U TD Count 1 / TD1 (1,  156,  289) / TD2 (2,    0,    0)
FT6336U TD Count 1 / TD1 (1,  156,  289) / TD2 (2,    0,    0)
FT6336U TD Count 1 / TD1 (1,  156,  289) / TD2 (2,    0,    0)

@videobuff
Copy link
Author

I have succeeded in porting the sketch to use the FT6336U library and wrote my own test sketch to prove it.
https://github.com/videobuff/GraphicTouchTestFT6336U-WT32-SCO1

I must say that with the FT6336U programming is a breeze in conjuntion with the standard display file by Bodmer for the WR32-SCO1.
Here is the link to the sketch and here is a link to a small video with the sketch working.

https://youtu.be/LmLn20KAmVY

Now all that is left is stydy the library FT6206 and see / find out why it is not working with me ?
Any help there is still very much appreciated.
Erik

@elgerg
Copy link

elgerg commented Feb 2, 2022

Maybe your board does have a FT6336U and not the FT6206.

If thats the case then I would drop trying to use the FT6206 library.. from your video it looks like you are deffo on the right track.

@Fischkopppp
Copy link

I would assume that you didnt install the forked library that supports pin override?

IE:

In your Arduino libraries directory, clone a fork of Adafruit_FT6206_Library that allows overriding the I2C GPIO pins in the Arduino Wire library.

Oh, yes I skimmed over it probably 3 times ;) Thank you for clarifying. And thank you for your work. It saved me a lot of time!

@elgerg
Copy link

elgerg commented Feb 2, 2022

Oh, yes I skimmed over it probably 3 times ;) Thank you for clarifying. And thank you for your work. It saved me a lot of time!

Thanks for the praise but it should go to SnowBug, not me ;)..

@elgerg
Copy link

elgerg commented Feb 2, 2022

FYI @videobuff I think your repo (https://github.com/videobuff/GraphicTouchTestFT6336U-WT32-SCO1) isnt public. I get a 500 error when trying to access it.

@videobuff
Copy link
Author

I just checked but at least it tells me now that it is public.

Schermafbeelding 2022-02-03 om 23 23 07

@Fischkopppp
Copy link

Oh, yes I skimmed over it probably 3 times ;) Thank you for clarifying. And thank you for your work. It saved me a lot of time!

Thanks for the praise but it should go to SnowBug, not me ;)..

Skimming over things, seems to be my thing ;)

@Fischkopppp
Copy link

I got the 500 Error a lot off times on Github yesterday. Many sites were not reachable, including Bodmer/TFT_eSPI

@euandekock
Copy link

Truly strange, I was also experiencing this issue.

I am using the forked touchscreen driver, and when I set the debug flag in the ts driver, I see that it does init the Wire device with the extra parameters (18, 19), but all the readRegister calls return 0xFFFF values.

This is what I get from the code as is:

19:56:45.218 -> Chip ID: 0xFF
19:56:45.218 -> Firm V: 255
19:56:45.218 -> Point Rate Hz: 255
19:56:45.218 -> Thresh: 255
19:56:45.218 -> I2C $0 = 0xFF
19:56:45.218 -> I2C $1 = 0xFF
19:56:45.218 -> I2C $2 = 0xFF
19:56:45.218 -> I2C $3 = 0xFF
19:56:45.218 -> I2C $4 = 0xFF
19:56:45.218 -> I2C $5 = 0xFF
19:56:45.218 -> I2C $6 = 0xFF
19:56:45.218 -> I2C $7 = 0xFF
19:56:45.218 -> I2C $8 = 0xFF
19:56:45.218 -> I2C $9 = 0xFF
19:56:45.218 -> I2C $A = 0xFF
19:56:45.218 -> I2C $B = 0xFF
19:56:45.218 -> I2C $C = 0xFF
19:56:45.218 -> I2C $D = 0xFF
19:56:45.218 -> I2C $E = 0xFF
19:56:45.218 -> I2C $F = 0xFF
19:56:45.218 -> Couldn't start touchscreen controller

However, if I put the Wire.begin(18, 19) in the main setup routine just before the ts.begin, then it all works. Not sure of something is getting redefined between that, and the ts.begin code.

19:59:46.221 -> Vend ID: 0x11
19:59:46.221 -> Chip ID: 0x64
19:59:46.221 -> Firm V: 3
19:59:46.221 -> Point Rate Hz: 10
19:59:46.221 -> Thresh: 40
19:59:46.221 -> I2C $0 = 0x0
19:59:46.221 -> I2C $1 = 0x0
19:59:46.221 -> I2C $2 = 0x0
19:59:46.221 -> I2C $3 = 0x41
19:59:46.221 -> I2C $4 = 0x3F
19:59:46.221 -> I2C $5 = 0x1
19:59:46.221 -> I2C $6 = 0xB8
19:59:46.221 -> I2C $7 = 0x0
19:59:46.221 -> I2C $8 = 0x0
19:59:46.221 -> I2C $9 = 0xFF
19:59:46.221 -> I2C $A = 0xFF
19:59:46.221 -> I2C $B = 0xFF
19:59:46.221 -> I2C $C = 0xFF
19:59:46.221 -> I2C $D = 0xFF
19:59:46.221 -> I2C $E = 0xFF
19:59:46.221 -> I2C $F = 0xFF

Literally, one line added from the code in this repo:

// Pins 18/19 are SDA/SCL for touch sensor on this device
// 40 is a touch threshold
Wire.begin(18, 19);   <------ THIS!

if (!ts.begin(18, 19, 40)) {
  Serial.println("Couldn't start touchscreen controller");
  while (true);
}

@elgerg
Copy link

elgerg commented May 8, 2022

@euandekock are you using onewireng?
I just updated my screen and has the same issue. Adding Wire.begin(18, 19) in the main setup routine just before the ts.begin made it work like a charm!
Nice work!!
Thanks

@euandekock
Copy link

euandekock commented May 9, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants