Prevent Mega32u4 based Arduino resetting and/or uploading

Wow, my first question - please be gentle! :slight_smile:

I have a Mega32u4-based Arduino board which has a completely different way of uploading / resetting when compared to the UNO. It relies on a 1200 baud burst to reset it, which then presents a different virtual USB port to Windows which is used for the uploading process. So far, so complicated!

Anyway, it all works fine (for the most part) but now I want to PREVENT any code being uploaded (or the board resetting) when I'm playing about with the IDE with OTHER Arduino boards, as the code is final (ish) and it's plugged into my Windows PC as a keyboard emulator and being actively used.

The problem is that it's all too easy (go on, ask me how I know this) to accidentally overwrite the code on THIS board rather than the intended development board, either through carelessness in checking the COM ports or the IDE getting its knickers in a twist with available COM ports.

So, how to prevent code being uploaded - but not permanently, I will want to upload code some time in the future but only when I deliberately do something like removing a link / resistor / capacitor (which is easy to do just by unplugging the Arduino board from its circuit motherboard).

I have tried resistors / links / capacitors across the Rx, Tx, RST but nothing has worked - code still gets uploaded. I think I can probably set a fuse in the board via software but that's a bit too permanent for me as I don't have an ICSP port on this board (it's some sort of Arduino Micro clone) to then reverse this.

There was a suggestion of setting the Rx pin HIGH in code (but it also checks another pin to see whether it should stop doing this so I can upload again) but having set the pin both HIGH and LOW via a resistor / link without success I'm thinking this might not work either?

Anyone have any working examples or other ideas? All answers gratefully received. :wink:

Try this:

  • Open Device Manager
  • Expand Ports
  • Double click on the serial port of your Micro
  • Open the Driver tab
  • Click Disable
  • Click OK

I recently did the same thing(except in an overly complex manner because I didn't realize you could do it this way) for the reasons you state and it has been nice not to have an extra serial port I never use cluttering up my Port menu in the IDE.

Well top marks Pert, for a bit of lateral thinking! Instead of faffing around with the Arduino, just knobble the port it's connected to. I hadn't considered this as I had somehow related the USB port with the HID enumeration (wrongly).

OK, just tried this and of course it works - Arduino IDE can no longer 'see' that port.

Question: as long as I keep the Arduino plugged into the same USB socket (via a hub I must mention) it will *always and for a day *keep that same port? I just have a niggle as I have seen port numbers move all over the place with some boards, from port 5 all the way up to 17!

It's no biggie to check now and again that it has not moved (my PC remains running 24 x 7) and disable whichever port its currently on, but I wouldn't want it to suddenly move ports on a whim.

Aside: Windows 7 insists you reboot after disabling the USB port but Windows 10 (the PC it's normally on), does not, thank goodness.

Thanks for the suggestion, it will save me loads of time as I will no longer have to try and 'unbrick' the Micro having had code for a Nano or Uno or something uploaded to it by mistake (took me over an hour yesterday - it was being seen as a Yun by Windows, which I don't even have, bizarre).

Ralph_S_Bacon:
Question: as long as I keep the Arduino plugged into the same USB socket (via a hub I must mention) it will always and for a day keep that same port? I just have a niggle as I have seen port numbers move all over the place with some boards, from port 5 all the way up to 17!

I have little experience with the disabled port because I figured out that it could be done right before my post. I did a couple unplug/plugs of the Micro, restarted my computer and it stayed disabled but that's the extent of my testing so far. Hopefully while the port is disabled it won't change. If it does still change there is a tip I saw on the forum for how to fix that. Whenever it changes to a different port, do this:

  • Open Device Manager
  • Expand Ports
  • Double click the port the Micro is on
  • Port Settings tab > Advanced... > COM Port Number > select the previous port the Micro was on

Ever since doing that my Micro always stays on the same port.

Sounds a pragmatic approach and so far (since I read your post) it's remained resolutely on Port 6. We shall see if it's still there over the next few days (or after a reboot which doesn't happen often on this PC).

I've just recorded the intro to a new YouTube video for my channel lamenting this problem and I've indicated the solution suggested by you (without naming names, not sure that's appropriate but if you want proper attribution let me know and I'll add it to the video at the appropriate place!).

Thanks again, my first question has been answered, I feel like a noob!

I don't care either way about the attribution. I've benefited a lot from the contributions of others in this community and I'm just glad when I can find an opportunity to give back. In this case I've actually benefited too because I was inspired by your post to think of a way to disable the port of the Arduino that appears to be better and easier than how I did it last week(rigging up a programmer to my soldered down to a circuit board Pro Micro using precariously attached jumper wires and then changing the PID so that it's no longer recognized by the driver). So if you find any problems with this approach please update here so I know whether it's worth changing the PID on mine back to the correct value.

Ralph_S_Bacon:
Anyone have any working examples or other ideas?

The RX and TX pins normally don't get used at all on a Leonardo-type board (32U4-based board with Caterina bootloader) for uploading, and the reset comes from the code not the reset pin. So, you can't do stuff to those pins to prevent uploading. What you can do is make the bootloader or core unique for that board, so it won't upload as if it was a Leonardo. Other ideas not yet mentioned:

  1. You could use the DFU bootloader instead of Caterina, and you could then upload a new hex file using DFU
  2. You could use Optiboot instead of Caterina, and in that case upload would be through the RX and TX pins using an FTDI adapter much in the same way you would program a Pro Mini.
  3. You could make a modified core for this board that listens for the "reset request" baud rate of something different from 1200, like maybe 300.

Ah yes, I sort of skirted around any solution that would require me to modify in any major way the actual board (given that it's a clone anyway, I'm guessing of a sparkfun Pro Micro as it does identify itself as such [sometimes] and as a Leonardo upon resetting).

But I like your #2 suggestion the best, about using a different bootloader so I can then forget about USB programming and just using an FTDI serial adapter - which I'll keep on the backburner if this USB Port disabling turns out to be less then reliable.

Turns out I'm spoilt for choice (a good thing). But I'm amazed that many others don't have this issue too with their 32U4 boards plugged into the same PC that they are then programming other Arduinos with.

Thanks for the replies chaps ;D

The How-To for #2: http://www.instructables.com/id/How-to-upload-sketches-to-Pro-MicroLeonardo-via-se/