In-circuit or serial programming?

Hello, my first Arduino project is comming along nicely but I need some advice re in-circuit programming vs. serial programming for the next stage. I have used a Nano 3.0 for developing the prototype on breadboard. Now I want to move to a bare Atmega328 28-pin DIP on breadboard and then onto stripboard.

To program the Atmega, I understand I can use the Nano as an in-circuit programmer by using the ArduinoISP sketch (I have read the tutorial on this). However, may I have another option. The Atmega328 has a bootloader already on it. I have read the tutorial explaining that if I had an Uno, for example, I could temporarily remove the existing chip and use the board as a USB to serial adapter to program the new Atmega on the breadboard. Obviously, with the Nano, I can't remove the chip! I don't have any other USB to serial adaptor.

Two questions: 1. Is there any advantage to keeping the bootloader on the Atmega, or should I just use the Nano as an ISP and overwrite the bootloader? 2. If there is an advantage to keeping the Bootloader, what is it, and is there a way I can effectively just use the Nano as a USB to serial adaptor?

Thanks,

Paul

Using an Arduino as an ISP is slightly more hassle than just connection to it via a serial port, because you have to configure the IDE to support the ISP upload option for that board type, you also need to add the reset disable hardware to the Nano as well as connecting the ISP wires and you have to have the ISP sketch loaded on the Nano. Hence this is likely to be slightly harder to get working, and slightly more cumbersome to actually perform an upload, compared to using a serial connection. However, it's not a huge deal either way. The least effort solution would be to buy a USB-to-TTL-serial adapter - they're readily available and not expensive.

Thanks for the response Peter. Unfortunately, I'm only slightly less confused. Why do I need to "add the reset disable hardware to the Nano"? The tutorials I have read don't mention it, e.g. http://forums.4fips.com/viewtopic.php?f=3&t=1080.

Is there no way I can use the Nano as a USB to TTL Serial adaptor? Is there a sketch, a bit like the ArduinoISP sketch, for this?

PaulRB: Why do I need to "add the reset disable hardware to the Nano"?

You need to prevent the Nano from resetting when the serial port is opened at the start of the upload process. The usual way to do this is by connecting a capacitor between the reset pin and ground. If you don't prevent it from resetting then the uploader will talk to the Nano's bootloader instead of talking to the Arduino ISP sketch.

I haven't tried it, but I think that it's possible to hold the UNO in reset and connect the serial Rx and Tx pins directly to the serial Rx and Tx pins of the target board. However, since the UNO no longer has any way to reset the target board, you'd have to do that manually at the right time in the upload sequence, which might need a lot of practice and trial and error to get right. I have no idea whether that would work for a Nano either.

Using an Arduino as ISP is much more consistent once you have got it working.

A USB-to-TTL-serial adapter still seems by far the easiest option.

I've been using the Atmel JTAGICE to program from Arduino, and it is not too complicated though it does add steps. I did it by (This is from memory, so there may be an error): 1) Writing and compiling code in Arduino 2) Going to the directory where the code compiled (It changes often and is in your temporary files), and copied out the .hex and .eep files to someplace I knew where it was. It will be named something random-looking but it will be the only appropriate file. 3) Opened up Atmel Studio and went to the programmer software 4) Connected to the programmer using the software and selected my .hex file to program.

