I was hoping for this to be a simple issue. I'm making a keyboard injector for work that automatically installs the os and all its configurations. This requires the system to reboot 3 times over the course of the full setup. I have everything about the set up itself down, but I can't solve a way around detecting how many reboots have gone through. My first go at this used the Arduinos EEPROM to keep track of how many cycles have happened. For whatever reason however when I run a reboot command, or the system reboots itself the Arduino doesn't lose power to rerun the setup command. Setting a delay() after a return for each function is inefficient and unscalable so that's out. I was thinking something like putting a jump wire directly onto the usb ports power input into an I/0 and then to pull high the reset pin when it detects a power drop but I have a feeling that won't work, and I don't want to mod the Micro just to find that out. If Anyone has any suggestions, I would highly appreciate it.
Edit: Im using an Arduino Micro and the computers are these proprietary prebuilt consoles running Windows 10.
as far as I know the USB ports of a PC will not cut off power during a reboot, even during the Power Saving Mode USB ports will still supply power.
You may check if there is an led at the console (or at a monitor attached to it!) that is switched off on again in case of a reboot. If yes you could use a light sensor to detect the reboot.
I think it will not be an easy task to detect the PC reboot unless you find something that safely signalizes that a reboot is taking place.
Maybe someone else in the forum has a better idea ...
Good luck!
ec2021
P.S.: What happens to the monitor display during the setup? Is it always bright but becomes dark only(!) while rebooting? In that case you could mount an LDR to a place on the monitor that is alway illuminated during setup but dark while rebooting ...
Thank you for the answer. Sadly something like a light sensor would defeat the plug it in and forget it aspect I'm going for. You did give me an idea however. Maybe the headphone jack gets its power cut or does a pop or something like that. Worth looking into. Hopefully there's an easier option. worst comes to worst I figured out that every reboot beyond the first one I can somewhat control. So that with stupid long 60000 * 20 delays can get it done even if its ugly.
If you don't like delays you could try something like this
unsigned long startTime = millis();
while (millis()-startTime < 60000UL*20){
// Idle or do something interesting ... ;-)
}
Actually I thought about the Windows sound message after reboot but you had to find out if it is reliable ...
I tested the following:
Connect two standard USB keyboards to a PC
Press (e.g.) NUM LOCK or CAPS LOCK at one of the keyboards
Result: Both keyboards switch their respective led on!!!!
So you might attach a standard keyboard parallel to the Micro to your PC, send KEY_NUM_LOCK or KEY_CAPS_LOCK every second and check the led of the standard keyboard ... If it does not light up in a given time the PC should reboot (or is in shut down mode ).
Actually it means that there must be a return message from the PC to each keyboard attached. If we could find out how to receive this message, we do not need a keyboard/led detector ...
while the sound message per say wouldn't work for what I need it for. the bios does make a beep when you're spamming the escape button so it may be able to try to detect the sound from the beep in the bios then run its code from there as a start. Ill need to find a way to detect that noise from the jack though but that doesn't sound very hard.
Its very interesting that both keyboards got the led indicator go off. That may come in handy if the audio doesnt work out. Maybe jump wire the led directly into an input pin.
Oh this is perfect actually. since the windows cmd can take buffered commands I can put in all the commands then make a while loop just spamming esc into the bios until it goes into the boot protocol. This helps alot thank you.
Would be nice if you could post a running sketch that detects whether Windows is running or not (and probably just switch a led on/off) because I think there will be more people interested in a solution!
Ill post it tomorrow when I get some time at work. Hopefully some oddly specific google search 15 years from now will find it helpful.
#include <HID-Project.h>
void setup() {
// put your setup code here, to run once:
BootKeyboard.begin(); //BootKeyboard seems to be just non typing functions of the keyboard. ".wakeupHost()" may come in handy one day
Keyboard.begin(); //The main keyboard function
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
while(BootKeyboard.getProtocol() != HID_BOOT_PROTOCOL){ //This checks that the pc is currently in the bios
Keyboard.press(KEY_DELETE); //Replace this with whatever the bios key is on your device
delay(100);
Keyboard.releaseAll();
}
digitalWrite(LED_BUILTIN, HIGH);
//Put your awesome code here for whatever you want to do in the boot menu
}
Okay nvm I wanted to see it work before tomorrow. It gives a non-fatal error about using a default ASCII layout but its working.