Robin2:
You cannot use the USB connection as a keyboard and as a serial port at the same time.
The code you posted is the normal code for using the USB connection as a serial port. I don't understand why you would expect it to work without that?
Please post your complete program.
...R
I meand, it only works with
while (!Serial) {
;
}
I know that what i posted above in my last post is the default code for a serial connection.
So you are basically confirming me, that using HID (Keyboard) & Serial connection over one usb connection is not working?
Why both is working while i have the IDE (with serial monitor) open then?
They keyboard commands are recived & at the same time my serial monitor recives data.
I've read different things about, it's possible & it's not possible and im not sure what the case is now.
Thats one of the reasons why i started this thread here.
When you have
while (!Serial) {
;
}
not in the setup and only trigger that peace of code, for example, when a button is pressed or a specified tag is scanned, in the loop void, then keyboard & serial are working at the same time.
if(id == valid_id) {
Serial.println("ID: " + id);
Serial.println("Access granted");
Keyboard.write('!');
delay(2000);
} else if(id == program_id) {
Serial.begin(9600);
while(!Serial) {
;
}
} else {
//access denied
}
That basically proofs, that it's possible right?
Just the
while(!Serial) {
;
}
in the setup, blocks everything, until a serial connection is opened, so that cannot be implemented as default, because the reader would not start reading without a open serial connection. Does (!Serial), wait for a open serial connection, or does it wait for the serial thing to initialize?