Author Topic: Digispark won't act as keyboard on PC boot  (Read 1866 times)

esc98

  • Newbie
  • *
  • Posts: 2
Digispark won't act as keyboard on PC boot
« on: April 25, 2018, 05:00:27 am »
Hey, I'm trying to use the digispark to make some bios changes to our new computer (200 pcs) and change the boot order. To avoid doing all steps by hand I tried to use a Digispark for this, but it won't be recognized on power on. After the OS is there, it starts doing it's code and is working perfectly fine, but way too late..

I tried to switch USB VID and PID IDs to a HP USB keyboard which gets recognized normally but no luck.. A copy of the usbconfig.h is attached. Is there another solution?
- Is this a normal behaviour?
- Is using an ATmega32U4 a solution?
- Would removing the 5s startup delay be a solution? digispark:tricks [Digistump Wiki]

EDIT: Couldn't find a proper fix, but stumbled across this: https://digistump.com/board/index.php?topic=1096.0 I used an Arduino Mega 2560 with Hoodloader2 and HID Project instead. If you want to download my Arduino Files, you can get them over here:
https://drive.google.com/open?id=1P3-gYGlTKPeVEivordT--9ulDofFPBBF

Here's my code:
Code: [Select]
#include "DigiKeyboard.h"
#include <C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\EEPROM\src\EEPROM.h>

#define KEY_DELETE      76 // 0x4C // 76
#define KEY_ENTER       40 // 0x40 // 40

#define KEY_ARROW_RIGHT 79 // 0x4F // 79
#define KEY_ARROW_LEFT  80 // 0x50 // 80
#define KEY_ARROW_DOWN  81 // 0x51 // 81
#define KEY_ARROW_UP    82 // 0x52 // 82

void setup() {
  pinMode(1, OUTPUT);
  digitalWrite(1, LOW);
  DigiKeyboard.sendKeyStroke(0);

  // Debug
  EEPROM.write(0, 0);
 
  if (EEPROM.read(0) == 0) {
    EEPROM.write(0, 1);
    spam(5000L, KEY_DELETE);
    DigiKeyboard.println("Fireport");
    DigiKeyboard.sendKeyStroke(KEY_ENTER);
    DigiKeyboard.delay(2000);
    DigiKeyboard.sendKeyStroke(KEY_ARROW_RIGHT);
    DigiKeyboard.sendKeyStroke(KEY_ARROW_RIGHT);
    DigiKeyboard.sendKeyStroke(KEY_ARROW_RIGHT);
    DigiKeyboard.sendKeyStroke(KEY_ARROW_DOWN);
    DigiKeyboard.sendKeyStroke(KEY_ENTER);
    DigiKeyboard.println("T..s");
    DigiKeyboard.sendKeyStroke(KEY_ENTER);
    DigiKeyboard.println("B..r");
    DigiKeyboard.sendKeyStroke(KEY_ENTER);
    DigiKeyboard.println("B..r");
    DigiKeyboard.sendKeyStroke(KEY_ENTER);
    DigiKeyboard.sendKeyStroke(KEY_ENTER);
    DigiKeyboard.sendKeyStroke(KEY_ARROW_RIGHT);
    DigiKeyboard.sendKeyStroke(KEY_ARROW_RIGHT);
    DigiKeyboard.sendKeyStroke(KEY_ENTER);
    DigiKeyboard.sendKeyStroke(KEY_ENTER);
   
  } else if (EEPROM.read(0) == 1) {
    EEPROM.write(0, 2);
    spam(2000L, KEY_P);
    DigiKeyboard.sendKeyStroke(KEY_ENTER);
    DigiKeyboard.delay(7000);
    spam(2000L, KEY_ENTER);
    while(true) {
      digitalWrite(1, HIGH);
      DigiKeyboard.delay(800);
      digitalWrite(1, LOW);
      DigiKeyboard.delay(150);
    }
  } else if (EEPROM.read(0) == 2 || EEPROM.read(0) == 255) {
    EEPROM.write(0, 0);
    while(true) {
      digitalWrite(1, HIGH);
      DigiKeyboard.delay(1500);
      digitalWrite(1, LOW);
      DigiKeyboard.delay(150);
    }
  }
}

void loop() {}

void spam(uint32_t period, byte key) {
  for ( uint32_t tStart = millis();  (millis() - tStart) < period;  ) {
    DigiKeyboard.sendKeyStroke(key);
    DigiKeyboard.delay(20);
  }
}
« Last Edit: May 31, 2018, 04:32:34 am by esc98 »