Make always-USB-connected Leonardo recognized by Win10 on *external* power apply

Hi, hope this is the right subforum for an introductory query. First timer, attempted search and found very conflicting answers. I know the Leonardo is old and out of current support, too, so willing to go with a different board if I must.

I have a 'sim-pit' (simulation cockpit) for spaceflight games, pic link below if anyone's curious. The chair is configured with multiple USB peripherals (joystick, auxiliary touchscreen monitor, etc), and want to use an Arduino Leonardo in HID mode as an additional button-box (momentary buttons, some latching, and an encoder). I think I have a handle on how to program all that, pretty basic with plenty of examples all over.

Issue is that after programming, I want to leave the Arduino plugged in to the computer's USB (via a powered hub in my chair base structure), but only have the computer see it as "on" when I enable the external power thru the barrel connector to the Leonardo directly (e.g. turn "on" the button box with a switch). The chair has a 12VDC/30A PSU in it that supplies power to the seat motors, USB hub, fans, etc. and I will have switchable power distribution to specific items.

From what I read the Leonardo auto-selects source of power from USB or the external connection, or both, with the 12V enough it won't really "use" the USB power if external power is there, but as it will be plugged into a powered hub I need to break that option somehow. If it receives power from USB it is 'on' anytime the hub is (whether or not the computer is even on). So to force it to only receive power from external, I can either

  • cut the voltage line in the USB cable

  • remove the polyfuse

  • remove the T1 (?) FET

I read however that if I were to turn off external power (shutting down the Leonardo) in some of those cases, with non-powered USB still physically connected, and turn the power back on again, the W10 computer might not recognize "a USB device is newly active" and re-connect it.

Is there a right way to make sure that the Leonardo on power-on "behaves" as if it was just plugged in to USB anew each time? I did read about setting the COM port to 1200 as a way to trigger a reset which would include the communications, but seems like if I put that in my sketch up front I might be just putting myself in a loop, unless the sketch can test and only do that reset on need?

So to summarize the behavior when deployed that I want is:

  • USB always plugged in, assume computer is on and Leonardo power 'off' to start
  • Turn Leonardo external power on, computer sees it as HID device
  • Turn Leonardo external power off, computer no longer sees it because it's off
  • Turn Leonardo external power on, computer again sees it as a connected USB device...
  • (rinse and repeat)

Overall chair pic link for the interested: Simpit Sitrep, August 2019 - Album on Imgur

I have an idea how this "might" be accomplished. But I will refrain from posting it as my brain is saying it's not a good idea. So, I'll await an answer from one of the Pros and see if I was even close (which I doubt).

I did some research into my "idea" and I think it was actually correct! What you need is a "data only" USB cable. Which is basically a regular USB with the 2 data lines AND the GND line. But with the 5V line omitted.

Here is a thread that brings it up to solve a similar goal

There are other methods mentioned in that thread as well that deal with modifying the Arduino board.

DangerToMyself:
I did some research into my "idea" and I think it was actually correct! What you need is a "data only" USB cable. Which is basically a regular USB with the 2 data lines AND the GND line. But with the 5V line omitted.

Here is a thread that brings it up to solve a similar goal

There are other methods mentioned in that thread as well that deal with modifying the Arduino board.

Thanks, I found that thread, and it's the one that indicated removing the FET (reply 11) was the the best way.

