Yep!
ou peut-il le faire tout seul même si déjà planté ?
Il faut utilisé un
watchdog. C'est un timer qui attend un signal à période régulière. Si le signal n'arrive pas sous le delai choisi, l'arduino reboot automatiquement.
Threshold value Constant name Supported on
15 ms WDTO_15MS ATMega 8, 168, 328, 1280, 2560
30 ms WDTO_30MS ATMega 8, 168, 328, 1280, 2560
60 ms WDTO_60MS ATMega 8, 168, 328, 1280, 2560
120 ms WDTO_120MS ATMega 8, 168, 328, 1280, 2560
250 ms WDTO_250MS ATMega 8, 168, 328, 1280, 2560
500 ms WDTO_500MS ATMega 8, 168, 328, 1280, 2560
1 s WDTO_1S ATMega 8, 168, 328, 1280, 2560
2 s WDTO_2S ATMega 8, 168, 328, 1280, 2560
4 s WDTO_4S ATMega 168, 328, 1280, 2560
8 s WDTO_8S ATMega 168, 328, 1280, 2560
#include <avr/wdt.h>
int t = 0;
void setup() {
//wdt_enable(WDTO_2S);
Serial.begin(9600);
setupWatchdog();
Serial.println("Setup complete");
}
void loop() {
Serial.println(t);
t = t + 200;
delay(t);
wdt_reset();
}
void setupWatchdog()
{
cli();
wdt_reset();
MCUSR &= ~(1<<WDRF);
WDTCSR = (1<<WDCE) | (1<<WDE);
WDTCSR = (1<<WDIE) | (0<<WDP3) | (1<<WDP2) | (1<<WDP1) | (0<<WDP0);
sei();
}
EDIT1 : Le watchdog est réglé sur 1 seconde, je crois, et comme je ne retrouve plus mes billes...
EDIT2 : Le code est fonctionnel, mais il faut savoir que le bootloader par defaut ne gère pas le watchdog, il faut donc le changer. En testant le code, j'ai une rallonge de cycle d'environ 20/30 ms...(visible avec t = t + 20;)
@+
Zoroastre.