My progress so far:

#include <SoftwareSerial.h>

SoftwareSerial ttySerial(10, 11); // RX, TX
byte buffer;

void setup()
  // Open serial communications and wait for port to open:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Native USB only

  Serial.println("Serial Initialized");

  //Set the data rate for the SoftwareSerial port
  ttySerial.println("tty Initialized");

void loop() 
  while (ttySerial.available())
    //byte buffer = ttySerial.read();

//    if (Serial.available())
//      ttySerial.write(Serial.read());

I am really confused because if I write the data as the as the buffer I have defined, the serial monitor goes crazy. If I upload the code as shown, I don't get anything weird in the monitor but the behavior is not what I expect.

I am writing to the software-serial on RX10 & TX11 (from javascript) the following data:
Buffer.from([0, 0, 4, 0, 0, 0, 0, 0]) (keystroke "a")

The Buffer.from method comes from node using the serialport npm module. (This is basically irrelevant since sending the data from Buffer.from('test') works and is output to the monitor.

As you can see, the buffer is 1 byte (the array forming the 8 bits). Why is the buffer not read as "a" in the monitor? Is it because the Micro has an abstract HID report descriptor (see below)?

Additionally, what does Serial.write(...) represent? I.e. when I close the Arduino IDE serial monitor, will my Arduino Micro automatically assume its HID function and write the data as an HID device? S

I know there are already keyboard and mouse HID libraries but I already have code that generates the raw HID data that I would prefer to utilize. Note that the buffer described above comes from the HID report descriptor for a generic keyboard i.e. the "4" is not merely the ASCII code for "a". Explained Here Maybe I can use https://www.arduino.cc/en/Reference/HID ?

Thanks in advance!

EDIT 1: This is the output I see from the code as shown (without the monitor "going crazy")

19:51:03.017 -> Serial Initialized
19:51:13.932 -> //Where I was hoping to see "a"

EDIT 2: I found the report descriptor in Keyboard.cpp:

  //  Keyboard
    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)  // 47
    0x09, 0x06,                    // USAGE (Keyboard)
    0xa1, 0x01,                    // COLLECTION (Application)
    0x85, 0x02,                    //   REPORT_ID (2)
    0x05, 0x07,                    //   USAGE_PAGE (Keyboard)

  0x19, 0xe0,                    //   USAGE_MINIMUM (Keyboard LeftControl)
    0x29, 0xe7,                    //   USAGE_MAXIMUM (Keyboard Right GUI)
    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
    0x25, 0x01,                    //   LOGICAL_MAXIMUM (1)
    0x75, 0x01,                    //   REPORT_SIZE (1)

  0x95, 0x08,                    //   REPORT_COUNT (8)
    0x81, 0x02,                    //   INPUT (Data,Var,Abs)
    0x95, 0x01,                    //   REPORT_COUNT (1)
    0x75, 0x08,                    //   REPORT_SIZE (8)
    0x81, 0x03,                    //   INPUT (Cnst,Var,Abs)

  0x95, 0x06,                    //   REPORT_COUNT (6)
    0x75, 0x08,                    //   REPORT_SIZE (8)
    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
    0x25, 0x73,                    //   LOGICAL_MAXIMUM (115)
    0x05, 0x07,                    //   USAGE_PAGE (Keyboard)

  0x19, 0x00,                    //   USAGE_MINIMUM (Reserved (no event indicated))
    0x29, 0x73,                    //   USAGE_MAXIMUM (Keyboard Application)
    0x81, 0x00,                    //   INPUT (Data,Ary,Abs)
    0xc0,                          // END_COLLECTION

I will need to compare this to the data I would be sending to Keyboard.write()

  • you have not said what problems you are experiencing ... serial monitor goes crazy and behavior is not what I expect are both meaningless
    – jsotola
    Commented Mar 2, 2020 at 3:01
  • please refer to this arduino.cc/en/Tutorial/SoftwareSerialExample
    – jsotola
    Commented Mar 2, 2020 at 3:03
  • @jsotola serial monitor goes crazy - the monitor receives a ton of output that is coming so fast I can't actually see what it is saying and its continuous scrolling wont let me narrow it down. behavior is not what I expect - If I turn the timestamp on I can see that data was received but it is nothing visible let alone the "a" I was hoping for Commented Mar 2, 2020 at 3:05
  • @jsotola Thanks but that is the example I used to come up with what you see above. In a sense, the software-serial works fine - it is the reading/writing I am struggling with Commented Mar 2, 2020 at 3:06
  • use a lower baud rate and you may be able to see what is flying by ... turning off the auto-scroll may also help .... otherwise, use an external serial monitor, such as putty and turn on file capture
    – jsotola
    Commented Mar 2, 2020 at 3:37

1 Answer 1


Don't use listen() this way. It clears the receive buffer. You loose the data received before listen() call.

You have only one SoftwareSerial instance so you don't need to call listen(). The listen() function clears the receive buffer because there is only one buffer for all SoftwareSerial instances.

  • This did not solve my issue. I will post my output in an edit Commented Mar 3, 2020 at 2:52
  • I am thinking that the Serial is not sure how to parse the input buffer. I thought that it might work for a Keyboard.write(<buffer>) method since the report descriptor in Keyboard.cpp might know how to parser the buffer input - but to no avail. This was part of reason for the question "what does Serial.write(...) represent?... Commented Mar 3, 2020 at 3:08
  • Perhaps HID.SendReport(uint8_t id, const void* data, int len) might work but idk what id, data, or len would be exactly in this context... maybe id is the buffer and len is 8 but what would data be? Commented Mar 3, 2020 at 3:10
  • @SterlingButters, your code in Question doesn't initialize and use HID, so there is no HID in play and sure not over SoftwareSerial
    – Juraj
    Commented Mar 3, 2020 at 6:21
  • but you think that if I initialized the HID, that buffer might work? Could you also speak to what id, data, and len might be in this case? Commented Mar 3, 2020 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.