!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!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

Quote

/* Keyboard Controller

Shows the output of a USB Keyboard connected to the native USB controller of an Arduino Due Board. */

UOTGHS->UOTGHS_CTRL = UOTGHS_CTRL_VBUSPO; while on USB power from PC, switches off 5V at native USB

UOTGHS->UOTGHS_CTRL = ~UOTGHS_CTRL_VBUSPO; while on USB power from PC, does not bring back 5V at native USB

//while on an external power supply there never is 5V at native USB, and the above code does nothing

I guess the code is wrong, because looking at the schematics of the Arduino Due board, it should be possible to switch on the 5V at the native USB with UOTGHS_CTRL_VBUSPO while on an external power supply. And it should be possible to turn on and off the 5V at the native USB programmatically again and again independently of power from the PC (via the programming USB port) or from an external power supply.

I hope that some person versed in the art of Arduino Due programming can answer this question, but so far no luck.

The mouse should be a straight forward Microsoft compatible USB mouse with three buttons, or two buttons and a wheel which can act as a button. The wheel function can not be used with the USBHost library.

The mouse I got has a LED (near the wheel) which will indicate whether there is 5V at the USB or not.

I hope that this problem (5V at the native USB port while on an external power supply) will be solved in the USBHost and Serial Class. Who will do that? Whom shall I contact?

I would not recommend adding this to the USBHost class, since it bypasses a safety feature. The idea of having the USB supply under the USB system control is that in case the supply is short-circuited the USB system will drop power to the port. But by using direct port writes the USB power will always remain on, even in a short circuit condition.

You can get away with this for now so long as the power supply you are using isn't more powerful than is necessary, that way it won't be powerful enough to do any real damage in a short circuit (and if you know your own mouse and keyboard are good it won't be a problem anyway). But I wouldn't add it to the library, in case someone else shorts it.

The proper thing to do is to write code which detects and resets the fault condition but I don't have the right sort of USB cable so can't help.

The proper thing to do is to write code which detects and resets the fault condition but I don't have the right sort of USB cable so can't help.

@stimmer: thank you for the reply.

By "fault condition" you probably mean "there is no 5V at the native USB port". How can this be sensed? Or, at which pin does one have to look in order to find out?

May be by "fault condition" you mean that the device at the native USB port and the power supply are providing 5V to the native USB port. Again, how and where could this be sensed?

Or, by "fault condition" you mean, that the 5V from the native USB are shorted at the other end (where the USB cable leads to, e.g. a faulty keyboard or mouse). Once more, how could this be detected by a program?

It's the third meaning, detecting a possible short. Also I think it's one of the ways the USB hardware detects a device change.

Anyway I now have a cable and have tried looking at the code. Fortunately it looks like everything needed for correct VBOF control is already in the hardware and software - the problem is that the Due circuit (incorrectly in my opinion) expects the VBOF signal to be active high, but the software is written for it to be active low.

I have been trying the following workaround: in loop(), immediately after the line usb.Task(); add the line uhd_set_vbof_active_high();This seems to work most of the time but sometimes the USB device doesn't work properly straight away - try pressing reset, or disconnecting the device and reconnecting.Can you try this and tell me if it works for you?