基于Arduino框架下实现USB CDC虚拟串口打印ADC数据
- 📌相关篇《【CH559L单片机】DMA方式在手工选择通道模式下AD采样数据串口输出》
- 👉了解CH55X Arduino平台环境搭建《Arduino框架下最便宜的开发芯片-CH552初探》
- 选择
Default CDC选项

示例代码
/*
AnalogReadSerial
Reads an analog input on pin P1.1, 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/AnalogReadSerial
*/
#include <Serial.h>
// the setup routine runs once when you press reset:
void setup() {
// No need to init USBSerial
//getLineCodingHandler();
// By default 8051 enable every pin's pull up resistor. Disable pull-up to get full input range.
pinMode(11, INPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin P1.1. You may use P1.1, P1.4, P1.5 and P3.2
int sensorValue = analogRead(11);
float voltage = sensorValue * (3.3/ 2048.0);
// print out the value you read:
USBSerial_print("sensorValue=");
USBSerial_print(sensorValue);
USBSerial_print(" ;电压值:");
USBSerial_print(voltage);
USBSerial_println("V");
// USBSerial_flush();
delay(800);
}
- 🌿选择USB CDC虚拟串口监视器打印


⛳注意事项
当使用Arduino IDE编译后,将程序烧录到了目标开发板后,推荐使用Arduino IDE自带的串口监视器查看调试信息:打开对应的USB CDC虚拟串口,在Arduino IDE环境下,代码的编码格式和其他平台例如Keil环境下有所不同,如果用其他串口调试工具软件查看串口调试信息,打印出来的信息中如果有中文会是显示乱码,这是编码问题,这一点需要注意。

8771

被折叠的 条评论
为什么被折叠?