I'm looking for confirmation or other ideas, I guess, before I yank a component... Post 13 therein implies that cutting the power in the USB cable but then jumpering from the Arduino's 5V to the board-side of the cut cable would also work, but elsewhere I've found people saying that's a bad idea as well (need to find those links again, it wasn't on arduino.cc).

This sounds like a very convoluted way to do things!

As there is no need (nor is it a very sensible way) to power via the "barrel jack", just feed a voltage divider (22k top, 15k bottom) from the 12 V to a pin on the Arduino, and make the code determine how to respond to the PC - which avoids problems with USB connect/ disconnects which would seem to actually represent a problem.

Paul__B:
This sounds like a very convoluted way to do things!

As there is no need (nor is it a very sensible way) to power via the "barrel jack", just feed a voltage divider (22k top, 15k bottom) from the 12 V to a pin on the Arduino, and make the code determine how to respond to the PC - which avoids problems with USB connect/ disconnects which would seem to actually represent a problem.

Why exactly is the barrel jack provided then and specified with a voltage range, if not to be (potentially) used?

With respect, how do I have Arduino code recognize whether the Arduino is plugged in and live or not on the computer? It's the PC response I'm concerned about. I know if I turn off, then on, the Arduino (whether thru barrell jack or thru any other input voltage pin) resets. What I don't know is under what circumstances that is seen by the PC as a new USB device becoming active, if the USB cable has not been unplugged/plugged. I don't intend to attempt programming on the USB/PC (device driver sort of thing) side, that's well beyond worth it...(and my skills).

Basically I want my project to act like it is plugged in to a USB "switched" hub, e.g. Amazon.com: Anker 4-Port USB 3.0 Data Hub with Individual Switch for MacBook, Mac Pro/Mini, iMac, Surface Pro, XPS, Notebook PC, USB Flash Drives, Mobile HDD, and More: Computers & Accessories , but using the Arduino's power as the on/off, as all the actual USB wire routing will be out of reach when the user is seated in the cockpit. I'm surprised more HID-applications haven't asked for this sort of thing. I presume there's a way, I just don't know the "rules".

I guess I'll just start with cutting the voltage line in the (micro USB) cable and testing how the computer reacts to power on and off events that way first, as the cable end will be 'inside' my electronics housing and I can always re-splice if that was a dumb decision later on. I was just hoping the right answer was known. So far my initial button matrix sketch worked ok, except I clearly have a bad button that's intermittently shorted when not pressed, when I unwire one row that goes away, so I need to find which of those it is and get some spares first.

rtrski:
Why exactly is the barrel jack provided then and specified with a voltage range, if not to be (potentially) used?

OK, my "stock" answer to this is:


The regulator on the Arduino UNO/ Nano/ Pro Mini/ Mega2560/ Leonardo/ Pro Micro has very little heatsink, so will not pass very much current (depending on the input voltage and thus, how much voltage it has to drop) before it overheats and (hopefully reversibly) shuts down. It is essentially a novelty provided in the very beginning of the Arduino project when "9V" power packs were common and this was a practical way to power a lone Arduino board for initial demonstration purposes. And even then it was limited because an unloaded 9 V transformer-rectifier-capacitor supply would generally provide over 12 V which the regulator could barely handle.

Nowadays, 5 V regulated switchmode packs are arguably the most readily available in the form of "Phone chargers" and switchmode "buck" regulators are cheap on eBay so these can be fed into the USB connector or 5 V pin to provide adequate power for most applications. Unfortunately, many tutorials or "instructables" are seriously outdated or misleading and have not been updated to reflect the contemporary situation.


It's a matter of "downward compatibility" such as has plagued Windoze over the years. Unfortunate design decisions, but with the perceived need to make the current design match previous expectations. Some "clones" however such as the "RoboRed" and more sophisticated Arduinos do incorporate an actually functional switchmode regulator, but it should simply be ignored on the older designs. :grinning:

As to your problem, I think you need to explain exactly what the significance of the USB connection is to the PC and its software. If the Leonardo is plugged in, it will be registered as a USB device, but unless its code at any point causes it to do so, it will neither respond to any signal from the PC nor provide any input (such as keypresses) to the PC.

rtrski:
I did read about setting the COM port to 1200 as a way to trigger a reset which would include the communications, but seems like if I put that in my sketch up front I might be just putting myself in a loop, unless the sketch can test and only do that reset on need?

You don't put that in your sketch, you use a terminal program (or dedicated application) to do that.

Note that that type of reset makes the startup of the Leonardo slow as it indicates to the boot loader that you want to upload; adds 8 seconds or so to the startup of the Leonardo.

Appreciate all the answers so far. (Especially over Xmas!)

I'll fiddle some and figure out how W10 is treating it right now with power on and off events if I can. I guess a quick powershell script might be able to open a terminal to the com port at 1200 and shut it again if I really had to (?).

(USB is annoying, supposed to be hot-swappable but the standards are so fragmented these days. I have another device (a cheap 7" touchscreen LCD as a peripheral as well with its own windows drivers) that 50% of the time on computer and USB hub powerup will not register (screen works because that's via HDMI, but the touch function doesn't without USB connectivity) until I unplug and replug the cable, and that's on first boot not on something I intended to possibly power off when not in use like this button-box. At least I can get to that cable end. I've had other older peripherals (Saitek X56 joystick and throttle) that would throw random ghost button presses if the two units were plugged into the same upstream controller (at the motherboard), needed to make sure one went to the aux USB not on the actual Intel chipset, too.)

So that's why I'm paranoid about this project addition. Once I've got the Ard wired up to buttonbox and power and inside the console I really don't want to have to axe into it again (although obviously I'll have reprogrammability if I can effect software changes that would alter behavior).

I'll reconsider on the 12V barrel, at least in terms of the voltage. I shouldn't ever be drawing much current, it is just a button-box, no LEDs, motors, relays, lions, tigers, or aardvarks. I could break the 5V line to the USB and wire that thru the console on-off switch, but the switch I had in mind is an LED lit 12V type, I'll have to find out if 5V from the hub is enough to light it up. Instead I think I can fit a buck converter inside the console too so I can proceed with the 12V thru the switch but then step it down so the Ard isn't ever challenged beyond 7-9V. Today plan on testing my encoder sketch alone, while I await replacements for the identified bad microswitches (2/5 ended up being bad....typical cheapo component quality, or I should probably blame my soldering skills..replacements will have slip-on terminals so I can solder those to wire-ends without risking switch damage. ;-/ ) I could just go the resistor voltage divider route but seems a shame to burn that much unnecessarily.

Paul__B:
...As to your problem, I think you need to explain exactly what the significance of the USB connection is to the PC and its software. If the Leonardo is plugged in, it will be registered as a USB device, but unless its code at any point causes it to do so, it will neither respond to any signal from the PC nor provide any input (such as keypresses) to the PC.

Basically the goal is building an HID button box peripheral (for flight simulation purposes), with an on/off switch but no easy access to plugging/unplugging it into the PC, simple as that. Off is just to preserve Ard lifetime if not in use. When on, I want button use to send Keyboard.press commands. When off, it can't, simple as that. I just want on/off to work correctly (e.g. if turned back on during same Windows boot, e.g. I switched games or something like that.)

I know I'm replying to myself, but I decided to attempt hacking the USB cable. Cut the 5V line and added a jumper to a pin from the microUSB (Arduino) end I could use (also a pin-socket on the other cut end, if I wanted to restore the path). Then wired up the 12V supply to my barrel plug adaptor.

I was watching USBTreeView software for connects, disconnects seen by the host computer.

  • Plugging in the USB cable (only GND and 2 data lines intact to computer) without barrell connector, obviously the PC sees nothing as the Ard is unpowered.
  • Plugging in the barrell in this state, the Arduino powers on, but the PC sees nothing. This is what I was afraid might happen if I yanked the FET, or just used a 'data only' USB cable.
  • I missed a test here - I should've unplugged the USB cable from the computer side while power was applied on the barrel, and the re-connected, to see if it showed up, if only out of curiosity...
  • Unplugged the barrel again, USB still connected with no 5V.
  • Leaving in the USB connection, but connected my extended jumper from the Ard's 5V pin to Ard's USB connection 5V line (no barrell inserted so no external supply is present yet, so obviously doing this alone results in nothing).
  • Plug in the barrell connector, and the PC sees the USB device connection. Success!
  • Unplug, and the USB connection disappears (obviously) as the whole unit is powered off.
  • Plug back in the barrell and it shows back up.

So aside from wanting to introduce a buck converter to drop my input at the barrell back down to 7-9V range for safety, I think I have my answer. Thanks very much everyone for the feedback and sanity checks along the way!

(Also my first try borrowing someone else's encoder library worked a charm, so I'm down to just having to re-source a few new 6mm momentaries I can't destroy with soldering, and will be off to the races flight deck in almost no time thereafter.)

rtrski:
Off is just to preserve Ard lifetime if not in use.

OK, well you can forget that one then. The Arduino will operate for years, almost certainly longer than your PC (because it will be running cooler). It just might crash due to power glitches, lightning and such but ...

rtrski:
When on, I want button use to send Keyboard.press commands. When off, it can't, simple as that. I just want on/off to work correctly (e.g. if turned back on during same Windows boot, e.g. I switched games or something like that.)

In which case I feel my suggestion would be the most reliable. :grinning:

But I already have a control panel machined with a spot for the lighted on/off switch for the remainder of the button panel, designed (foolishly) before I actually dove into the Arduino sketch and functionality. So I still want to have a turn on/ turn off control. Because "stubborn" :slight_smile:

(Aux top right):

Remainder of that top row is the other switched-power controls (and a 'dimmer' PWM for the seat fans) for the cockpit, overall. Everything below the top row is the fairly basic button-box the Leonardo will be controlling.

Do you really want on/off or is it sufficient that the box no longer reacts when a control is activated.

That would probably be sufficient, but with the switch requiring probably at least 7-8 V to light up the LED, I don't see how I could make that a 'logic' check in my sketch. Probably still require the buck.

But I am sad to say I managed to fry my Leonardo, I think, with my prior messing around. (Insert Homer Facepalm here.) Plug it in now (USB only, no mods to the cable) and it never makes a COM port connection. Pwr LED comes one, "L" LED also, and the polyfuse gets pretty hot.

I've tried several attempts at resetting (using the Leonardo reset instructions) to no avail. It might be rescue-able eventually but in the meantime I'm switching horses.

Based on what I've learned from this experience probably going to try a Teensy 3.2 instead - I did get a buck converter and already have it dialed down to delivering 4.98V with an 8ohm resistor load (5.03V if "loaded" only by a multimeter), pulleddown off my 12V lighted switch. Should arrive tomorrow, already searching how to do a good job of the USB HID descriptors in my programming effort.

Quick final reply in case anyone else searches on this sort of 'how to' issue (which was always more about behavior on the computer after programming).

The ultimate answer was definitely a Teensy (3.2 in my case, although the LT probably would have been enough too.)

Teensy provides an easily cut trace on the back face between Vin and VUSB. Once cut, the USB port no longer powers it, only intentional Vin connection (3.6-6V range). I don't know if one of the newer Arduino boards is more of a direct parallel to the Teensy 3.2 in the above terms.

Plus, the Teensy is much better at emulating a full USB HID device after programming via selections in the TeensyDuino add-on. It was essentially a no-brainer (important for me because in this case, I have none... :slight_smile: ): Cut trace, power with buck converter after my 12V LED switch, program as USB Keyboard/Mouse/Joystick. Windows 10 happily recognizes it connecting when all I do is toggle its primary power, even thru the USB hub (that's part of the main cockpit seat project) to the computer itself, even to USB3, and happily gives the device unplugged sound when I toggle power off. Never touch the USB cable after installation but it remains fully toggled like I wanted.