Production tools

For a while, to mass produce some of the products I have programmed using Arduino, I have simply used Arduino. This means each time I need to program a chip, I open the INO file and "Upload" using Arduino, then fuse using the command line. Is there a way to work with a binary file already compiled and simply upload and fuse all at once from either the command line, some utility or within Arduino?

Once I have a release version of the software, I copy the hex file to a dedicated directory under the project.

I have a PowerShell script to use avrdude to program the arduino and set the fuses via a programmer and icsp.

Lastly, I also make the project files (ino, h, cpp) readonly; that's currently not part of the script.

sterretje:
Once I have a release version of the software, I copy the hex file to a dedicated directory under the project.
I have a PowerShell script to use avrdude to program the arduino and set the fuses via a programmer and icsp.
Lastly, I also make the project files (ino, h, cpp) readonly; that's currently not part of the script.

Is there a tutorial on this PowerShell/avrdude stuff? does it work with any programmer? I've been using USBASP programmers... I don't work with "arduino" boards, but I use the Arduino language and IDE to programm compatible AVR micros.

There is somewhere an avrdude pdf. Can't remember where I found it.

You can use powershell or an ordinary bat file. If I remember, I will post my crappy powershell script tomorrow. If I forget, you can kick this thread.

You can program multiple boards simultaneously. Just hook up the output from the programmer (Serial TX and RESET) to all boards and the input can connect to only one board.

This does carry a higher risk of errors on the boards that aren't being monitored by sending data back to the PC but it's a very cheap way of tripling your productivity.

Do this:

  • File > Preferences
  • Check the box next to "Show verbose output during: upload".
  • Click "OK".
  • Do an upload as you usually would for your production process.
  • After the upload finishes, examine the contents of the black console window at the bottom of the Arduino IDE window (you may need to scroll up to see it all). There you will find the avrdude command that the Arduino IDE generated for the upload. You can copy that command, modify it as you like, and run it from the command line.

Be aware that the .hex file generated by the Arduino IDE is stored in a temporary folder which will be deleted when the Arduino IDE is closed. So save it somewhere safe before exiting the Arduino IDE and update the avrdude command accordingly.

Perehama:
then fuse using the command line.

Do you mean that you're already using avrdude from the command line to set the fuses on the chips?

You can run multiple operations in a single avrdude command. avrdude will generally run them in the order they are found in the command. So you can create a hybrid avrdude command that sets fuses and uploads the .hex file in a single command.

Here is the documentation for the avrdude command line options:

Perehama:
does it work with any programmer? I've been using USBASP programmers... I don't work with "arduino" boards, but I use the Arduino language and IDE to programm compatible AVR micros.

Yes. The Arduino IDE is just running an avrdude command to upload so it's no different at all for you to run the same command from the command line. Anything you can do from the Arduino IDE with avrdude, you can do from the command line.

#
#   Uploading code for xxxx
#
#   Uses an stk500V2 type programmer using ICSP. Tested with a Pololu USB AVR Programmer v2.
#   Make sure the wires from the box header on the Pololu to the Nano/Uno are wired correctly!
#
#   This script will upload the code, clear the BOOTRST flag and set the lock bits.
#   Usage:
#       upload -comPort COMPORT -hexFile FILE
#
#   Notes:
#       hfuse for factory loaded Uno/Nano
#       Uno:  0xD6 arduino.org
#             0xDE piotr's clone
#       Nano: 0xDA
#

# note that Param must be the first line
Param (
    # com port to use
    [string] $comPort = "COM14",
    # the hex file to program with default value
    [string]$hexFile = "C:\Users\Wim Sturkenboom\Documents\Arduino\Projects\Piotr\mushroom_factory\WeGrowFungi.1.1\WeGrowFungi.ino.hex",
    # Arduino processor; only tested with 328P
    [string] $processor = "atmega328p"
)

# programmer to use
$programmer = "stk500V2"

########################
# Functions
########################

Function bye
{
Param($txt = "")
    if($txt -ne "")
    {
        Write-Host $txt
    }
    Write-Host "Press <enter>"
    Read-Host
    exit
}

Function getHighFuse
{
    Write-Host "Reading High fuse"
    $reply = & $avrDude -c $programmer -C $avrdudeConfig -p $processor -P $comPort -U hfuse:r:-:i

    $records = $reply -split " "
    if ($records.Length -ne 2)
    {
        bye "2 records expected"
    }
    if ($records[0].Length -ne 13)
    {
        bye "Incorrect record length"
    }
    $f = "0x" + $records[0].Substring(9, 2);

    return $f
}

Function setHighFuse
{
Param($fuse = "")
    if($fuse -eq "")
    {
        bye "idiot"
    }
    Write-Host "Writing High fuse"
    $write = "hfuse:w:{0}:m" -f $fuse
    & $avrDude -c $programmer -C $avrdudeConfig -p $processor -P $comPort -U $write
}

Function setLockBits
{
Param($fuse = "")
    if($fuse -eq "")
    {
        bye "idiot"
    }
    Write-Host "Writing lock bits"
    $write = "lock:w:{0}:m" -f $fuse
    & $avrDude -c $programmer -C $avrdudeConfig -p $processor -P $comPort -U $write
}

Function upload
{
    Write-Host "Uploading code"
    $write = "flash:w:{0}:i" -f $hexFile
    #Write-Host $write
    & $avrDude -c $programmer -C $avrdudeConfig -p $processor -P $comPort -U $write
}

Function readFlash
{
    Write-Host "Reading code"
    $write = "flash:r:protected.hex:i"
    & $avrDude -c $programmer -C $avrdudeConfig -p $processor -P $comPort -U $write
}

########################
# Main code
########################

Write-Host "PowerShell version: " $PSVersionTable.PSVersion

$avrdude = "C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avrdude"
$avrdudeConfig = "C:\Program Files (x86)\Arduino\hardware\tools\avr\etc\avrdude.conf"


Try
{
    #upload code
    upload

    # read high fuse
    $fuse = getHighFuse
    Write-Host -NoNewline "Current High fuse = "
    Write-Host $fuse

    # calculate new high fuse value
    $newFuse = $fuse -bor 0x01
    $nf = "0x{0:X2}" -f $newFuse
    Write-Host -NoNewline "New High fuse =     "
    Write-Host $nf
    
    # set new hfuse
    setHighFuse $nf

    # set lock bits
    setLockBits "0x00"
    # verify lock bits by reading back flash
    readFlash
    Write-Host "Please check the file protected.hex; it should only contain the end-of-file record."
}
Catch
{
    $ErrorMessage = $_.Exception.Message
    $FailedItem = $_.Exception.ItemName
    Write-Host $ErrorMessage
    exit
}


bye

The above is used with powershell version 3. Older or newer versions might error with syntax errors.

You might find this article on a standalone AVR chip programmer interesting, its mainly discussing programming the bootloader, but can be used for other code. A bit of work to set up, but fast if you are doing mass production.

To go along with that, a discussion on how to program the bootloader and a sketch at the same time using an ISP programmer:

http://forum.arduino.cc/index.php?topic=145124.0

pert:
Do you mean that you're already using avrdude from the command line to set the fuses on the chips?

Thank you all, especially pert. This was exactly what I wanted to know. Yes, I've been fusing the chips using avrdude from the command line. I never liked using a bootloader.

You're welcome. I'm glad if I was able to be of assistance. Enjoy!
Per