Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: any potential errors when powering teensy without computer?

  1. #1

    any potential errors when powering teensy without computer?

    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 !

  2. #2
    Senior Member
    Join Date
    Apr 2017
    Posts
    115
    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.

  3. #3
    Senior Member
    Join Date
    Oct 2015
    Location
    Roma (IT, EU)
    Posts
    107
    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!

  4. #4
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    2,821

    Cool

    Quote Originally Posted by XFer View Post
    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.

  5. #5
    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 .

  6. #6
    Senior Member
    Join Date
    Oct 2015
    Location
    Roma (IT, EU)
    Posts
    107
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •