The CH552 has capacitive touch support on a few pins (A0, A1, A2/MOSI, A3, MISO and SCK) without needing any external components. In this example, you'll upload the sketch to your board and use the Serial Monitor to monitor the touch input on pin A0.
// SPDX-FileCopyrightText: 2024 ladyada for Adafruit Industries // // SPDX-License-Identifier: MIT #include <TouchKey.h> uint8_t count = 0; uint8_t state = 0; void setup() { while (!USBSerial()); // wait for serial port to connect. Needed for native USB port only delay(100); USBSerial_println("QT Py CH552 Cap Touch Test"); USBSerial_println("Uses pin A0 (P1.1)"); TouchKey_begin((1 << 1)); //Enable channel P1.1/A0 } void loop() { // put your main code here, to run repeatedly: TouchKey_Process(); uint8_t touchResult = TouchKey_Get(); if (touchResult) { if (state == 0) { count += 1; state = 1; USBSerial_print("TIN1.1 touched "); USBSerial_print(count); USBSerial_println(" times"); } } else { state = 0; } delay(1000); }
Confirm that your upload settings match the settings listed here under Tools:
- Board: CH552 Board
- USB Settings: Default CDC
- Upload method: USB
- Clock Source: 16 MHz (internal), 3.3V or 5V
- Bootloader pin: P3.6 (D+) pull-up
For the port, select the COM port that matches your QT Py. It will not be labeled like you may be used to with other boards in the Arduino IDE.
You can confirm that you have the correct port selected by selecting Get Board Info from the Tools menu. This will open the Board Info window. The CH552 QT Py VID is 1209 and the PID is C550.
Text editor powered by tinymce.