Considering building a programmer with NANO

After coming to realize some of my NANO boards probably don't have a standard bootloader, I'm looking into the various bootloaders and programmers available. So I came across this article, about "Turning an Arduino into an AVR ISP programmer). Its interesting, especially being a hardcore DIY person.

https://playground.arduino.cc/Code/Programmer2

( I see you can turn a parallel port into a programmer too, but using an arduino seems a lot more portable, since few laptops even come with parallel ports anymore).

So I thought trying to compile the linked code to see if it would even compile might be a good start. My IDE is a little dated (1.8.3), but I do have 1.8.5 on at least one machine.

Anyway, that code won't compile without mods. All I've discovered wrong there so far is the use of the discontinued keyword 'BYTE' in a lot print statements, like this one...

void DebugLCD::println()
{
  this->print(254,BYTE);
  this->print(128+64,BYTE);
}

I've seen forum posts asking how to fix this with write functions, and there seem to be a lot of conflicting suggestions: write(254); ? write('254'); ? write((unsigned char)254); ? print(254,BIN);? ). Really, since the code is using outdated keywords, I figure maybe I should back up and ask some other questions before I try to "fix" it, like...

  • is it even possible to use this code to turn a NANO into a programmer?
  • is there a more recent version of this programmer code I should be looking at?
  • Possibly a stupid question, but I don't see any references to programming a new bootloader into an Atmega328 NANO (with any programmer). Maybe there are no newer bootloaders (like the Optiboot I've been hearing about) for the NANO?

I'm trying to research all this, but sometimes its good to just ask some questions before you just start spending time on a project!

I did it this way. I took a Seeeduino Uno (328p and CH340) and uploaded the Arduino ISP sketch from IDE examples. Then I connected all ICSP pins together except of reset. Reset pin of target goes to pin 10 on the programmer board. Then I selected Uno as board (to burn Optiboot to Nano), selected "Arduino as ISP" in Programmer menu and then "Burn bootloader". ready

Later I read that you must disable the autoreset on the programmer board. I did not and there was no problem. I think it was because Optiboot has very fast reset. Other possibility is that it was the CH340.

Later I used that Nano to burn Ariadne bootloader to Mega. Again without disabling autoreset.

Just use the official Arduino as ISP firmware sketch. I'm guessing it's better than that outdated sketch you found on the Playground. It's included in the Arduino IDE at File > Examples > 11.ArduinoISP.

I also haven't found it necessary to add the capacitor to disable auto-reset on the Arduino as ISP programmer.

I do really like being able to make a DIY ISP programmer and have all the firmware as an Arduino sketch. I built a dedicated Arduino as ISP from scratch as one of my first Arduino projects. But in the end I much prefer my USBasp programmer to my Arduino as ISP.

I have a breadboard with an Atmega 328 on it that can be programmed with a USB-TTL cable. I have some connections on the breadboard so I can plug in another Atmega 328 if I want to load a bootloader onto it. And I also use the board for programming ATtinys using ICSP.

It is also very convenient for Nick Gammon's diagnostic programs

I should probably re-build it onto a piece of stripboard, but I don't use it often enough.

...R

I offer a built up programmer, running Nick Gammon's sketch

http://www.crossroadsfencing.com/BobuinoRev17/

Select from 256 files to (00 to FF) to program from SD card to the target. Also set the fuses to allow bootloder to start up or not.

pert:
Just use the official Arduino as ISP firmware sketch. I'm guessing it's better than that outdated sketch you found on the Playground. It's included in the Arduino IDE at File > Examples > 11.ArduinoISP.

I also haven't found it necessary to add the capacitor to disable auto-reset on the Arduino as ISP programmer.

I do really like being able to make a DIY ISP programmer and have all the firmware as an Arduino sketch. I built a dedicated Arduino as ISP from scratch as one of my first Arduino projects. But in the end I much prefer my USBasp programmer to my Arduino as ISP.

So those USB asp programmers that sell for a lousy couple of bucks on ebay (plus the 10-pin to 6 pin adapter I guess) can be used to program my NANOs? I mean, I am a DIY guy, but its hard to get motivated when its that cheap and neatly done already. But I may go that "lazy" route, especially if another NANO board wouldn't make a very good programmer (not sure why, but I haven't seen anyone say they did it yet).

Not sure I understand about the capacitor. On the NANOs, there is a capacitor from the serial chip's DTR to reset, that you can remove to avoid auto-reset on serial events. That must be something different?

Thanks for all the alternatives folks. Sill not sure I have an answer to my first question though. If I can't use a NANO as a programmer, I do have an UNO (Rev 3) here. But I am curious if a NANO is up to the task, and code exists to implement it. If not, as @pert reminded me, it might be easier to just buy one of these?

From the perspective of Arduino as ISP programming, a Nano is just an oversized Uno.

Pert summed it up perfectly, just use the current software and be done with OR buy a $3 USBASP with the 6 pin adapter (as all AVR based Arduinos use the 6 pin isp arrangement). I use one of Chinese Usbasp’s with the translucent blue plastic cases, I think it cost all of $4.50. At those prices, it doesn’t make sense to repurpose a Uno or a whatever when you can have protected, small board that is easy to store and find.

Trying to get some old, unknown, unsupported code base working just because it’s says Nano is a double waste of time.

avr_fred:
From the perspective of Arduino as ISP programming, a Nano is just an oversized Uno.

Or did you mean the opposite? Uno takes the space of about 6 NANOs! :wink:

avr_fred:
Pert summed it up perfectly, just use the current software and be done with OR buy a $3 USBASP with the 6 pin adapter (as all AVR based Arduinos use the 6 pin isp arrangement). I use one of Chinese Usbasp’s with the translucent blue plastic cases, I think it cost all of $4.50. At those prices, it doesn’t make sense to repurpose a Uno or a whatever when you can have protected, small board that is easy to store and find.

