My Arduino Due is connected to the PC via its programming USB port and I use the Serial Monitor to communicate with the Arduino Due via its programming USB port.
I connected a keyboard to the native USB port of my Arduino Due.
First question: The keyboard gets no power from the native USB port of the Arduino Due. Is this normal? Is there no power on the native USB baord for a Keyboard or a Mouse?
Second Qustion: I wrote the following sketch to test a keyboard on the native USB port, is it correct?
/*
Keyboard Controller
Shows the output of a USB Keyboard connected to the USB
controller of an Arduino Due Board.
*/
#include <KeyboardController.h>
char inByte = 0; // incoming serial byte
// Initialize USB Controller
USBHost usb;
// Attach Keyboard controller to USB
KeyboardController keyboard(usb);
void setup(){
Serial.begin(9600);
establishContact(); // establish contact until receiver responds
}
void loop(){
if (Serial.available() > 0) {
inByte = Serial.read();
Serial.print("vom PC : ");
Serial.println(inByte);
}
usb.Task();
}
void keyPressed() {
Serial.print("Pressed: ");
Serial.print(keyboard.getKey());
Serial.println();
}
void establishContact() {
while (Serial.available() <= 0) {
Serial.println("Waits for connection to PC"); // send an initial string
delay(1000);
}
}
Greetings, Conrad
sketch_dec01b.ino (867 Bytes)