-
Notifications
You must be signed in to change notification settings - Fork 262
Command Line Upload Instructions for Windows
While the mitigation suggestions for time out issues presented on the Troubleshooting Firmware Upload Issues page work most of the time, an alternative and almost surefire way to deal with the timing issue is to upload the firmware via the command line. This breaks the Upload process into two distinct steps -- creating the binary and then uploading it -- rather than a single combined process.
If it proves out that people need to use this process frequently, the community is hoping to put together a PowerShell script that will make this process much simpler. In the meantime, this more manual process works.
Once you work through this process, you should only ever need to do Part 3: Execute the Command. You will only need to update the command if the location of where you are storing your Sketch changes, or you need to use a new version of the avrdude
program.
You need to know the COM of the Bootloader. Do not confuse this with the COM port of the Keyboardio Model 01 itself. See the Verify Bootloader Driver Installation or Determine its COM Port instructions on how to detemine the Bootloader's COM port.
- If you are using the Example sketch, you will need to first Save a copy of it. Go to File > Save As to do such.
- In the Arduino IDE, go the menu and select Sketch > Export compiled Binary. This will compile and save the sketch binary to your Sketch's "Sketch Folder" or "Sketch Directory". You can open that directory from the menu by selecting, depending on your operating system either Sketch > Show Sketch Folder.
- Inside the Sketch Directory will be a
{SketchName}.ino.model01.hex
file, For example, if your sketch is namedMy-Model01-Firmware
, there will be a file namedMy-Model01-Firmware.ino.model01.hex
. There may also be a file withwith_bootloader
in the name. We can ignore this one. - Copy the full path to the
.ino.model01.hex
file and save in a Plain Text file (using Notepad for example). An example path would be:C:\Users\UserName\Documents\Arduino\My-Model01-Firmware\My-Model01-Firmware.ino.model01.hex
In the examples below, UserName
is used as a generic name. In your case it will be the actual user name you have on your computer. Similarly the examples use a sketch named My-Model01-Firmware
. This will vary depending on what you named your sketch when you saved it.
For those unfamiliar with using command line commands, here is a quick tutorial. Command line commands use what are called switches. They are single case sensitive values that are proceeded by a dash -
For example the switch -v
turns on verbose output. Some switches take arguments. These are entered immediately after the switch without a space. For example, giving the -P
(for port) switch an argument of COM6
results in -PCOM6
. Spaces separate switches. So combing the precious two examples we would have -v -PCOM6
. Because spaces separate switches, an argument cannot contain spaces unless it is quoted. So if we want to pass the value Charlie Brown
to the example name switch -N
, we would write -N"Charlie Brown"
. The instructions below will walk you through creating the command we need. As part of that, it will be quoting some arguments to some of the switches.
There are two options on how yuo can create the command. Either should work.
- Be sure that Verbose Output is turned on for the Upload process. See Turn on Verbose Upload Output
- Run the Upload process from the Arduino IDE (It's ok is this step fails. We just need to copy a line from the output.)
- After the process completes, scroll through the output. After a series of lines that read similar to
PORTS {COM1, COM7, } / {COM1, COM7, } => {}
(the port values may differ) will be a long line that is the command used to do the upload. It will look similar to this:We will be cleaning that up a bit.C:\Users\UserName\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/bin/avrdude -CC:\Users\UserName\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf -v -patmega32u4 -cavr109 -PCOM7 -b57600 -D -Uflash:w:C:\Users\UserName\AppData\Local\Temp\arduino_build_313920/My-Model01-Firmware.ino.hex:i
- Select the full command from your output (being sure to scroll to the right) and copy it.
- Open a Plain Text editor such as Notepad (or EditPad, Notepad++, UltraEdit, etc.) Do not use a Word processor or other rich text editor like Word.
- Paste the command you copied into Notepad.
- From the menu, Select Edi > Replace. Enter a forward slash
/
in the "Find" field and an backslash '\' in the "Replace" field. Then click "Replace All". - The Initial portion of the command line is the program,
avrdude
that executes. Edit it so that the full path is inside double quotes"
. So this:will become thisC:\Users\UserName\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9\bin\avrdude
Keeping in mind your actual path may vary some (including having your actual username rather than"C:\Users\UserName\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9\bin\avrdude"
UserName
) - Next we want to quote the path to the
avrdude.conf
file that is passed into the-C
switch. We want an opening quote after the-C
switch before the path, and a closing quote at the end of the path. So this:is changed to-CC:\Users\UserName\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9\etc\avrdude.conf
-C"C:\Users\UserName\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9\etc\avrdude.conf"
- The next thing we need to do is to change the COM port. The value in the command may either be that of the "Keyboardio Model 01" (most likely), or the value of the "Keyboardio Model 01 Bootloader", or simply the bootloader. In the Prerequisite section above, you determined the COM port for the bootloader. Edit the command;s
-P
swtch so that it has the COM port of the Bootloader. In this example, the Keyboardio Model 01 is on COM7 and the Bootloader is on COM6. So we changePCOM7
to-PCOM6
. - The final switch,
-U
, and its argument is a little different in the syntax it uses. In addition to a path, it contains some other values delimited with a colon:
. We are simply going ot quote the full argument in case the path contains spaces. So this:will become this:-Uflash:w:C:\Users\UserName\AppData\Local\Temp\arduino_build_313920\My-Model01-Firmware.ino.hex:i
-U"flash:w:C:\Users\UserName\AppData\Local\Temp\arduino_build_313920\My-Model01-Firmware.ino.hex:i"
- You will notice the
-U
argument contains a path to a temporary file. The Arduino IDE puts its build binary files in a temporary directory. This is fine to use as is, but it will change every time you restart the Arduino IDE because the temporary directory used,arduino_build_313920
in this example, will be different the next time the Arduino IDE is restarted. Thus the path would need to be updated. Instead, we are going to use the binary we created in the Part 1: Create the Binary. Replace the path to the hex file in the temporary directory to the path you created in the part 1. The Path will likely start withC:\
. Be careful to not remove/overwrite theflash:w:
before the path value or the:i"
at the end of it. So this:will become something like this:-U"flash:w:C:\Users\UserName\AppData\Local\Temp\arduino_build_313920\My-Model01-Firmware.ino.hex:i"
-U"flash:w:C:\Users\UserName\Documents\Arduino\My-Model01-Firmware\My-Model01-Firmware.ino.model01.hex:i"
- After all the edits, you should have changed the copied command from something like this:
to something like this:
C:\Users\UserName\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/bin/avrdude -CC:\Users\UserName\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf -v -patmega32u4 -cavr109 -PCOM7 -b57600 -D -Uflash:w:C:\Users\UserName\AppData\Local\Temp\arduino_build_313920/My-Model01-Firmware.ino.hex:i
"C:\Users\UserName\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9\bin\avrdude" -C"C:\Users\UserName\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9\etc\avrdude.conf" -v -patmega32u4 -cavr109 -PCOM6 -b57600 -D -U"flash:w:C:\Users\UserName\Documents\Arduino\My-Model01-Firmware\My-Model01-Firmware.ino.model01.hex:i"
- Double check your command carefully.
- Use File > Save As in Notepad to this command somewhere.
- You can now proceed to Part 3: Execute the Command below.
As a point of reference, the finally command will look something like this. It will vary slightly based on your system.
"C:\Users\UserName\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9\bin\avrdude" -C"C:\Users\UserName\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9\etc\avrdude.conf" -v -patmega32u4 -cavr109 -PCOM6 -b57600 -D -U"flash:w:C:\Users\UserName\Documents\Arduino\My-Model01-Firmware\My-Model01-Firmware.ino.model01.hex:i"
- Use the Search field in the Start Menu to search for
%LOCALAPPDATA%\Arduino15\packages\arduino\tools\avrdude
. This will the target directory in Windows Explorer.- If the directory is not found, try searching for just the
%LOCALAPPDATA%
directory and look for an Arduino directory. If it, or the packages directory within it, is missing, you need to install the Keyboardio board in the Board Manager as outlined in Step Two of the Arduino Installation Guide. - If you are still unable to locate the directory, you can instead use the
avrdude
instance installed with the Arduino IDE. Navigate to eitherC:\Program Files (x86)\Arduino\hardware\tools\avr
(64-bit Windows) orC:\Program Files\Arduino\hardware\tools\avr\
(32-bit Windows) ans skip to step 3.
- If the directory is not found, try searching for just the
- In Windows Explorer, drill down into the
#.#.#arduino#
directory with the latest version number. For example, if both6.0.1-arduino5
and6.3.0-arduino9
are showing, navigate to the6.3.0-arduino9
directory since 6.3.0 is the latest version number. - Copy the full path to the directory you are in. It will be something like
C:\Users\UserName\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9
whereUserName
is your user name and the last directory and the last directory is the one determined in the previous step. - Open a Plain Text editor such as Notepad. Do not use a Word processor.
- Enter an opening double quote
"
character then paste the path you just copied. Append\bin\avrdude
to the end. Then enter a closing quote"
. The end result will be something like this:"C:\Users\UserName\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9\bin\avrdude"
- Enter a space followed by
-C"
making sure to use an uppercase C Then paste the same path fom step 3 again. Append\etc\avrdude.conf
to the end of it and close the quotes. The end result wil be this so far:"C:\Users\UserName\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9\bin\avrdude" -C"C:\Users\UserName\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9\etc\avrdude.conf"
- Enter a space followed by the value
-v -patmega32u4 -cavr109 -P
. Immediately after the-P
(i.e. no space) enter in all uppercase the COM port determined in the Prerequisite section above. For example, if yuo determined it to beCOM6
you will enterCOM6
. Then enter a space followed by-b57600 -D
. So far you should have something like this:"C:\Users\UserName\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9\bin\avrdude" -C"C:\Users\UserName\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9\etc\avrdude.conf" -v -patmega32u4 -cavr109 -PCOM6 -b57600 -D
- Next enter a space followed by the value
-b57600 -D -U"
(including the opening double quote at the end. - Paste the value you determined in Part 1: Create the Binary. and then enter (without any spaces) the value
:i"
(including the closing quote). You should now have the final full command:"C:\Users\UserName\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9\bin\avrdude" -C"C:\Users\UserName\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9\etc\avrdude.conf" -v -patmega32u4 -cavr109 -PCOM6 -b57600 -D -U"flash:w:C:\Users\UserName\Documents\Arduino\My-Model01-Firmware\My-Model01-Firmware.ino.model01.hex:i"
- Double check your command carefully.
- Use File > Save As in Notepad to save this command somewhere.
- You can now proceed to Part 3: Execute the Command below.
Below are two options based on whether or not you have a second keyboard (other than the Model 01 ) attached to you PC.
- Open the command you created in Part 2: Create the Command to Use. Make sure there is no trailing spaces or return/newline characters after the command. To check this in Notepad, hit the cursor down arrow key
↓
on your keyboard. The cursor should not move to the next line but stay on the first line with your command. If it does move down, delete the return/newline character at the end of your command. Test again to make sure no additional new lines need to be deleted. (Don't forget to save the changes.) - Open a command Window in one of the following ways:
- Search for
cmd
in the start menu - Type
Win+R
to open the Run dialog. Entercmd
and click OK
- Search for
- Copy the edited command from NotePad by using Edit > Select All and then Edit > Copy.
- Paste the command into the command window after the C:\Users\UserName> prompt (the actual prompt may vary. It doesn’t matter.) Note that Ctrl+V will NOT work in the command window. Instead, right click in the window and select "Paste" from the context menu.
- If you did not copy any new lines, the cursor should be at the end of the command and the command should not run. If it does run, simply use the the cursor down arrow key
↑
on your keyboard to retrieve the command from history.
- If you did not copy any new lines, the cursor should be at the end of the command and the command should not run. If it does run, simply use the the cursor down arrow key
- Make sure you have a fresh binary created by running __ in the Arduino IDE as discussed in Part 1: Create the Binary.
- Unplug your Model 01 from PC. Wait a good 10 seconds. You should hear the standard USB disconnect tone. If you want to be absolutely sure, make sure that the “Keyboardio Model 01” no longer shows under “Ports (CON & LPT)” in Device Manager. (See Open the device Manager for details.)
- Make sure the command window has focus. Hold down the
prog
key on your keyboard and plug it into the PC. As soon as you see the red light under theprog
key come on, hit Enter on your second keyboard (not the Model 01) so the command we pasted into the command window runs. (You can let go of theprog
key) - The firmware should upload and end with the statement
avrdude done. Thank you.
- To rerun the command, use the the cursor down arrow key
↑
on your keyboard to retrieve the command from history. Then return to step 5. Rinse and repeat as needed.
- Open the command you created in Part 2: Create the Command to Use. We want to have a single newline return character after the command. Here;s how to check this in Notepad:
- Make sure the command is on the very first line in Notepad
- Hit the cursor down arrow key
↓
on your keyboard. If it moves down, you hae a newline. If not, use theEnd
key to go to the end of the line and hitEnter
. Save your changes. - Be sure there is only a single newline. If you hit the cursor down arrow key
↓
a second time, it should not move to another new line.
- Open a command Window in one of the following ways:
- Search for
cmd
in the start menu - TypeWin+R
to open the Run dialog. Entercmd
and click OK - Copy the edited command from NotePad by using Edit > Select All and then Edit > Copy.
- Make sure you have a fresh binary created by running __ in the Arduino IDE as discussed in Part 1: Create the Binary.
- Unplug your Model 01 from PC. Wait a good 10 seconds. You should hear the standard USB disconnect tone. If you want to be absolutely sure, make sure that the “Keyboardio Model 01” no longer shows under “Ports (CON & LPT)” in Device Manager. (See Open the device Manager for details.)
- Hold down the
prog
key on your keyboard and plug it into the PC. As soon as you see the red light under theprog
key come on, you can let go of theprog
key, and use your mouse to right click in the command window and select "Paste". The command will paste into the window. And since it has a newline character on the end, it should run. - The firmware should upload and end with the statement
avrdude done. Thank you.
- To rerun the command, simply go to step 3.
Troubleshooting
Advanced Topics
Development and customization
Keyboardio Model 01 docs
- Keyboardio Model 01 Introduction
- Flashing a new bootloader
- Default Model 01 QWERTY Layout
- Common Alternate Layouts
- Hardware Test Mode
Community