Program works connected to PC but not battery/bench

I've been trying to solve a strange issue and wondering if anyone else has had this happen and how they fixed it. I have a Mega and USB host, found dongles that work and pair with my controllers when connected to a PC via USB connection on the arduino. When I move to a battery (full charge) or a bench power supply (tried 12V through barrel jack and 5V through USB separately) the dongle doesnt seem to turn on (flashing blue light like when on PC). I hit the rest buttons and still nothing when not connected to the PC. through other posts it seems like there is a line telling the USB to wait for a serial connection to the PC before starting but I cannot for the life of me figure this one out. Any help greatly appreciated!!!!

// =======================================================================================
// Initialize - Setup Function
// =======================================================================================
void setup()
{
//Debug Serial for use with USB Debugging
Serial.begin(115200);
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection

if (Usb.Init() == -1)
{
    Serial.print(F("\r\nOSC did not start"));
    while (1); //halt
}

Serial.print(F("\r\nBluetooth Library Started"));

output.reserve(200); // Reserve 200 bytes for the output string

//Setup for PS3
PS3NavFoot->attachOnInit(onInitPS3NavFoot); // onInitPS3NavFoot is called upon a new connection
PS3NavDome->attachOnInit(onInitPS3NavDome); 

//Setup for Serial2:: Motor Controllers - Sabertooth (Feet) 
Serial2.begin(motorControllerBaudRate);
ST->autobaud();          // Send the autobaud command to the Sabertooth controller(s).
ST->setTimeout(10);      //DMB:  How low can we go for safety reasons?  multiples of 100ms
ST->setDeadband(driveDeadBandRange);
ST->stop(); 
SyR->autobaud();
SyR->setTimeout(20);      //DMB:  How low can we go for safety reasons?  multiples of 100ms
SyR->stop(); 

//Setup for Serial1:: MarcDuino Dome Control Board
Serial1.begin(marcDuinoBaudRate); 

//Setup for Serial3:: Optional MarcDuino Control Board for Body Panels
Serial3.begin(marcDuinoBaudRate);

randomSeed(analogRead(0));  // random number seed for dome automation   

}

// =======================================================================================
// Main Program Loop - This is the recurring check loop for entire sketch
// =======================================================================================

void loop()
{
//Useful to enable with serial console when having controller issues.
#ifdef TEST_CONROLLER
testPS3Controller();
#endif

//LOOP through functions from highest to lowest priority.

if ( !readUSB() )
{
  //We have a fault condition that we want to ensure that we do NOT process any controller data!!!
  printOutput();
  return;
}

footMotorDrive();
domeDrive();
marcDuinoDome();
marcDuinoFoot();
toggleSettings();
printOutput();

// If running a custom MarcDuino Panel Routine - Call Function
if (runningCustRoutine)
{
   custMarcDuinoPanel();     
}

// If dome automation is enabled - Call function
if (domeAutomation && time360DomeTurn > 1999 && time360DomeTurn < 8001 && domeAutoSpeed > 49 && domeAutoSpeed < 101)  
{
   autoDome(); 
}

Schematic please. This sounds like HW (power) issue more than code. Hand drawn schematic is fine. A nice clear pic of your hw too please.

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

here is the hardware pic. the rest of the build goes to motor controllers and such. But the key issue is this paring problem that works only on PC and then wont work when off PC

this is what I get on PC and pairs right away

The photos are not very helpful.

Ignoring requests to properly post code and a schematic does not make a good impression.

Please do not post pictures of screens. Instead, select the text, copy it and paste it here in code tags

sorry madmark asked for a clear hardware picture:

this is what comes up when connected to PC:

Bluetooth Library Started
Bluetooth Dongle Initialized
No response to HCI Reset
HCI Reset complete
Write class of device
Local Bluetooth Address: 00:1A:7D:DA:71:15
Wait For Incoming Connection Request
Gamepad is connecting
Incoming Connection Request
Remote Name: Navigation Controller
Connected to Device: E0:AE:5E:21:9B:1C
HID Control Incoming Connection Request
HID Control Successfully Configured
HID Interrupt Incoming Connection Request
HID Interrupt Successfully Configured
Wait For Incoming Connection Request
Navigation Controller Enabled

BT Address of Last connected Device when FOOT PS3 Connected: E0:AE:5E:21:9B:1C
We have our FOOT controller connected.


the schematic is just a 12V barrel jack input to the board with shield on top. I cant assess further issues if I cant get the controller to work on battery power outside of being connected to the PC

There seemed to be other similar issues in the forum from 2020 but they dont go into any detail about what the fix was:

[matt_lee_smith]

[Mar '20]

Hello Sree,

Without seeing the code it sounds a lot like you have a line in your setup function similar to:

while(!Serial);

This means that the device will wait until a serial communication is established before proceeding with the code.

Also if you use a battery that is below the minimum input voltage for the VIN pin (which I think is around 5V) then this can cause power issues.

If there isn't the while loop in your code please upload the code by posting in the reply and use thing </> button.

Thanks,
Matt

[Mar '20

Matt,

You are wonderful!! Thank you so much

As you pointed out "while(!Serial);" is the issue..

I made the change . It is working now with battery/power supply..

Thanks again

Sorry for being dumb here. This same while(!serial) code is in the SHADOW MD sketch I am using

// =======================================================================================
//                          Initialize - Setup Function
// =======================================================================================
void setup()
{
    //Debug Serial for use with USB Debugging
    Serial.begin(115200);
    while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
    
    if (Usb.Init() == -1)
    {
        Serial.print(F("\r\nOSC did not start"));
        while (1); //halt
    }
    
    Serial.print(F("\r\nBluetooth Library Started"));
    

12V in the barrel jack generally overheats the onboard 7805. Feed +5V in on the 5V pin and omit the barrel jack.

I fed the 5V from a bench though the shield and the board turned on but still no dongle activation. from my bench power supply it is delivering 5.03V drawing 0.104A and 0.523W

So what happens when you remove that line?

Which will hang until the serial monitor connects. Remove it, or replace it with something like delay(2000);

i uncommented, saved, reloaded the sketch without the line and still no activation when on bench or battery. No changes and good connection when hooked to PC and I can use the serial monitor. This has got me completely confused as to why it work only when on the PC.

Check battery voltage and connections for correctness and continuity.