any potential errors when powering teensy without computer?

Status
Not open for further replies.

gony

Well-known member
a bit funny to admit but i just randomly discovered it's possible to operate teensy after uploading a program with just a simple USB adapter connected to wall power .
i had a program running and then plugged it out and connected to a charger that was near by just to see what happens , and it worked !

it might come in handy , so i was wondering whether there are any set backs or precautions i should consider with this option ?

thank you !
 
As far as I know there are no setbacks or precautions from powering without a computer, the only thing you should avoid doing is making calls to the usb serial.
 
Well, I'd say that after having developed your program, the final goal would be indeed having it run without being attached to a computer.
As vjmuzik pointed out, just be sure you don't have calls to "Serial" in your final program, because "Serial" in Teensy is actually USB-Serial (not UART, which is called "Serial1") and would not be available when the board works without a PC attached via USB.

A typical problem you want to avoid:

Code:
:
while (!Serial);
:

This piece of code is often found within Arduino sketches: it waits for Serial port to be available before continuing (so that no Serial.print debug messages are missed).
It works ok when connected to a computer (with Serial Monitor launched); but when you run the board alone, this would prevent your program to run!
 
Well, I'd say that after having developed your program, the final goal would be indeed having it run without being attached to a computer.
As vjmuzik pointed out, just be sure you don't have calls to "Serial" in your final program, because "Serial" in Teensy is actually USB-Serial (not UART, which is called "Serial1") and would not be available when the board works without a PC attached via USB.

A typical problem you want to avoid:

Code:
:
while (!Serial);
:

This piece of code is often found within Arduino sketches: it waits for Serial port to be available before continuing (so that no Serial.print debug messages are missed).
It works ok when connected to a computer (with Serial Monitor launched); but when you run the board alone, this would prevent your program to run!

Generally, I use something like this:

Code:
  // wait up to 3 seconds for the Serial device to become available
  while (!Serial && (millis () <= 3000))
    ;

This way if you are connected to the computer, it will wait until the Serial USB connection is set up. If you are powering it via a battery, it will just wait 3 seconds before continuing.

You can keep in the Serial.print and Serial.println calls, the output will be discarded.

There are cases with LEDs like neopixels (WS2812) that may work better on batteries than on USB power. When I had the problematical neopixels in use, I would program the microprocessor with USB, and then unplug it and run it off of the lithium ion battery to watch it work. If you are going to power your Teensy directly with a battery that doesn't provide USB power, you need to either cut the trace underneath the Teensy so it isn't powered by USB, or just remove the battery before connecting the USB power. It may 'word' if you have two power sources, but it isn't recommended.
 
so i actually had the line :
Code:
Serial.begin(9600);while(!Serial);
in my code , so i changed it as MichaelMeissner suggested :
Code:
Serial.begin(9600);
   // wait up to 3 seconds for the Serial device to become available
  while (!Serial && (millis () <= 3000));

and it worked!

i still have issues when i connect it back to the computer though . i'm not sure 100% it's related to plugging it to an usb adaptor , but lately I've been getting more of these random errors of "failed to reboot" , "failed to upload , teensy is busy " and such , printed in red on the TyCommander screen . it only is solved after a hard reset (15 seconds) .

i had this problem much less before connecting without computer but according to people in this thread i will decide if to open a new one asking only about it .
 
If your program is running very "tightly" (very busy "loop()", or empty loop() which is continuosly executing), the microcontroller may be too busy to aknowledge the reboot command in time.
It's not unheard of, it occurred to me at times.
Anyway, check your USB cables and, if possible, connect the Teensy directly to a native USB port.
 
Status
Not open for further replies.
Back
Top