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:
Serial.begin(115200);
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.begin(115200);
ttySerial.println("tty Initialized");
}
void loop()
{
ttySerial.listen();
while (ttySerial.available())
//byte buffer = ttySerial.read();
//Serial.write(buffer);
Serial.write(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()
serial monitor goes crazy
andbehavior is not what I expect
are both meaninglessserial 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