Using the CH9328 breakout with Arduino involves wiring up the breakout to your Arduino-compatible microcontroller, installing the Adafruit_CH9328 library and running the provided example code.
Wiring
Wire as shown when you are uploading code to the microcontroller. The CH9328 and the microcontroller will both be connected to your computer via USB but will share a ground connection. Make sure that the CH9328 onboard switches are set to Mode 3 (switch 2 off, switches 3 and 4 on) before powering it up.
Here is an Adafruit Metro wired up to the breakout using a JST SH cable.
Here is an Adafruit Metro wired up using a solderless breadboard:
Make sure that the CH9328 onboard switches are set to Mode 3 (switch 2 off, switches 3 and 4 on) before powering it up.
Library Installation
You can install the Adafruit CH9328 library for Arduino using the Library Manager in the Arduino IDE.
Click the Manage Libraries ... menu item, search for Adafruit CH9328, and select the Adafruit CH9328 library:
There are no additional dependencies for this library.
/* * This demo is for the "transparent transmission" mode #3 which you can enter by * setting the Adafruit CH9328 switches so that #2 is OFF, and #3 and #4 are ON * In this mode you can send 'raw' HID key commands for more complex keypress combos! */ #include <Adafruit_CH9328.h> Adafruit_CH9328 keyboard; // Uncomment these lines if you need to use SoftwareSerial because there's no Serial1 device #if defined(__AVR_ATmega328P__) #include <SoftwareSerial.h> SoftwareSerial Serial1(3, 2); // RX, TX pins #endif void setup() { // Start the debug serial port, wait till it opens Serial.begin(115200); while (!Serial) delay(100); // The default baud rate for the CH9328 is 9600 Serial1.begin(9600); keyboard.begin(&Serial1); // Sending "Hello World!" as an ASCII character string keyboard.typeString("Hello World!"); // Wait for 1 second delay(1000); // Send the backspace key 12 times to erase the string byte keys[6] = {KEY_BACKSPACE, 0, 0, 0, 0, 0}; // Keycode for backspace in US mapping byte noKeysPressed[6] = {0, 0, 0, 0, 0, 0}; for (int i = 0; i < 12; i++) { keyboard.sendKeyPress(keys, 0); // Press & keyboard.sendKeyPress(noKeysPressed, 0); // Release the key } } void loop() { }
Upload the sketch to your board and open up the Serial Monitor (Tools -> Serial Monitor) at 115200 baud. The text "Hello World!
" will be typed out and then deleted. This will only happen once, since the loop in the example is empty.
Page last edited January 21, 2025
Text editor powered by tinymce.