Detect FT6336U Capacitive Touch Screen on Raspberry Pi Pico using Arduino-FT6336U library.

This video show reading FT6336U Capacitive Touch Screen using Arduino-FT6336U library. (Run on Raspberry Pi Pico/3.2" 240x320 IPS SPI ILI9341 with Capacitive Touch)

For the display part, refer to the post Raspberry Pi Pico (RP2040) + 3.2inch IPS SPI Module ILI9341 (Arduino Framework using Adafruit_ILI9341 library).

To install Arduino-FT6336U for touch part, visit https://github.com/aselectroworks/Arduino-FT6336U, download code in ZIP form. For steps, read this video.


Connection
ILI9341 Module     Raspberry Pi Pico    
1 	VCC        3V3
2 	GND	   GND
3 	LCD_CS	   GP17
4 	LCD_RST	   GP21
5 	LCD_RS	   GP20
6 	SDI(MOSI)  GP19
7 	SCK	   GP18
8 	LED	   3V3
9 	SDO(MISO)  GP16
10 	CTP_SCL    GP5
11 	CTP_RST    GP3
12 	CTP_SDA    GP4
13 	CTP_INT    GP2
14 	SD_CS      GP15
Exercise code

pico_ReadTouchParam_FT6336U.ino, modified from ReadTouchParam to display touch event.
/*
Exercise to read FT6336U Capacitive Touch Screen.

Run on Raspberry Pi Pico
+ 3.2 inch 320x240 IPS SPI Module ILI9341 with FT6336U Capacitive Touch Screen,
using Arduino-FT6336U (https://github.com/aselectroworks/Arduino-FT6336U).

Basically modified from Example FT6336U CTP Controller (Arduino-FT6336U) > ReadTouchParam
*/
#include "FT6336U.h"

/*
Hardware I2C pins for Raspberry Pi Pico
I2C_SDA = 4
I2C_SCL = 5

CTP_SCL = GP5
CTP_RST = GP3
CTP_SDA = GP4
CTP_INT = GP2
*/
#define RST_N_PIN 3
#define INT_N_PIN 2

//FT6336U ft6336u(I2C_SDA, I2C_SCL, RST_N_PIN, INT_N_PIN);
FT6336U ft6336u(RST_N_PIN, INT_N_PIN);

void setup() {
    delay(500);
    Serial.begin(115200);
    delay(1000);

    Serial.println("I2C_SDA:\t" + String(I2C_SDA));
    Serial.println("I2C_SCL:\t" + String(I2C_SCL));

    Serial.println("RST_N_PIN:\t" + String(RST_N_PIN));
    Serial.println("INT_N_PIN:\t" + String(INT_N_PIN));

    Serial.println();

    ft6336u.begin();

    Serial.print("FT6336U Firmware Version: ");
    Serial.println(ft6336u.read_firmware_id());
    Serial.print("FT6336U Device Mode: ");
    Serial.println(ft6336u.read_device_mode());
}

void loop() {
    delay(1000);
    if(digitalRead(INT_N_PIN) != -1) {
      
        // TD_STATUS 0x02
        // Number of touch points [3:0] 
        // The detected point number, 1-2 is valid.
        // Serial.print("FT6336U TD Status: ");
        // Serial.println(ft6336u.read_td_status());

        uint8_t touch1_event = ft6336u.read_touch1_event();
        // Serial.println(touch1_event);
        switch(touch1_event){
          case 0x00:
            Serial.print("Press Down");
            Serial.print(" ("); Serial.print(ft6336u.read_touch1_x()); Serial.print(" , "); Serial.print(ft6336u.read_touch1_y()); Serial.print(")");
            break;
          case 0x01:
            Serial.print("Lift Up");
            break;
          case 0x02:
            Serial.print("Contact");
            Serial.print(" ("); Serial.print(ft6336u.read_touch1_x()); Serial.print(" , "); Serial.print(ft6336u.read_touch1_y()); Serial.print(")");
            break;
          case 0x03:
            Serial.print("No event");
            break;
        }
        Serial.println();

        /*
        Serial.print("FT6336U Touch Event/ID 1: (");
        Serial.print(ft6336u.read_touch1_event()); Serial.print(" / "); Serial.print(ft6336u.read_touch1_id()); Serial.println(")");
        Serial.print("FT6336U Touch Position 1: (");
        Serial.print(ft6336u.read_touch1_x()); Serial.print(" , "); Serial.print(ft6336u.read_touch1_y()); Serial.println(")");
        Serial.print("FT6336U Touch Weight/MISC 1: (");
        Serial.print(ft6336u.read_touch1_weight()); Serial.print(" / "); Serial.print(ft6336u.read_touch1_misc()); Serial.println(")");
        Serial.print("FT6336U Touch Event/ID 2: (");
        Serial.print(ft6336u.read_touch2_event()); Serial.print(" / "); Serial.print(ft6336u.read_touch2_id()); Serial.println(")");
        Serial.print("FT6336U Touch Position 2: (");
        Serial.print(ft6336u.read_touch2_x()); Serial.print(" , "); Serial.print(ft6336u.read_touch2_y()); Serial.println(")");
        Serial.print("FT6336U Touch Weight/MISC 2: (");
        Serial.print(ft6336u.read_touch2_weight()); Serial.print(" / "); Serial.print(ft6336u.read_touch2_misc()); Serial.println(")");
        */
    }else{
      Serial.println("INT_N_PIN == -1");
    }
  

}


pico_ILI9341_FT6336U.ino, Read Touch event and display on screen.
/*
Exercidr run on Raspberry Pi Pico
+ 3.2 inch 320x240 IPS SPI Module ILI9341 with FT6336U Capacitive Touch Screen,
using Adafruit_ILI9341 and Arduino-FT6336U (https://github.com/aselectroworks/Arduino-FT6336U).

Read Touch event and display on screen.

Sometimes miss touch events, depends on sampling rate.
*/

#include <Adafruit_ILI9341.h>
#include <FT6336U.h>

/*
Hardware I2C pins for Raspberry Pi Pico
I2C_SDA = 4
I2C_SCL = 5

Hardware SPI pins for Raspberry Pi Pico
SPI_MOSI = 19
SPI_MISO = 16
SPI_SCK  = 18

ILI9341 Module      Raspberry Pi Pico    
1 	VCC	    3V3
2 	GND         GND
3 	LCD_CS	    GP17
4 	LCD_RST	    GP21
5 	LCD_RS	    GP20
6 	SDI(MOSI)   GP19
7 	SCK	    GP18
8 	LED	    3V3
9 	SDO(MISO)   GP16
10 	CTP_SCL     GP5
11 	CTP_RST     GP3
12 	CTP_SDA     GP4
13 	CTP_INT     GP2
14 	SD_CS       GP15

*/

#define TFT_DC    20
#define TFT_CS    17
#define TFT_RST   21

#define RST_N_PIN 3
#define INT_N_PIN 2

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);


