Advertisement
microrobotics

Arduino test CH340E USB-C to Serial Converter

May 10th, 2023
1,832
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. 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:
  3.  
  4. 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.
  5.  
  6. To run this test:
  7.  
  8. Upload this sketch to your Arduino board.
  9. Connect the Arduino's serial port to the CH340E USB-C to Serial Converter.
  10. Open the Arduino IDE's serial monitor (Tools -> Serial Monitor).
  11. Type something into the send box and click "Send" or press Enter.
  12. 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.
  13.  
  14. 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.
  15. */
  16.  
  17. void setup() {
  18.   // Start the serial communication with the baud rate you desire, commonly 9600 or 115200
  19.   Serial.begin(115200);
  20. }
  21.  
  22. void loop() {
  23.   // Check if data is available to read
  24.   if (Serial.available()) {
  25.     // Read the incoming byte
  26.     char incomingByte = Serial.read();
  27.  
  28.     // Echo the byte back out the serial port
  29.     Serial.write(incomingByte);
  30.  
  31.     // You can also print a message to the serial monitor
  32.     Serial.println("Received byte: ");
  33.     Serial.println(incomingByte, HEX);
  34.   }
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement