Teensy uploaded code not running on external power

kirillmcq

Member
I have a Teensy 4.1 that is connected to 2 SG90 servos, a BMP280, and an MPU6050. I also have code that interfaces with all of that and does some things. When I plug this into my computer via USB and I upload the code, everything works great.

The issue arises when I connect it to external power. I have 4 AA batteries inside a battery holder, and I connected it to the 5V and GND pins on my Teensy. The light on the MPU6050 turns on when I do this, indicating that it is receiving power. The issue is, nothing happens while it is on external power. The servos aren't even locked in place, which means these lines of code:
C-like:
  /*Init Servos*/

  servoX.attach(9); /*x->D9*/

  servoY.attach(8); /*y->D8*/

  servoX.write(90); /*Initial angle 90deg*/

  servoY.write(90); /*Initial angle 90deg*/

don't even execute, and they are in the middle of the `setup()` function.

I suspect my code doesn't run because:

4 AA batteries (6V) is not nearly enough power for the servos and sensors.

Any advice would be greatly appreciated. Thank you!
 
I don't have that, but I do have Serial.Begin in my code. Would that affect anything?
No, but I made a guess on a common problem with seeing no code. Your best bet is to make the smallest possible program that shows the problem and share the code, and also tell us IDE, TeensyDuino versions and platform.
 
I suspect my code doesn't run because:

4 AA batteries (6V) is not nearly enough power for the servos and sensors.
Yes, that's one big issue. Sensors are fine, servo's are power hungry, each probably needs 1A minimum if the small sort.

The other is the standard commodity battery holders are of low-quality riveted construction and don't work well with large current draw.
 
Another completely blind guess... try adding a delay before you initialize the motion sensors.

Perhaps Teensy is booting up too quickly and those sensors aren't ready when you try to initialize them, but of course it all works fine with the power has already been on and those sensors already had plenty of time to start up.
 
Back
Top