1

I'm building a USB keyboard that has two buttons - space and enter. The plan is to use this USB keyboard (with an Apple Lightning connector to USB) with the built in iOS switch control. I bought the lightning to USB dongle, and hooked it up to a normal keyboard, and it works fine.

Next, I took an Arduino Micro (ATMEGA32u4) and programed it to act as a keyboard with the two keys I need (space and enter). On a PC, it works just fine, but when I hook it up to my iPhone, I get the message:

Arduino Micro: The connected device requires too much power.

I've done quite a bit of research on this, and I found this post. In a nutshell, that post said that when you connect a device to an iOS device, one of the first things it does is tell the iDevice how much current it could potentially draw. This number (about 200mA for the Arduino Micro) is what decides whether the iDevice will support the device or not, when in truth, the device will not come close to its max current draw, at least not in my case.

I hooked up a meter to the normal keyboard, and it draws just over 4mA. When I hook up the Arduino, it is drawing almost 40mA. While the Arduino is drawing much more than the keyboard, it should be okay, because when I plugged in a flash drive, it was drawing 50mA, but the iPhone didn't complain.

There is my story, here is my question:

Is there any way to change it so that the Arduino Micro doesn't request so much power? In other words, is there a way to reset the value that is causing the iPhone to not use the device?


2
  • do not use an arduino for this ..... take apart a regular USB keyboard ..... discard the switches and install a couple of push buttons to replace the two keys
    – jsotola
    Commented Jan 18, 2019 at 22:28
  • Did you get this to work? I am working on a keyboard I need to connect to iPhone and I can't get it to work. Please help Commented Aug 25, 2022 at 6:38

2 Answers 2

3

The power consumption is part of the exchange with the PC when it is plugged in. You can change that. Find the file USBCore.h in your Arduino install directory. In my case (under Linux) it was:

./hardware/arduino/avr/cores/arduino/USBCore.h

Inside that file, at around line 269 (depending on the distribution) you should see these lines:

#define D_CONFIG(_totalLength,_interfaces) \
    { 9, 2, _totalLength,_interfaces, 1, 0, USB_CONFIG_BUS_POWERED | USB_CONFIG_REMOTE_WAKEUP, USB_CONFIG_POWER_MA(500) }

On the right of the second line is the requested power consumption in milliamps (currently 500). Change that to (say) 100:

That is, change USB_CONFIG_POWER_MA(500) to USB_CONFIG_POWER_MA(100).

Save and recompile.

You may find that the bootloader initially requests 500 mA even with this change (as it initially runs the bootloader). However when the sketch starts it should re-establish a USB connection and only request 100 mA. To fix that you would need to recompile the bootloader with the same fix, and reinstall it, a somewhat more complex task.

Another possible approach would be to tweak the fuses so that it doesn't run the bootloader, if you have finished debugging your code. Only do that if you are confident with playing with the fuses.

3
  • Majenko beat me to it while I was testing my answer. :)
    – Nick Gammon
    Commented Jan 18, 2019 at 21:11
  • I have a simple Arduino keyboard and it works great on all other devices then iPhone. Did you guys get this to work on iPhone? Commented Aug 1, 2022 at 11:27
  • @ErikAndershed This sounds like a new question to me. Feel free to make one.
    – Nick Gammon
    Commented Aug 2, 2022 at 5:39
1

Yes, but it requires manual modification of the Arduino core software.

  1. Find the file USBCore.h within your AVR boards installation (it could be in the data storage folder wherever that is on your OS, or within the actual IDE software)
  2. Look for the line #define D_CONFIG(_totalLength,_interfaces) \
  3. The next line has the power setting. Change USB_CONFIG_POWER_MA(500) to what you require (for example USB_CONFIG_POWER_MA(50)
1
  • I did test with 50. But it do not work. When I plug it in to my iPhone with a adapter (from usb-c to lighting and it’s supports both power and data). My Arduino chip don’t wake up. Did you get this to work? Commented Aug 1, 2022 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.