A-Star 32U4 does not wake PC from sleep state

Is there any way to wake a computer from sleep with A-Start 32U4 board acting as a Keyboard?

Hello.

Waking up the computer is the default behavior of the Arduino Keyboard library. Whenever you call Keyboard.press or Keyboard.release in an Arduino sketch, the Keyboard class in the Arduino core code calls HID.SendReport, which calls USB_Send, which initiates the USB remote wakeup signalling, as you can see from the code here:

I modified the Keyboard example that we provide for the A-Star 32U4 Prime so that it does not call Keyboard.release constantly. After uploading it with Arduino 1.8.0, it seems to work well for waking up a computer from sleep mode. Here is the code I used:

#include <Keyboard.h>
#include <AStar32U4.h>

AStar32U4ButtonA buttonA;

void setup() {
  Keyboard.begin();
}

bool keyPressedA = false;

void loop() {
  if (buttonA.getSingleDebouncedPress() && !keyPressedA)
  {
    keyPressedA = true;
    Keyboard.press('a');
  }
  if (!buttonA.isPressed() && keyPressedA)
  {
    keyPressedA = false;
    Keyboard.release('a');
  }
}

If you want to wake up the computer without emulating a keyboard, the Arduino IDE has an undocumented function USBDevice.wakeupHost() that works too.

–David