Hi @KunFai,
what is “comport connect” ?
I have simplified the path of my project to have everything in the same folder like so:
Hi @KunFai,
what is “comport connect” ?
I have simplified the path of my project to have everything in the same folder like so:
hi @h128
here the code
CST816D.cpp
#include "CST816D.h"
CST816D::CST816D(int8_t sda_pin, int8_t scl_pin, int8_t rst_pin, int8_t int_pin)
{
_sda = sda_pin;
_scl = scl_pin;
_rst = rst_pin;
_int = int_pin;
}
void CST816D::begin(void)
{
// Initialize I2C
if (_sda != -1 && _scl != -1)
{
Wire.begin(_sda, _scl);
}
else
{
Wire.begin();
}
// Int Pin Configuration
if (_int != -1)
{
pinMode(_int, OUTPUT);
digitalWrite(_int, HIGH); //高电平
delay(1);
digitalWrite(_int, LOW); //低电平
delay(1);
}
// Reset Pin Configuration
if (_rst != -1)
{
pinMode(_rst, OUTPUT);
digitalWrite(_rst, LOW);
delay(10);
digitalWrite(_rst, HIGH);
delay(300);
}
// Initialize Touch
i2c_write(0xFE, 0XFF); //禁止自动进入低功耗模式。
}
bool CST816D::getTouch(uint16_t *x, uint16_t *y, uint8_t *gesture)
{
bool FingerIndex = false;
FingerIndex = (bool)i2c_read(0x02);
*gesture = i2c_read(0x01);
if (!(*gesture == SlideUp || *gesture == SlideDown))
{
*gesture = None;
}
uint8_t data[4];
i2c_read_continuous(0x03,data,4);
*x = ((data[0] & 0x0f) << 8) | data[1];
*y = ((data[2] & 0x0f) << 8) | data[3];
// *x=240-*x;
return FingerIndex;
}
uint8_t CST816D::i2c_read(uint8_t addr)
{
uint8_t rdData;
uint8_t rdDataCount;
do
{
Wire.beginTransmission(I2C_ADDR_CST816D);
Wire.write(addr);
Wire.endTransmission(false); // Restart
rdDataCount = Wire.requestFrom(I2C_ADDR_CST816D, 1);
} while (rdDataCount == 0);
while (Wire.available())
{
rdData = Wire.read();
}
return rdData;
}
uint8_t CST816D::i2c_read_continuous(uint8_t addr, uint8_t *data, uint32_t length)
{
Wire.beginTransmission(I2C_ADDR_CST816D);
Wire.write(addr);
if ( Wire.endTransmission(true))return -1;
Wire.requestFrom(I2C_ADDR_CST816D, length);
for (int i = 0; i < length; i++) {
*data++ = Wire.read();
}
return 0;
}
void CST816D::i2c_write(uint8_t addr, uint8_t data)
{
Wire.beginTransmission(I2C_ADDR_CST816D);
Wire.write(addr);
Wire.write(data);
Wire.endTransmission();
}
uint8_t CST816D::i2c_write_continuous(uint8_t addr, const uint8_t *data, uint32_t length)
{
Wire.beginTransmission(I2C_ADDR_CST816D);
Wire.write(addr);
for (int i = 0; i < length; i++) {
Wire.write(*data++);
}
if ( Wire.endTransmission(true))return -1;
return 0;
}
CST816D.h
#ifndef _CST816D_H
#define _CST816D_H
#include <Wire.h>
#define I2C_ADDR_CST816D 0x15
//手势
enum GESTURE
{
None = 0x00, //无手势
SlideDown = 0x01, //向下滑动
SlideUp = 0x02, //向上滑动
SlideLeft = 0x03, //向左滑动
SlideRight = 0x04, //向右滑动
SingleTap = 0x05, //单击
DoubleTap = 0x0B, //双击
LongPress = 0x0C //长按
};
/**************************************************************************/
/*!
@brief CST816D I2C CTP controller driver
*/
/**************************************************************************/
class CST816D
{
public:
CST816D(int8_t sda_pin = -1, int8_t scl_pin = -1, int8_t rst_pin = -1, int8_t int_pin = -1);
void begin(void);
bool getTouch(uint16_t *x, uint16_t *y, uint8_t *gesture);
private:
int8_t _sda, _scl, _rst, _int;
uint8_t i2c_read(uint8_t addr);
uint8_t i2c_read_continuous(uint8_t addr, uint8_t *data, uint32_t length);
void i2c_write(uint8_t addr, uint8_t data);
uint8_t i2c_write_continuous(uint8_t addr, const uint8_t *data, uint32_t length);
};
#endif
Thank you so much Louis for sharing this knowledge mate after 6 days of rigorous troubleshooting and scrolling the web I was able to solve this issue all credits to you.
Please stay in touch to help me with my project.
thank you ZigDuDim, i resolved the problem
So glad it helped. ZigDuDim came through for me, so I’m happy my results helped you.
Hi Louis, I’m Leyder I bough recently an ESP32-2424S012 from aliexpress PRODUCT_LINK but Im trying to use LVGL to create a project, I was following a video tutorial but my device doesn’t work, I don’t even know whats the problem, I already tried to configure the User_Setup.h file, but it doesn’t work, Can you help me with the configuration file? I use the
#define ILI9341_DRIVER // Generic driver for common displays
and the pin definitions
#define TFT_MOSI 7 // In some display driver board, it might be written as "SDA" and so on.
#define TFT_SCLK 6
#define TFT_CS 10 // Chip select control pin
#define TFT_DC 2 // Data Command control pin
#define TFT_RST -1 // Reset pin (could connect to Arduino RESET pin)
// #define TFT_BL 3 // LED back-light - Use analogWrite
#define TFT_MISO -1
In Arduino IDE I used ESP-C3-M1-I-KIT, but still can’t run any example. Please if you can help me I’ll really appreciate it.
Hi! I got the same problem, but finally I made it work (ESP32-2424S012). I’m very new user on this, but maybe if you follow my guide, you can made it work. The information provide by the seller doesn´t worked for me, even the SCH has different pinout.
For display, I worked with “TFT_eSPI” library.
On “User_Setup.h” file, this are the modification you must do:
At the beginning of the file, remove “//” from (this is the chip for this board)
// Display type - only define if RPi display
//#define RPI_DISPLAY_TYPE // 20MHz maximum SPI
// Only define one driver, the other ones must be commented out
#define GC9A01_DRIVER
Then, define your PIN
// ###### EDIT THE PIN NUMBERS IN THE LINES FOLLOWING TO SUIT YOUR ESP32 SETUP ######
// For ESP32 Dev board (only tested with GC9A01 display)
// The hardware SPI can be mapped to any pins
#define TFT_MOSI 7 // In some display driver board, it might be written as “SDA” and so on.
#define TFT_SCLK 6
#define TFT_CS 10 // Chip select control pin
#define TFT_DC 2 // Data Command control pin
#define TFT_RST -1 // Reset pin (could connect to Arduino RESET pin)
#define TFT_BL 3 // LED back-light
#define TFT_MISO -1
but I´m still having the problem with the backlight pin, because is an analog output.
In your code, insert:
#define TFT_BLK 3
void setup(void) {
pinMode(TFT_BLK, OUTPUT);
analogWrite(TFT_BLK, 255);
}
Good luck!
As rimerà says, don’t forget to uncomment
#define GC9A01_DRIVER
Do t set backlight value to 255. That’s too bright and swamps the display. Start at 10 then go from there.
hi ZigDuDim
hello name do you know the number of tx,rx pins on the board (the ones on the white connector).
If you know them please write them to me thank you
Hi,
Sorry I can see what you are referring to.
hi,
i referring of the pin rx,tx on white connector( the circled ones on blue).
you are know the number ??
Hi! I´m trying tu upload a sketch from Squareline Studio to this board,can anyone be so kind as to upload the user_setup.h file that they use?´ve trying for a few days but i just cant make it work.
hi pablo,
this is my setup file.
#define GC9A01_DRIVER
#define TFT_WIDTH 240 // ST7789 240 x 240 and 240 x 320
#define TFT_HEIGHT 240 // GC9A01 240 x 240
#define TFT_MOSI 7 // In some display driver board, it might be written as “SDA” and so on.
#define TFT_SCLK 6
#define TFT_CS 10 // Chip select control pin
#define TFT_DC 2 // Data Command control pin
#define TFT_RST -1 // Reset pin (could connect to Arduino RESET pin)
// #define TFT_BL 3 // LED back-light - Use analogWrite
#define TFT_MISO -1
#define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
#define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
#define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
#define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
#define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:-.
#define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
//#define LOAD_FONT8N // Font 8. Alternative to Font 8 above, slightly narrower, so 3 digits fit a 160 pixel TFT
#define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts
#define SMOOTH_FONT
#define SPI_FREQUENCY 80000000
// Optional reduced SPI frequency for reading TFT
#define SPI_READ_FREQUENCY 20000000
// The XPT2046 requires a lower SPI clock rate of 2.5MHz so we define that here:
#define SPI_TOUCH_FREQUENCY 2500000
I can’t get it to work, I already made the changes in tft and added the libraries, does anyone know if there is a step missing?