Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- To test the functionality of the CH340E USB-C to Serial Converter, you would need a microcontroller that can communicate over a serial port. The most common microcontroller that's used for this purpose is an Arduino. Here's a simple Arduino sketch that sends and receives data over the serial port:
- This code opens a serial connection, waits for incoming bytes, and when a byte is received, it sends the byte back out over the serial port and also prints the byte to the serial monitor.
- To run this test:
- Upload this sketch to your Arduino board.
- Connect the Arduino's serial port to the CH340E USB-C to Serial Converter.
- Open the Arduino IDE's serial monitor (Tools -> Serial Monitor).
- Type something into the send box and click "Send" or press Enter.
- If everything is working correctly, you should see the bytes you sent echoed back to you, as well as printed out as a hexadecimal number.
- This is a basic functionality test. If you are having issues, make sure you have the correct drivers installed for the CH340E chip, and that the USB-C cable and port are functioning correctly.
- */
- void setup() {
- // Start the serial communication with the baud rate you desire, commonly 9600 or 115200
- Serial.begin(115200);
- }
- void loop() {
- // Check if data is available to read
- if (Serial.available()) {
- // Read the incoming byte
- char incomingByte = Serial.read();
- // Echo the byte back out the serial port
- Serial.write(incomingByte);
- // You can also print a message to the serial monitor
- Serial.println("Received byte: ");
- Serial.println(incomingByte, HEX);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement