Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Question about Arduino Keyboard library and USB sleeping

  1. #1
    Junior Member
    Join Date
    Nov 2019
    Posts
    2

    Question about Arduino Keyboard library and USB sleeping

    Hi there!

    I'm using Teensy 2.0 w/ the Arduino Keyboard/Mouse library. I've noticed that after the computer goes to sleep, even after I wake it up again, my Teensy device will not send `Keyboard.press` (or Mouse) commands, even though it is clearly responding to inputs (it blinks LEDs as expected). (Caveat here is that it may have nothing to do with sleep -- could just be a long period of inactivity)

    Do I need to be handling the computer going to sleep? Does the computer going to sleep require a new `Keyboard.begin` or something? How do I detect the computer sleeping? I've read a lot about getting the Teensy to wake a computer from sleep but I can't find anything about detecting it happening.

    Here's the code:

    Code:
    #include <Keyboard.h>
    #include <Mouse.h>
    
    int redPin = 14;
    int bluePin = 15;
    int footswitchPin1 = 20;
    int footswitchPin2 = 13;
    
    void setup() {
      pinMode(redPin, OUTPUT);
      pinMode(bluePin, OUTPUT);
    
      pinMode(footswitchPin1, INPUT_PULLUP);
      pinMode(footswitchPin2, INPUT_PULLUP);
    }
    
    void loop() {
      digitalWrite(redPin, LOW);
      digitalWrite(bluePin, LOW);
    
      if (digitalRead(footswitchPin1) == LOW) {
        Mouse.move(0,0,5);
        digitalWrite(redPin, HIGH);
      }
    
      if (digitalRead(footswitchPin2) == LOW) {
        Mouse.move(0,0,-5);
        digitalWrite(bluePin, HIGH);    
      }
    
      delay(250);
    }
    The wiring is super simple. I've got two momentary switches wired to pins 20 and 13 and LEDs wired to pins 14 and 15.

    Thanks for any help, this is my first Teensy project, if you couldn't tell.

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    10,065
    What OS is the computer running?

    Windows has some odd hibernate/sleep modes that many devices don't some back from. Looks here USB Selective suspend setting

    It might be that - or just above that maybe the Hybrid Sleep

  3. #3
    Junior Member
    Join Date
    Nov 2019
    Posts
    2
    Ah sorry, yes I'm running Windows 10.

    I can definitely update my Windows 10 settings but I don't have this issue with other peripherals. Are those somehow able to detect the suspend and reconnect?

    Thanks for the response!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •