!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
A solution has been found, see my last post in this topic! Reply #7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
I connected a keyboard to the native USB port of the Arduino Due. It only works with the power coming from the PC over the programming USB port.
The moment I use an external power supply (plugged into the Arduino Due power plug), the keyboard does not work any more (because the 5V at the native USB port are switched off).
Is it possible to turn the 5V for the native USB port on by pulling PB10 UOTGVBOF high or low?
Could someone show me some code which toggles UOTGVBOF at PB10.
Attached is an example code, but the keyboard is off (the 5V at the native USB port are off) the moment I connect an external power supply.
I want to use a keyboard or a mouse to control something on the various digital and analogue ports of the Arduino Due while it is on its own power supply (e.g. a 12 V battery and not connected to a PC via its programming port).
I attached the relevant part of the Arduino Due schematics, where the 5V to the native USB are switched off when connected to an external power supply (VIN).
Greetings, Conrad
/*
Keyboard ControllerShows the output of a USB Keyboard connected to the
native USB controller of an Arduino Due Board.
*/#include <address.h>
#include <adk.h>
#include <confdescparser.h>
#include <hid.h>
#include <hidboot.h>
#include <hidusagestr.h>
#include <KeyboardController.h>
#include <MouseController.h>
#include <parsetools.h>
#include <Usb.h>
#include <usb_ch9.h>char inByte = 0; // incoming character from PC
char Key = 0; // incoming character from keyboard
int rawKey = 0; // incomming key as integer from keyboard
int led = 13; // yellow LED on Arduino Due BoardUSBHost usb; // USB Controller
KeyboardController keyboard(usb); // Attach Keyboard controller to USBvoid setup(){
pinMode(led, OUTPUT);
digitalWrite(led, LOW); // turn LED offSerial.begin(9600);
establishContact(); // establish contact with PC until a byte is received from PC
}void loop(){
if (Serial.available() > 0) {
inByte = Serial.read();
Serial.print("from PC : ");
Serial.println(inByte);if (inByte == 'w') {
// ?????????????????????????
// set VBOF at PB10 UOTGVBOF ????
// turn +5V at native USB off/on ?????
// PIOB->PIO_SODR=PIO_PB10A_UOTGVBOF; //sets UOTGVBOF ???
PIOB->PIO_CODR=PIO_PB10A_UOTGVBOF; //clears UOTGVBOF ???
// ???????????????????????????????????????Serial.println("UOTGVBOF LOW");
}
digitalWrite(led, LOW); // turn LED off
}
usb.Task();
}void keyPressed() {
Serial.print("Raw Key: ");
rawKey = keyboard.getKey();
Serial.print(rawKey);
Serial.print(" - Character: ");
Key = rawKey;
Serial.print(Key);
Serial.print(" - OEM: ");
Serial.print(keyboard.getOemKey());
Serial.print(" - mod: ");
Serial.print(keyboard.getModifiers());
Serial.println();digitalWrite(led, HIGH); // turn LED on
}
void establishContact() {
while (Serial.available() <= 0) {
Serial.println("Send a character!"); // send an initial string to PC
delay(1000);
}
}