Trying to get some old, unknown, unsupported code base working just because it’s says Nano is a double waste of time.

I definitely agree. And I had not realized dedicated ready-to-go programmers were that readily available, cheap, easy to use, readily supported... geeze... what more could I want? I'm very "late to the party" on all this arduino stuff, and have such a long history of having to re-invent every little wheel, I have to slap some sense into myself sometimes.

Now that you mention it, what is opposite of oversized? Undersized just doesn’t convey the same concept...

Having being away from the diy world of micros for about twenty years, I’m still speechless over the hardware that you can purchase from China for next to nothing, shipping included.

The 10 pin USBasp with the 10 to 6 pin adapter works fine. I prefer the 6 pin USBasp so I don't need the adapter because I never need a 10 pin programmer. The 6 pin version of the USBasp is a little more expensive than the 10 pin on eBay but once you get done paying for an adapter for the 10 pin the 6 pin is cheaper. Here's one:
https://www.ebay.com/itm/232327462892

You actually still get a chance to do some DIY on your USBasp if you like. The stock firmware on the USBasp is pretty good but it has one problem I've run into. If you upload a sketch to an ATmega2560 that has the Arduino Mega fuse configuration using the programmer it doesn't run. That's not a huge problem because most people will be uploading to the ATmega2560 using a bootloader (the stock firmware works fine for Burn Bootloader) and the fuse change is easy enough, but it bothered me. Now there is an updated firmware that fixes that bug and also makes some other improvements:

To update the firmware on your USBasp you need another ISP programmer. That could be an Arduino as ISP or another USBasp.

PeterPan321:
especially if another NANO board wouldn't make a very good programmer (not sure why, but I haven't seen anyone say they did it yet).

A Nano board will be a great Arduino as ISP programmer. You could make a custom cable that plugs into the ICSP header of the Nano and then has an extra wire going over to pin 10 (or whichever wire you want to use for the reset controller, you can configure it in the ArduinoISP sketch). Or if you're programming a lot of DIP package bare chips you could make a board that the Nano plugs into with a ZIF socket for programming chips and a cable for programming boards via their ICSP header.

PeterPan321:
Thanks for all the alternatives folks. Sill not sure I have an answer to my first question though. If I can't use a NANO as a programmer, I do have an UNO (Rev 3) here. But I am curious if a NANO is up to the task, and code exists to implement it. If not, as @pert reminded me, it might be easier to just buy one of these?

Didn't I write that I use the Nano to flash Mega?

avr_fred:
From the perspective of Arduino as ISP programming, a Nano is just an oversized UNO.

PeterPan321:
Or did you mean the opposite? UNO takes the space of about 6 NANOs! :wink:

He was joking!

PeterPan321:
But I am curious if a NANO is up to the task,

A Nano is the "workhorse" version of the UNO, the one used for real-world applications once you have had enough playing around. The UNO is essentially an experimental platform and "demonstrator" device.

The Nano has the extra analog-input-only pins A6 and A7. The only thing the UNO has that the Nano has not, is the second processor which may be reprogrammed for extra functionality, but very rarely is.

And that is only if we are talking about actual UNOs, because many knock-offs sold as "UNO"s are not UNOs at all, but variants of the earlier Duemilanove which are electrically entirely equivalent to the Nano (but with various USB adapter chips). In fact, if you use the "knock-offs" of both pseudo-UNOs and Nanos with the same USB chip (CH340), they are functionally identical.

In terms of the programming, UNOs and Nanos are identical if loaded with the same bootloader. (If loading using ICSP, they differ in the ID of the SMD versus DIL chip.)

Juraj:
Didn't I write I use the Nano to flash Mega?

It works fine for Burn Bootloader. The problem I mentioned only applies to Upload Using Programmer.

In the past I have bought some 40+ Nanos for various projects - they are small , cheap and work well .
You can load the UNO bootloader into them ( optiboot) which a lot don’t have , so you can use interrupts etc.
They will make a programmer as well as any UNO and for most applications are a better choice than the much bigger UNO.
I bought a cheap programmer off eBay ( USBtiny) to load bootloaders or for “direct “ programming .

Awesome information! besides coming "late to the party" as I mentioned, I also have become so amazed with all the things I can do with my NANO boards, that I barely bothered to look under the hood. Now I got interested because I've realized that one of the things I would like to do someday is make a custom change to to bootloader. So hey... that's a LOT of research I need to catch up on. Me-thinks I ought to start by getting/making a programmer, making sure I can program a new (existing) bootloader into a board, see if i can obtain an existing bootloader source, and get the same result compiling and programming that! Lots of baby steps! THEN I can examine the actual bootloader code (and probably start tearing my hair out at first, but... one step at a time).

Anyway, I'm going to try some things making a programmer with all your suggestions, but probably will opt for one of those neatly packaged Chin modules in the end.

Thanks folks! Got some traveling ahead of me in the coming weeks. probably good to forget techie stiff for a while. I'll be back, fer sure! :slight_smile:

bootloader source code is installed with IDE. linux path ~/arduino-1.8.6/hardware/arduino/avr/bootloaders/optiboot

I'd work off the latest optiboot code instead of the old version that comes with Arduino AVR Boards:

pert:
I'd work off the latest optiboot code instead of the old version that comes with Arduino AVR Boards:
GitHub - Optiboot/optiboot: Small and Fast Bootloader for Arduino and other Atmel AVR chips

Is the footprint much bigger? Some of my projects are already using a lot of flash space.

I bootload all my '328P projects as an UNO. Can set the board variant in boards.txt from 'standard' to 'eightanaloginputs' if you need to use A6, A7 as analog inputs.