Teensy3.1 losing my application

Status
Not open for further replies.

SMaric

Member
Once I've downloaded the application - all runs OK
Until I unplug the micro-usb - then I seem to lose the application that was downloaded

I am running from external power (so have cut the trace on the back of the board)

I need to run my Teensy program without being connected to a PC

Have I missed something obvious ???
 
Without more cutting&connect pics and code details anything would be a W.A.G. - per Forum Rule . . .

I'd say start with a simple BLINK sketch to visually prove it works before and after USB disconnect -
 
At powerup, Teensy always runs whatever program you've previously loaded.

Problems where your program works after uploading, but not upon powerup, usually turn out to be 1 of 2 things.

1: leftover "while (!Serial) ;" waiting for the Arduino Serial Monitor
2: immediate initialization of hardware that takes time to boot up (eg, MPU6050)

Since you didn't post any code or details (the "forum rule"), I can't give you any more specific advice.
 
Putting something like this setup is better than the infinite "while (!Serial)" - but still give time to catch the USB setup when needed:

while (!Serial && (millis() <= 6000));

extending that to this combo at least pops the LED on upfront to show sign of life so you never wonder if the code 'starts' - the qBlink() toggles the LED state whenever called. This setup will work with or without USB connected to an active port for monitoring, but when not on active USB will sit until 6 seconds after power-up with the LED ON as written:

Code:
#define qBlink() (digitalWriteFast(LED_BUILTIN, !digitalReadFast(LED_BUILTIN) ))

void setup() {
  digitalWriteFast(LED_BUILTIN, 0);
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(9600);  // USB
  qBlink();
  while (!Serial && (millis() <= 6000));
  Serial.print("Hello World! ... ");
  Serial.println(millis());
  qBlink();
}

void loop() {
  delay(1000);
  qBlink();
  Serial.println(millis());
}
 
I have been through the code and commented out ALL uses of Serial - so that's not the cause
I did have the while (!Serial && (millis() <= 6000)); code in place --- BUT all that is now gone

Code uses the qBlink technique to show application running --- blink every major iteration of the main processing task

Just using the timer interrupts, the ADC (interrupt based) and the I2C bus to communicate with a PWM/Servo driver board


Any thoughts gratefully received
 
SMaric - are you saying you never see the LED on or see it cycle? With or without USB?

You don't have to remove the Serial - they fail 'gracefully'. The while is just to five the PC time to catch the USB when connected.

Supposing it Programs fine? Compile as LC and try to upload - you should get an error. Then rebuild for the 3.1 @96MHz optimized with the code that worked for me.

Does it run the first time after upload restart? Or never run to blink?

I'd hit the button a second time after that with TeensyDuino Verbose on and see if anything pops out.

You may have a corrupted software install - unless you see it work on other units.

Also perhaps drop a picture of your board as noted above so Paul can observe the cut and wiring as it stands.
 
Any thoughts gratefully received

Maybe try File > Examples > 01.Basics > Blink on your board? Perhaps do it with your board removed from any connections to other circuitry?

That can at least help test if the hardware is still working properly, and if it is, at least give you some confidence and a starting point for troubleshooting.
 
I think I'm having the same problem: my program runs when I program the Teensy (3.1), but not when I just power the board from USB or a LiPo battery. I'm using Arduino 1.6.3 and the Teensy Loader.

I've been working with 8-bit boards for years and have never had an issue like this. I've tried putting delay()'s up to 2000ms between things in setup() but nothing has changed this behavior.

I tested with the "Blink" sketch and it works as expected: I can program it, and the program runs on USB or battery power. It just doesn't want to run this program talking to the MAX7219 (which btw is definitely not a genuine Maxim IC ;).

Any clues would be greatly appreciated!

Here's the complete sketch:

Code:
/*
MAX7219 Matrix Driver IC Test

It runs after programming, but not when just powered from USB or an external LiPo cell.
*/

#include <Sprite.h>
#include <Matrix.h>

long t0;
long t;
long t_last;
long d = 0;
int d_exp = 4;    // number of steps to increment the next row
byte x, y;

Matrix myLeds = Matrix(11, 13, 10, 1);

void setup() {
  myLeds.clear();
  t0 = millis();
  t_last = millis();
}

void loop() {
  t = millis();
  if (t > t_last) {
    t_last = t;
    d = d_exp;
    for (y = 0; y < 8; y++) {
      x = (1 + (t / d)) % 8;
      if (x == 0) {
        myLeds.write(7, y, LOW);
      }
      else {
        myLeds.write(x - 1, y, LOW);
      }
      myLeds.write(x, y, HIGH);
      d *= d_exp;
    }
  }
}
 
Details: it seems the application isn't "lost," Teensy just doesn't start up the MAX7219 chip wired up to it.

When I power it via USB, it does run-- I can tell because I added lines to turn on Serial and write a message every second, and it works when I plug it into the USB port and watch the serial monitor. I just don't see any LED's on the matrix :(

How does Teensy reset itself after programming? It's definitely doing something different than when it starts up otherwise.
 
Put overt delay in perhaps 10 seconds, after qBlink on. I don't know the MAX startup behavior, but from first power the teensy is fast. If you added qBlink that should show up before anything else can go wrong, showing the start. On a'warm' program restart the MAX is ready.
 
I agree, put a delay(10000) as the very first line in setup().

If that MAX7219 is a counterfeit, it's very likely some sort of microcontroller programmed to mimic the real part. It probably isn't ready immediately, and Teensy boots up very quickly.

Also, put some code in your loop() to toggle pin 13 (the LED on Teensy), so you can see if the loop is running!
 
QBLINK is that led 13 toggle. And getting that on before the delay would show you the teensy is in control.

Start with msg #4 code and add the MAX after with the while made:

while (millis() <= 10000);

Using this
Code:
  while (millis() <= 10000) if (!(millis()%500))  qBlink();

Will even make it give a twitchy blink each half second during the 10 second wait to make the time pass faster and letting you know the code is actively there.
 
Last edited:
Works! Added delay in Matrix library

Adding delays in various places in the sketch had no effect-- the program with Serial output worked fine but the MAX7219 didn't display anything.

Everything pointed to the counterfeit MAX7219 being the issue since, as you mention, Teensy starts up so fast. I modified the Matrix library to run a delay in the constructor, before setting any of the MAX7219 registers, and it works!

I delayed 1000ms at first, then I dialed it down to see how much time the fake MAX7219 needs: about 8ms to start up properly.

Thanks for the clues, I'm happily Teensying away :)
 
Status
Not open for further replies.
Back
Top