This adds a lot more steps to updating code, but requires less hardware, since you can connect directly to the device with the programmer using 6 pins (Listed somewhere on Atmel's Website). The $100 programmer however is relatively expensive compared to a $5 or less single chip on the board. But it could be much simpler than setting up the Bootloader. However, once you use the ISP, then you have to reprogram the bootloader to use it again.

PeterH: A USB-to-TTL-serial adapter still seems by far the easiest option.

Thanks again Peter. Its just that its another piece of kit to deal with. And although they are cheap, they don't cost much less than a replica Nano.

But wait... I just found this: I think its still in development, and also requires disabling the reset pin, but may be what I was asking about:

http://playground.arduino.cc//Thruload/Thruload

also requires disabling the reset pin

@Paul,

The 1st Arduino (Nano in your case) is running the ArduinoISP sketch and if it reset, it would intercept the download from the PC and reprogram the Nano. What we want is to keep the Nano in the ISP program so that it can program the downstream 328, t85, etc. In the formal ATmel world, dedicated hardware is provided for this task: www.atmel.com/Images/doc0943.pdf

Here is my take on the bootloader: if you are using a socket and can easily remove the uC, then you get a weebit of flash memory (2-4)K back for your use. If it would be necessary to sweat to remove the chip, then either bring out Rx, Tx, and Gnd (Reset must be accessible) to a connector AND use a bootloader OR bring out all the ISP connections to a connector... I often glue the female header in the battery compartment. Since you are doing a rather thorough Development life-cycle, you may feel confident in not using a bootloader: I rarely use 'em myself after the breadboard cycle (you and I are using the same approach.)

And, with a bootloader, you could bypass the USB approach completely and use an RS232'ish approach much like the PICAXE.... similar resistor values. It is the same concept; however, I have not tried this personally. I think this link will provide you a simple answer: http://blog.solutions-cubed.com/programming-the-arduino-uno-with-a-serial-port/

As I work often with naked 328 and tiny85, I invested in this: http://www.adafruit.com/products/462 and modified it with jumpers to work with either the 28 pin or 8 pin uC. I probably would just build my own now that I am more confident with the homebrew 'duinos and ZIF sockets are really nice. http://www.flickr.com/photos/77727388@N06/7119371109/

  • Ray

Thanks for the link - it looks like just the sort of thing I want - I have been making enquiries in another Topic http://forum.arduino.cc/index.php?topic=174422.0 but have got no solution yet.

...R

PaulRB: But wait... I just found this: I think its still in development, and also requires disabling the reset pin, but may be what I was asking about:

http://playground.arduino.cc//Thruload/Thruload

IMHO...

whatever pins you have access to will be the route you take..

things to keep in mind..

If you upload through ICSP (overwrite bootloader).. *boots faster *gives more space *you will ALWAYS have to upload this way.. even for a quick sketch/code change.. as there is NO bootloader looking/waiting for sketch uploads

If you upload through SERIAL, you just need to connect RX/TX/GND/V++/DTR (or press reset button if available)

I suggest getting a cheap USB TTL to SERIAL cable:

http://www.ebay.com/itm/USB-2-0-to-TTL-UART-6PIN-CP2102-Module-Serial-Converter-/390618992129?pt=LH_DefaultDomain_0&hash=item5af2b4ce01

I use this one.. works great! I have never looked back!

I use it ALL the time.. no fuss!

simple connect to pins noted above (RX/TX/GND/V++/DTR) and use Arduino IDE and hit upload button (after selecting COM port and board type of course)

I have also done the other way (through ICSP using my Arduino board as programmer) when I came across a board/project that had NO ICSP headers broken out.. and the chip was blank (no bootloader).. I had to FLASH CHIP WITH BOOTLOADER so I could set fuses correctly (tell it to use internal 8MHz clock and +3.3v).... so I also just uploaded the sketch that way too (to save time for myself)

Once you have the steps outined in front of you.. I dont think either way is more difficult.. so whatever fits your needs/project..

Along the lines of what Peter said, if you remove the UNO chip from its socket, then you can jumper all 3 of Rx, Tx, and Reset to a secondary board, and use the UNO board's USB port for uploading.

Thanks all, things are becoming clearer...

One thing I still don't understand is why, when using ArduinoISP, the Arduino IDE sends the reset signal at all? Surely it should not send the reset signal itself, but rely on the Arduino playing the part of the ISP to send the reset signal to the Arduino/AVR being programmed.

@oric_dan: I don't have an Uno, I have a Nano 3.0, so can't remove the chip!

@Robin2: I know how you feel. Ray and I know a forum that puts this one to shame sometimes in terms of the speed, quality and friendliness of the help you receive. Unfortunately, it is not an Arduino forum, and they don't like it if you talk too much about Arduino!

Here's a video of my project running, I'm sure you're all familiar with the subject:

http://www.youtube.com/watch?v=W8sSmD8JJ44&feature=player_detailpage

Why not just use Nick Gammon’s arduino as ISP?
You load a sketch into an Arduino, it then programs your destination board, just like any standalone ISP board does.
http://www.gammon.com.au/forum/?id=11635

CrossRoads: Why not just use Nick Gammon's arduino as ISP? You load a sketch into an Arduino, it then programs your destination board, just like any standalone ISP board does. http://www.gammon.com.au/forum/?id=11635

Thanks CrossRoads, forgive my ignorance, how it that different/better than the regular ArduinoISP sketch?

No messing around disabling the reset signal.

Now I want to move to a bare Atmega328 28-pin DIP on breadboard and then onto stripboard.

Also, if you're gonna play a lot with 328s on stripboards, it might pay to buy at least one UNO board for development work.

CrossRoads:
No messing around disabling the reset signal.

Thanks again CrossRoads, but there may be a problem. I use Ubuntu 13.04 on my PC. Is there a way to make Nick’s technique work with Linux?

Paul

No idea, am not a Linux guy. You could PM Nick and ask him.

CrossRoads: No idea, am not a Linux guy. You could PM Nick and ask him.

OK, thanks.

I have had another idea: would this work?

Could I simply connect the Nano and the Atmega328 DIP up in parrallel (Rx, Tx, Gnd, +5V, RST) and then simultaneously download the same program into both? After all, it is the same chip in both cases and they both have 16MHz crystal oscillators, so they should stay in-step through the programming cycle. I could put 100R between the Tx pins to protect against shorts, or just not connect the Tx pin on the Atmega.

I'm not sure that would work. If there is any difference in response at all then comm's would get messed up. Why not just load the Nano up with Nick's bootloader sketch, and let it program the 2nd design?

CrossRoads: I'm not sure that would work. If there is any difference in response at all then comm's would get messed up. Why not just load the Nano up with Nick's bootloader sketch, and let it program the 2nd design?

Well, browsing Nick's site, he is clearly not anti-linux, so I guess if a linux version of the MUSHclient was available he would advertise the fact.

Even if it were available, I would be facing the complexity of installing a software package intended for something related to playing Dungeons & Dragons, to allow me to program an AVR??? Now I understand "reset prevention hardware" is just a cap or a few resistors, that now sounds like the simpler of the two, and more "mainstream".

So, genuinely and sincerely, thanks again for the suggestion, CrossRoads, and I will remember it for the future when I get more experienced.

For now, I think I will give my parallel programming idea a little try, not connecting the Tx line on the Atmega so as not to mess up the comms. And if that doesn't work, ArduinoISP and disabling the reset on the nano.