macdonaldtomw
Member
Hey all,
I think I've rendered my Teensy useless by uploading some code to it that makes the MCU go into sleep mode 3 seconds after it boots up.
To make matters worse, I tweaked the code after loading it, so I don't have the exact code that is on it to debug.
I'm using the LowPower library from duff.
Here is the code that I believe is loaded on it:
If I reboot my PC (to fix the serial driver enumeration problem where Windows doesn't see the Teensy if you plug/unplug it), connect the usb cable to the Teensy, and plug the Teensy into my battery (note: Vusb traces have been cut so Teensy only boots up once I connect the battery), and start clicking on the Serial Monitor button in Arduino IDE, it will open and print "Putting Teensy to sleep".
So, to flash my Teensy with a new program, I need to do so in that initial 3 second window between the Teensy booting up and going to sleep.
Problem is, it's not working. The timing is really hard to get right. You have to click "Upload" in Arduino IDE and then wait for compile, then wait for upload to Teensy Loader, then plug the battery in to boot the Teensy at just the right moment.
I'm not even sure if the Teensy Loader is able to function in such a short time window.
Help!
I think I've rendered my Teensy useless by uploading some code to it that makes the MCU go into sleep mode 3 seconds after it boots up.
To make matters worse, I tweaked the code after loading it, so I don't have the exact code that is on it to debug.
I'm using the LowPower library from duff.
Here is the code that I believe is loaded on it:
Code:
#include <LowPower_Teensy3.h>
TEENSY3_LP LP = TEENSY3_LP();
volatile boolean teensySleep=false;
float startTime=millis();
uint32_t Serialbaud = 4800;
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
byte colPins[COLS] = {
19, 20, 21, 22}; //connect to the row pinouts of the keypad
byte rowPins[ROWS] = {
15, 16, 17, 18}; //connect to the column pinouts of the keypad
void keypadSleep(){
for(int r=0; r<ROWS; r++){
pinMode(rowPins[r],INPUT_PULLUP); //Pull row pins high (internal pullup)
attachInterrupt(rowPins[r], callbackhandler, CHANGE);
}
for (int c=0; c<COLS; c++){
pinMode(colPins[c], OUTPUT); //Connect columns to ground
digitalWrite(colPins[c], LOW);
}
}
void callbackhandler() {
teensySleep= false;
Serial.println("Change on a row pin!, disabling Teensy sleep");
startTime=millis();
}
void setup() {
Serial.begin(Serialbaud); //Begin serial communication with Serial Monitor
while(!Serial);
Serial.println("Serial monitor operational");
Serial.println("Beginning main loop");
}
void loop() {
delay(3000);
Serial.println("Putting Teensy to sleep");
keypadSleep(); //Setup wakeup pins for Teensy
delay(10);
LP.Sleep();
Serial.println("I'm awake!");
teensySleep=false;
}
If I reboot my PC (to fix the serial driver enumeration problem where Windows doesn't see the Teensy if you plug/unplug it), connect the usb cable to the Teensy, and plug the Teensy into my battery (note: Vusb traces have been cut so Teensy only boots up once I connect the battery), and start clicking on the Serial Monitor button in Arduino IDE, it will open and print "Putting Teensy to sleep".
So, to flash my Teensy with a new program, I need to do so in that initial 3 second window between the Teensy booting up and going to sleep.
Problem is, it's not working. The timing is really hard to get right. You have to click "Upload" in Arduino IDE and then wait for compile, then wait for upload to Teensy Loader, then plug the battery in to boot the Teensy at just the right moment.
I'm not even sure if the Teensy Loader is able to function in such a short time window.
Help!