user52264: I'm looking for two answer here.

Is it possible to power a Leonardo to be always on, separate from the power from the USB host - I've tried with a full size Leonardo and a power adapter but for some reason the code didn't run when I did that. I've bought a battery shield too which will be arriving soon.
I want it be power-able via a switch with batteries so that I do a few things. For a start avoid it's boot up time and have it pressing a key as soon as the booted computer sees it (I'm running it as a keyboard/mouse via USB-HID) and also at one point I have the computer send serial data to have the Arduino run a different part of it's code...at this point the host computer reboots. Obviously that means the Arduino will see it's USB host disappear then come back online, will that automatically reset it and thus start it from the beginning again, or can I set it so that with always on power it will carry on doing what it is, irregardless of it's connecting to the host?

Do I need to change code, or libraries to achieve any of this?
With the theory intact answered, here is some of my actual code, i've stripped most of it out as it's just a bunch of keyboard presses 
#include <Keyboard.h>
#include <Mouse.h>
char returnKey = KEY_RETURN;
char tabKey = KEY_TAB;
void setup() {
Keyboard.begin();
Mouse.begin();
// delay(60000); //Deploy Delay
delay(3000); //Testing Delay
// Keyboard commands
Keyboard.write(returnKey);
delay(14000);
// Welcome Screen 
Mouse.click(MOUSE_LEFT);
delay(100);
}

void loop() {
}


user4143: 
Is it possible to power a Leonardo to be always on, separate from the power from the USB host

Yes, that is what the barrel jack is for.

I've tried with a full size Leonardo and a power adapter but for some reason the code didn't run when I did that.

Then your code is wrong. Are you using while (!Serial); or something similar near the top of your code?

For a start avoid it's boot up time

The most certain way of doing that is to not use the bootloader. Instead program the board directly with a hardware programmer disabling (or erasing) the bootloader.

Obviously that means the Arduino will see it's USB host disappear then come back online, will that automatically reset it and thus start it from the beginning again, or can I set it so that with always on power it will carry on doing what it is, irregardless of it's connecting to the host?

The Leonardo only reboots if you open the serial port at 1200 baud, or toggle the RESET pin / button.

Do I need to change code, or libraries to achieve any of this?

It sounds like you may need to, yes - since it's not working at the moment when if the code were correct it should work.

IMPORTANT
Most computers will not recognize the Leonardo until the operating system is fully booted. This means you cannot use the Leonardo to interact with the BIOS or boot menu. The Leonardo does not implement the "Boot Protocol" keyboard which is required to interact with the BIOS or other pre-boot environment.

52264: <p>I'm looking for two answer here.</p>

<ol>
<li><p>Is it possible to power a Leonardo to be always on, separate from the power from the USB host - I've tried with a full size Leonardo and a power adapter but for some reason the code didn't run when I did that. I've bought a battery shield too which will be arriving soon.</p></li>
<li><p>I want it be power-able via a switch with batteries so that I do a few things. For a start avoid it's boot up time and have it pressing a key as soon as the booted computer sees it (I'm running it as a keyboard/mouse via USB-HID) and also at one point I have the computer send serial data to have the Arduino run a different part of it's code...at this point the host computer reboots. Obviously that means the Arduino will see it's USB host disappear then come back online, will that automatically reset it and thus start it from the beginning again, or can I set it so that with always on power it will carry on doing what it is, irregardless of it's connecting to the host?</p></li>
</ol>

<p>Do I need to change code, or libraries to achieve any of this?</p>

<p>With the theory intact answered, here is some of my actual code, i've stripped most of it out as it's just a bunch of keyboard presses </p>

<pre><code>#include &lt;Keyboard.h&gt;
#include &lt;Mouse.h&gt;
char returnKey = KEY_RETURN;
char tabKey = KEY_TAB;
void setup() {
Keyboard.begin();
Mouse.begin();
// delay(60000); //Deploy Delay
delay(3000); //Testing Delay
// Keyboard commands
Keyboard.write(returnKey);
delay(14000);
// Welcome Screen 
Mouse.click(MOUSE_LEFT);
delay(100);
}

void loop() {
}
</code></pre>
 4143: <blockquote>
  <p>Is it possible to power a Leonardo to be always on, separate from the power from the USB host</p>
</blockquote>

<p>Yes, that is what the barrel jack is for.</p>

<blockquote>
  <p>I've tried with a full size Leonardo and a power adapter but for some reason the code didn't run when I did that.</p>
</blockquote>

<p>Then your code is wrong. Are you using <code>while (!Serial);</code> or something similar near the top of your code?</p>

<blockquote>
  <p>For a start avoid it's boot up time</p>
</blockquote>

<p>The most certain way of doing that is to not use the bootloader. Instead program the board directly with a hardware programmer disabling (or erasing) the bootloader.</p>

<blockquote>
  <p>Obviously that means the Arduino will see it's USB host disappear then come back online, will that automatically reset it and thus start it from the beginning again, or can I set it so that with always on power it will carry on doing what it is, irregardless of it's connecting to the host?</p>
</blockquote>

<p>The Leonardo only reboots if you open the serial port at 1200 baud, or toggle the RESET pin / button.</p>

<blockquote>
  <p>Do I need to change code, or libraries to achieve any of this?</p>
</blockquote>

<p>It sounds like you may need to, yes - since it's not working at the moment when if the code were correct it should work.</p>

<hr>

<p><strong>IMPORTANT</strong></p>

<p><strong>Most computers will not recognize the Leonardo until the operating system is fully booted. This means you cannot use the Leonardo to interact with the BIOS or boot menu. The Leonardo does not implement the "Boot Protocol" keyboard which is required to interact with the BIOS or other pre-boot environment.</strong></p>
