【Beetle ESP32 C6 Mini Development Board】Multi-function desktop air quality detector-03 with built-in USB serial port to control the color of the light
[Copy link]
This post was last edited by eew_cT3H5d on 2024-5-22 20:59
1. USB serial port function (Beetle ESP32 C6 does not have a USB to serial port chip, how can I use the USB virtual serial port?)
Serial port debugging plays a vital role in embedded system development and is mainly used in the following aspects:
-
Confirm the serial port status : Use system information (such as /proc system information) or device nodes (such as dmesg | grep ttyS) to confirm whether the serial port is working properly.。
-
Configure and test serial port parameters : Use tools such as the stty command to configure the serial port's baud rate, data bits, parity bits, and other parameters, and perform self-tests to ensure that the serial port functions normally.。
-
Data transmission and reception : Serial port debugging assistant can be used to send and receive data. It allows users to communicate with the device at the other end through the serial port line on the computer to realize data transmission and reception。
-
Hardware debugging : The serial port debugging assistant is not only used for software debugging, but also for hardware debugging. By configuring the serial port parameters, you can perform detailed testing and debugging on the hardware device.。
-
Data monitoring and analysis : In the field of industrial control, serial port debugging tools are widely used in data monitoring, data collection and data analysis, and are one of the necessary professional tools for serial port application development and debugging.。
-
Protocol parsing and display : Some advanced serial port debugging assistants support multiple serial port communication protocols and can realize functions such as sending, receiving, displaying and parsing serial port data.。
-
Extended commands and custom settings : Some serial port debugging tools provide the function of extending commands and custom command lists, allowing users to create and save multiple commands to facilitate complex data sending and receiving operations.。
-
Virtual serial port simulation : For computers without physical serial ports, you can use a virtual serial port simulator to simulate serial port communication, which is very useful during debugging and testing。
In summary, serial port debugging has multiple functions in embedded system development. It can not only be used to confirm and test serial port status and parameters, but also can be used for data transmission and reception, hardware debugging, data monitoring and analysis, etc. It is a very important tool.
Beetle ESP32 C6 and other Arduino development boards are similar to microcontrollers that communicate directly with computer USB via USB, but they need to be set up to use the serial port function. The DFrobot official website introduction is not very clear, and it vaguely tells you that you need to set up to use the USB virtual serial port
Official website link: https://wiki.dfrobot.com.cn/SKU_DFR1117_Beetle_ESP32_C6#target_6
2. Try to use the built-in USB serial port
After consulting some cases and the product features of Arduion, I feel that Beetle ESP32 C6 can communicate via the built-in USB port.
Reference tutorial: https://mc.dfrobot.com.cn/thread-318977-1-1.html
https://docs.espressif.com/projects/esp-idf/en/latest/esp32c6/get-started/establish-serial-connection.html
Try to write a program for debugging: serial port
Here are the highlights:
- Check whether USB CDC is in Enable state
- Use other serial port debugging assistants to view print information
code:
int ledPin = 15;
void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
}
void loop() {
if (Serial.available()) {
int receivedData = Serial.read();
if (receivedData == '1') {
digitalWrite(ledPin, HIGH);
} else if (receivedData == '0') {
digitalWrite(ledPin, LOW);
}
}
delay(100);
Serial.println("Hell EEWORLD! ");
}
Successfully received data through the USB serial port
3. Control the color change of ws2812 through USB serial port
Code:
int ledPin = 15;
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 6 // On Trinket or Gemma, suggest changing this to 1
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 16 // Popular NeoPixel ring size
// When setting up the NeoPixel library, we tell it how many pixels,
// and which pin to use to send signals. Note that for older NeoPixel
// strips you might need to change the third parameter -- see the
// strandtest example for more information on possible values.
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels
void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
// END of Trinket-specific code.
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
//pixels.clear(); // Set all pixel colors to 'off'
}
void loop() {
if (Serial.available()) {
int receivedData = Serial.read();
if (receivedData == '1') {
digitalWrite(ledPin, HIGH);
pixels.setPixelColor(1, pixels.Color(0, 150, 0));
pixels.show(); // Send the updated pixel colors to the hardware.
}
else if (receivedData == '2')
{
pixels.setPixelColor(1, pixels.Color(150, 0, 0));
pixels.show(); // Send the updated pixel colors to the hardware.
}
else if (receivedData == '3')
{
digitalWrite(ledPin, LOW);
pixels.setPixelColor(1, pixels.Color(0, 0, 150));
pixels.show(); // Send the updated pixel colors to the hardware.
}
}
delay(100);
Serial.println("Hell EEWORLD! ");
}
display effect
Demo Video
串口控制WS2812颜色
|