Having run into a number of problems with sketches not working the way they should, I have a simple (but large) example running on an Arduino Uno (and Nano) which I'm programming in the standard way via the serial port. Everything looks ok in the IDE, including "COM10 (Arduino Uno)" under the ports menu.
With the v1 IDE, everything works and the output ends with:
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x79
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x79
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x79
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x79
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x79
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x79
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x79
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x79
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x79
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x79
Failed uploading: uploading error: exit status 1
If I then try programming it via the ISP (USBTinyISP) I get:
avrdude: ser_open(): can't open device "\\.\COM10": The system cannot find the file specified.
Failed uploading: uploading error: exit status 1
Going back to the v1 IDE, it no longer works but I can fix it by burning the bootloader.
I can also program it in the v2 IDE using the ISP if I first burn a new bootloader. (This seems strange as I thought the whole point of using the ISP was it didn't need the bootloader. Maybe some fuses are being set differently?)
Avrdude works fine from the command line and all the fuses look to be ok. I have the standard 0xff/0xde/0x05.
I'm thinking the cause is a problem with the v2 IDE. I've had many problems with it in the past and have generally been using the v1 IDE but the v1 IDE is often so slow it's unusable. Possibly this a sketch that's too large and is corrupting the bootloader, but then I also had a case where the v2 IDE wouldn't burn the bootloader (complaining about a serial port again) and I had to go back to the v1 IDE to get it working.
Any ideas how to reliably upload sketches with the v2 IDE?
Let's focus exclusively on the problem with the Uno board for now. If we try to troubleshoot two boards at once it is bound to result in confusion and wasted time. Once the work for the Uno has been concluded we can the switch to the Nano.
Serial ports are not used at all when uploading via a USBtinyISP programmer, so this error indicates that you performed a normal "Upload" operation instead of the "Upload Using Programmer" operation we must use in order to program a board using an ISP programmer.
What procedure did you use when you attempted this? When using Arduino IDE 1.x, there are three different ways to trigger an "Upload Using Programmer" operation with an Uno board:
Select Sketch > Upload using Programmer" from the Arduino IDE menus.
Press the Ctrl+Shift+U keyboard shortcut.
Hold the Shift key while clicking the "Upload" button on the Arduino IDE toolbar.
When using Arduino IDE 2.x, only the first two triggers are available. If you attempt to trigger an "Upload Using Programmer" operation in Arduino IDE 2.x via the third, it just does a normal "Upload" operation just the same as if you didn't hold the Shift key.
Does this mean that you were able to solve the problem by simply burning the bootloader once?
Or are you saying that you must burn the bootloader prior to every upload?
I'm going to ask you to provide the full verbose output from a failed "Burn Bootloader" operation using Arduino IDE 2.x.
This procedure is not intended to solve the problem. The purpose is to gather more information.
Please do this:
Select File > Preferences... from the Arduino IDE menus.
The "Preferences" dialog will open.
Check the box next to Show verbose output during: ☐ upload in the "Preferences" dialog. ⓘ This preference applies to "Burn Bootloader" operations in addition to uploads.
Click the "OK" button.
The "Preferences" dialog will close.
Attempt a "Burn Bootloader" operation, just the same as you did before.
Wait for the "Burn Bootloader" operation to fail.
You will see a "Error while burning the bootloader: ..." notification at the bottom right corner of the Arduino IDE window. Click the "COPY ERROR MESSAGES" button in that notification.
Open a forum reply here by clicking the "Reply" button.
Click the <CODE/> icon on the post composer toolbar.
This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
Press the Ctrl+V keyboard shortcut (Command+V for macOS users).
This will paste the error output from the upload into the code block.
Move the cursor outside of the code block markup before you add any additional text to your reply.
I assure you I didn't. I'm very used to using the ISP to program Arduinos. Most of the projects use standalone AVRs (ATMega16, ATTiny2313 etc.) so there's no choice but to use ISP.
I've just tried it again. Nothing plugged into the USB port. USBTinyISP on the ISP connector. The error is: 'Port monitor error command 'open' failed. Serial port not found. Coult not connect to COM10 port'.
I don't have the serial monitor open. Looking at the error, maybe it thinks I'm trying to monitor the serial port while running the sketch. Also the sketch isn't working (first thing it should do is flash the onboard LED) so I concluded the upload failed.
For the ISP, I used the menu. I didn't know about the shortcuts.
Just tried it again and it appears I can upload multiple times. To be clear I did:
Tried serial upload with v2. Failed
Burn bootloader with v1
Upload with v2 serial. Worked.
Upload with v2 serial. Worked.
One issue that's just occured to me. There's a heap allocation in the sketch. Only very small but is there any protection against overwriting the bootloader? Also I didn't check if v1 and v2 are using the same compiler versions. That might explain why there are differences in behaviour.
Interesting. So it does actually succeed in burning the bootloader. It ends with
However, the 'burning bootloader' notification continues to indicate it is still uploading. Eventually it ends with 'Port monitor error" command 'open' failed. Serial port not found. Could not connect to COM10 serial port.
As I said, I havent't got the serial monitor running. I generally use putty anyway as it seems to can't reliably copy the output and I couldn't find a way to save the output.
I've switched to VSCode/PlatformIO for now. I would like to find a way to use the Arduino v2 IDE though as it's more convenient for smaller projects.
I think you do have it open and just don't realize it. The design of the Arduino IDE 2.x Serial Monitor is significantly different from Arduino IDE 1.x. The Arduino IDE 2.x Serial Monitor is a view which is displayed in the bottom panel of the IDE window (by default). The bottom panel is also used as a container for other views such as the "Output" view. You can have multiple views open at the same time. The visibility of the views are controlled by tabs at the top of the bottom panel. So if you have the "Output" view selected in the bottom panel, the "Serial Monitor" view will still be open, even when it is not visible. Serial Monitor will try to connect to the serial port you have selected from the Tools > Port menu after you upload. If the board isn't connected to the computer then it is expected that you will get this "Port monitor error command 'open' failed" error.
You can close Serial Monitor by clicking the X icon on its tab:
OK I'm willing to accept that. I do find it astonishing the developers think it's acceptable to have a UI where you can open the monitor without any indication and it can then start issuing error messages when you burn the bootloader. Arduino is supposed to be suitable for novices after all. Personally I found it easier to learn PlatformIO and that's not a simple IDE by any means.
Anyway, many thanks for your help. Much appreciated!