FT6336U ft6336u(RST_N_PIN, INT_N_PIN);

void setup() {
    delay(500);
    Serial.begin(115200);
    delay(1000);

    Serial.println();

    tft.begin();          // Initialize screen
    tft.invertDisplay(true);
    tft.fillScreen(ILI9341_BLACK);

    ft6336u.begin();

    Serial.print("FT6336U Firmware Version: ");
    Serial.println(ft6336u.read_firmware_id());
    Serial.print("FT6336U Device Mode: ");
    Serial.println(ft6336u.read_device_mode());
}

void loop() {
    if(digitalRead(INT_N_PIN) != -1) {
        switch(ft6336u.read_touch1_event()){
          case 0x00:
            tft.fillScreen(ILI9341_BLACK);
            break;
          case 0x02:
            tft.fillCircle(ft6336u.read_touch1_x(), ft6336u.read_touch1_y(), 3, ILI9341_WHITE);
            break;
        }
    }
}


Related:
Control 3.2" 240x320h IPS SPI Module ILI9341 with cap. touch FT6336U on Nologo Nano 33 BLE (Arduino Framework)

Comments

Popular posts from this blog

480x320 TFT/ILI9488 SPI wih EP32C3 (arduino-esp32) using Arduino_GFX Library

my dev.tools - FNIRSI 2C23T 3-in-1 Dual Channel Oscilloscope/Multimeter/Signal Generator