Help Understanding Power Source Change Behavior Of Arduino 101

Hi again,

As the Subject states, I need help understanding the behavior of the Arduino 101 whenever it performs a switch-over from USB to DC Power input. Here is the scenario I am having trouble understanding.

  1. Plug in the USB connection. Leave the DC power input unconnected or powered off.
  2. Upload the Sketch and test using the Serial Monitor.
    (All serial communications functions of the Sketch work as expected.
  3. Plug in or turn on power to the DC power input barrel connector.
  4. Observe that the Arduino -seems- to reboot.
    (I hear the USB disconnect and reconnect chimes on the attached PC.)
  5. The Serial Monitor does not print the Sketch's debug messages and does not accept commands for the Sketch.

I am puzzled by the reboot when power is applied to the DC power barrel when the card is already being powered by the USB. I had assumed that the auto-power-switching circuitry of the Arduino 101 would simply "OR" in the power sources seamlessly without a reboot.

My project drives some LED strings that required more power than can be derived from the on-board regulators. I am driving these strings from the Vin power input via an ULN2003 driver. My project Sketch senses whether power has been applied to the DC input jack before allowing the 101 to output PWM signals to the ULN2003 driver.

I had built the code such that as the Sketch starts up, it measures the voltage of the Vin (through a voltage divider to an analog input) and then decides whether to allow further operations. I had hoped that I could simply blink a status LED showing that the project was running but needed DC power before continuing. The reboot and loss of serial communications keeps that from happening at the moment.

I did try powering up the 101 from the DC Jack first and then plugging in the USB cable. That sequence works. The serial port communications operate as expected when the 101 doesn't have to switch from external power to USB power. It only seems to be a problem when switching from USB to DC jack power.

Finally, my questions:
a) Is the reboot expected when switching power from USB to DC jack input?
Are there any strapping options that might prevent the reboot?
b) Is the loss of the serial port "real" or simply an artifact of the IDE and it's dual use of the port?
In other words, is this an IDE problem and the board should work standalone?
(It seems not but I have only done limited testing that way.)

I know that many here want to see schematics and code before answering general questions, so for completeness, here is a partial schematic of the design and code. The schematic shows a prototype board version which only uses four LED "strings" (of one LED each for now) and is thus missing the ULN2003 driver. Since the project is still incomplete and currently over 800 lines long, I have only attached the setup() and loop() sections of code. They should give a vague idea of what I am doing.

//================================================================================
/*================================================================================
 * Initial set up of the Multi-Spectral Light Box Controller.
 *===============================================================================*/
//================================================================================ 
void setup()
{
  // Start the serial port interface
  Serial.begin(9600);                         // Initialize Serial communication
  while(!Serial);                             // Wait for serial port to connect.
  #ifdef DEBUGMODE
    Serial.print("Serial Port Enabled / Connected. Initializing hardware...\n");
  #endif

  DeviceStatus = STARTUP;
  ShowStatus(DeviceStatus);
  
  memset(CmdBuffer, 0, 20);                   // Initialize the serial command buffer
  
  for (int led = 0; led < MAXLEDS; led++)
    pinMode(LED_pin[led], OUTPUT);            // Set the PWM pins to OUTPUT mode.

  // Set the initial conditions for the Multi-Spectral Light Box
  MotorState = STOPPED;
  LEDState = OFF;
  CoverState = NOTKNOWN;
  MasterEnable = false;

  // Turn all LEDs off to begin
  setLEDsOnOff(OFF);

  // Load the current default stored profile from EEPROM
  CurrentProfile = 0;
  memset(ProfileName, 0, 14);
  readProfile(CurrentProfile);
  
  // Read the input voltage on the Vin pin.
  pinMode(Voltage_Pin, INPUT);                 // Set up the Voltage measurement pin
  #ifndef ARDUINO_ARCH_ARC32
    // The Arduino 101 can only use a 3.3v reference voltage. The analogReference()
    //   function will give a compile-time error on the 101.
    // If compiling for other Arduino boards, remember to change the Vin voltage 
    //   divider to give an input voltgae appropriate to the selected reference.
    analogReference(INTERNAL);                   //   Set the voltage reference to 5v
  #endif
  ReadVinVoltage();

  // Hardware Setup and Initialization are now complete. 
  // If no errors were encountered, go to operational status.
  if (DeviceStatus == STARTUP)
    DeviceStatus = NORMAL;
  ShowStatus(DeviceStatus);
  #ifdef DEBUGMODE
    Serial.print("Hardware initialization has been completed...\n");
  #endif
}



//================================================================================
/*================================================================================
 * The main loop.
 *   This simply waits for commands to arrive via the serial port. When a 
 *   transmission is detected, the command is read and saved into the command 
 *   buffer.
 *   Following the command reciept, the command is parsed and executed.
 *===============================================================================*/
//================================================================================
void loop()
{
  // Check that we are not in an error condition.
  if (DeviceStatus != NORMAL)
  {
    //================================================
    // TODO: Need to Complete Status LED blink coding.
    //================================================
  }
  // Attempt to process any commands sent to the device.
  //   (Do not lock out serial communications completely even in an error condition.
  if (Serial.available())
  {
    ReadCommand();
    #ifdef DEBUGMODE
      Serial.print("Command recieved. Cmd = \'");
      Serial.print(CmdBuffer);
      Serial.println("\'");
    #endif
    ParseCommand();
  }
}

Any help with my two main questions above is appreciated.

Best Regards,
John

Have you tried it without the "while(!Serial);" section

All that will do is wait to output any messages until it has a USB "data" connection and not go past there until it does.

It wont do anything on external power past that point.

EDIT

And thank you for one of the best questions I have seen in a while... Almost every bit of information needed.

Bob,

Once again, thanks for the input. I have done some more thorough testing now and found the following:

  1. The Arduino does indeed actually reset itself each time the external power to the DC jack is turned on or off. I am going over the chip specs for parts used in the 101 power switching schematics and am starting to understand how this reset comes about when the external power changes state.

  2. I tested with and without the while(!Serial) construct and it doesn't change the behavior of what I was seeing before. Something about the power switch reset puts the port into a state that cannot be easily recovered without a press of the Master Reset.

  3. The loss of the Serial port is not an artifact of the IDE. All behaviors are exactly the same without the use of the IDE. I used PUTTY to simply open a terminal session without the Arduino IDE and noted no changes in results during my testing.

  4. The only sequence I found that works is to first power up the Arduino 101 using the external DC jack and only then plug in the USB connection. Under this scenario the project code is not hindered by the anomalous reboot.

I will continue to go over the 101 schematics. I have an idea for a board hack that might make my project work the way I had originally imagined.

Finally, to summarize my original questions; I have more or less found (but don't like) the answers:

a) Is the reboot expected when switching power from USB to DC jack input?
Are there any strapping options that might prevent the reboot?

b) Is the loss of the serial port "real" or simply an artifact of the IDE and it's dual use of the port?
In other words, is this an IDE problem and the board should work standalone?
(It seems not but I have only done limited testing that way.)

Answer a) Yes, the power switching circuitry on the Arduino 101 is forcing a reboot when external power is turned on or off even if the USB power is always present.

Answer b) Yes, the loss of the Serial Port is real and not an artifact of the coding of the Arduino IDE.

My next work on this aspect of my project is to further investigate the reboots to see if they can be prevented with a hardware hack and to look at ways to better handle the loss of serial communications across the reboots.

John