1

I work with a significant amount of Arduinos (about 2000 a batch), and they all need firmware loaded on them via usb. I've already written programs to speed up this process, but I can't find a way to stop the program from rewriting the firmware to the Arduino Leonardo, because the only identifier seems to be the com port number. To work around this I've pressed a key every time I plug in new Arduinos but this is slow. I want to keep the program in a loop so I don't need to press a key every time or re run the program. If I get this to work then I can just plug in as many as possible and keep switching them out when they're done uploading, because my program can already upload to multiple devices.

I've already learned of avrdude's -U parameter which allows a programmer to read or verify the device's files which could potentially work to check for loaded files, but it requires bootloading the Leonardo, which defeats the purpose at least in terms of efficiency (takes .5 seconds for the Leonardo to go into bootloader mode). I've also thought of connecting to the devices with the firmware through its package, but the timeout for devices that don't have the firmware loaded yet is around 5 seconds.

Is there anyway to check for previously loaded firmware on a Arduino Leonardo, without the use of the bootloader? Any help would be greatly appreciated.

(Just for your information, I'm writing this program in Python using the Pyserial and Subprocess packages)

Eric Hedengren
  • 455
  • 1
  • 5
  • 19
  • Or you could get a real programmer, even a gang programmer, and quit fiddling with bootloaders. If you have real production runs, it's easy also to contract this out. – TomServo Jun 16 '21 at 23:45
  • But I'm not sure others could do a better job, thanks for the idea though. I'm pretty experienced with programming and I've looked at a lot of options. – Eric Hedengren Jun 20 '21 at 19:32

1 Answers1

0

There is the diagnose() function in the tclab package as shown in the documentation. A simple function is likely what you already tried but not faster than your prototype.

def check_firmware():
    import tclab
    import time
    try:
        start = time.time()
        lab = tclab.TCLab()
        print(lab.version)
        Q1w=lab.Q1(1); Q1r=lab.Q1()
        lab.close()
        if Q1w==Q1r:
            print('Firmware loaded')
        else:
            print('Firmware not loaded')
        print('Time: ',time.time()-start)
        return True
    except:
        print('Firmware not loaded')
        print('Time: ',time.time()-start)
        return False

print(check_firmware())

Here is some timing with firmware loaded:

TCLab version 0.4.9
Arduino Leonardo connected on port COM4 at 115200 baud.
TCLab Firmware 2.0.1 Arduino Leonardo/Micro.
TCLab Firmware 2.0.1 Arduino Leonardo/Micro
TCLab disconnected successfully.
Firmware loaded
Time:  4.687340974807739
True

Here is the timing with no firmware loaded:

TCLab version 0.4.9
Firmware not loaded
Time:  8.068862199783325
False

The function returns a True or False based on whether it detects the firmware.

John Hedengren
  • 12,068
  • 1
  • 21
  • 25