You can use one of the ADC pins on the QT Py as an analog input. In this example, you'll connect a potentiometer to pin A3, upload the example code to the board and use the Serial Monitor or Serial Plotter to see the signal on the pin fluctuate as you turn the potentiometer.
- Board GND to potentiometer GND (black wire)
- Board A3 to potentiometer wiper (yellow wire)
- Board 3V to potentiometer positive (red wire)
// SPDX-FileCopyrightText: 2024 ladyada for Adafruit Industries // // SPDX-License-Identifier: MIT /* ReadAnalogVoltage Reads an analog input on pin P1.1, converts it to voltage, and prints the result to the Serial Monitor. Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu). Attach the center pin of a potentiometer to pin P1.1, and the outside pins to +5V and ground. This example code is in the public domain. http://www.arduino.cc/en/Tutorial/ReadAnalogVoltage */ #include <Serial.h> #define A0 11 #define A1 14 #define A2 15 // also MISO! #define A3 32 #define ANALOG_IN A3 #define VREF 3.3 // the setup routine runs once when you press reset: void setup() { // No need to init USBSerial // By default 8051 enable every pin's pull up resistor. Disable pull-up to get full input range. pinMode(ANALOG_IN, INPUT); } // the loop routine runs over and over again forever: void loop() { // read the input on analog pin 0, P1.1: int sensorValue = analogRead(ANALOG_IN); // Convert the analog reading (which goes from 0 - 255) to VREF: float voltage = sensorValue * (VREF / 255.0); // print out the value you read: USBSerial_println(voltage); // or with precision: //USBSerial_println(voltage,1); delay(10); }
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.
Upload the sketch to your board. Open the Serial Monitor (Tools -> Serial Monitor) at 115200 baud. As you turn the potentiometer, you'll see the voltage reading on pin A3 change.
Text editor powered by tinymce.