Electronic – arduino – What are some reasons the atmega32u4 loses program when disconnected from power

arduinoatmegaatmelembeddedflash

I have two different boards running the same code with the same chip (ATMega32u4).

Problem Summary

THe problem is that the 2nd board seems to lose the program that has been flashed to the chip if it loses power.

Both of these boards have mini USB connectors and get power from USB and both run at 5v.

First (Working) Board

The first board is an "official" SparkFun Pro Micro.
sparkfun pro micro

Second (Failing) Board

The second board is a knock-off of that board which I bought on amazon. You can see the details for that board at:
Pro Micro knock-off board at amazon

NOTE: I'm not expecting anyone to examine those boards perfectly and tell me the exact reason why. I'm just adding that info in case someone notices something completely different that would indicate the problem.

Programming the Boards

When I program the boards I set the Arduino IDE to the Pro Micro board at 5v and 16Mhz and the program flashing works equally well on both boards. I then run the knock-off board and it works perfectly. It's a little program that receives data from bluetooth and displays the data elsewhere.

Loss of Power, Loss of Flashed Program

On the first board, I programmed it once weeks ago and it works after being powered off for days. Obviously, that's the way it is supposed to work.

On the second board, if it loses power at all it seems to lose the program.

Common Things To Check?

I'm just wondering if there are some common things I can check to determine why the program seems to be lost.

Are there any obvious things that I'm just missing? Is it possible the manufacturer hasn't wired something up properly which would cause this — I mean is this common problem with board manufacturing? I have 5 of these knock-off boards and have tested two so far and both seem to have the problem.

Any help is greatly appreciated.

Edit: Additional Info

I found the following information in a review on Amazon:

Like some other reviewers, my Pro Micro seemed to be losing the sketch
when disconnected from power. However, I've now figured out that the
Pro Micro isn't actually losing the sketch, there is a different
problem altogether. When the Pro Micro is reconnected to power, for
some reason the bootloader isn't running the sketch. If you then do a
soft-reset by connecting the RST pin to ground, upon reset the
bootloader starts running the sketch successfully.

So the issue can be worked around by wiring a button to the RST pin
and hitting the button every time you plug in the Pro Micro so that it
will reset and run the sketch. It's annoying that the issue exists,
but at least it's workable.

  1. Can anyone explain this phenomena?
  2. Might there be another workaround that is an automated solution– versus pushing a button each time?

Best Answer

Can anyone explain this phenomena?

Yes, the bootloader installed simply waits for a new sketch indefinitely, without timing out and entering the existing one after a certain period.

Might there be another workaround that is an automated solution-- versus pushing a button each time?

Install a new bootloader. I have a sketch described on my page about burning bootloaders which installs the Leonardo bootloader. I think the Pro Micro bootloader is similar or identical (it is the same chip after all).

You just need a second board (your other Micro would do) to use for the programming. Wiring for a Leonardo is described on my page - however see below for the Micro. The code is at Arduino sketches on GitHub - in particular in the "Atmega_Board_Programmer" directory.

You need to connect together the two boards as follows:

SCK  <--> SCK  (pin labelled 15 on the Pro Micro board) *
MISO <--> MISO (pin labelled 14 on the Pro Micro board)
MOSI <--> MOSI (pin labelled 16 on the Pro Micro board)
VCC  <--> VCC
Gnd  <--> Gnd
D10  <--> Reset (pin labelled 10 on the programming board to Reset on the
                 board to be programmed)

* As far as I can tell from your photo and the schematic

Pro Micro board

Possibly (probably) after installing the bootloader the board will identify itself to your PC as a Leonardo and not a Micro, but that doesn't matter since it is the same underlying chip.

Related Topic