Arduino Uno – Programming With A Serial Port

arduino_rs232_hack_photo

I’m working on an Arduino clone.  The Arduino is essentially an ATMEGA328P development board with a bootloader pre-loaded.  There are a lot of custom macros built into the programming interface that make it really easy to use, and even easy to build some powerful applications.  Arduinos have taken off and can be found everywhere, doing everything.   The hardware and software is open-source which seems to have really contributed to the product’s success.

Anyway, I was looking over the schematic of the Arduino Uno.  I noticed the programming interface, which is USB, made use of another Atmel microcontroller (the ATMEGA16U2).  This is the small surface mount IC in the upper left corner of the picture above.  In fact most of the components in the upper left of the board are associated with programming.  I figure these parts probably cost in the area of $4-$6 to add to the board, which is likely 1/3 of the entire manufacturing cost.

It seemed redundant and costly to have two microcontrollers on the board.  Especially since the bootloader appears to be a simple serial interface.  I suspect that I understand why the Arduino Uno people went the two microcontroller route.  First, new computers don’t have a serial port anymore.  So a USB interface is just easier for the customer.  Second, the cost of the microcontroller and surrounding components is about the same as a dedicated USB-232 converter IC.  It might even be less expensive, although there would be some NRE (non-recurring engineering) costs.

This all left me wondering if I could replace all of the USB to conversion on the board and just use an RS232 to logic level converter chip to program the Arduino Uno with my PC.  If so, then the programming interface circuitry drops to about $0.80 in small quantities.

It turned out that this was pretty easy to do.  So here’s what I did.

1.  Connect jumper wires to pins 2,3,4, and 5 of a DB9-F serial port connector.  Pin two is data from the PC, pin 3 is data to the PC, pin 4 is the DTR signal used to reset the Arduino, and pin 5 is ground.  Ground should be common to all circuits.

2.  Remove RN4 and C5 which connect the ATMEGA16U2 (programmer) to the ATMEGA328P (Arduino).  Keep these parts so you can put them back on later.  Also, since RN4 is a resistor array removing it also prevents the green “ON” LED from lighting.  You could solder a 1K ohm resistor across the  2 pads closest to the LED if you wanted it to light up when power is applied.

arduino_rs232_hack_schematic

3.  Connect an RS232 converter IC (I used a MAX202) between the DB9-F and the Arduino RX, TX, and Ground connections.  Connect a 0.1uF capacitor between the DTR logic level output the RS232 IC and the Reset pin on the Arduino.  I actually used a 0.01uF cap, since it was what I had handy, and it worked as well.

arduino_rs232_hack_max202

With those changes I was able to program the Arduino Uno with a serial port and no USB.  But the real benefit was stripping quite a bit of the cost off the board at the expense of ease of use.  Now as I proceed with the Arduino clone design I can just ignore a big chunk of hardware found in the open source schematic.

One last note.  These connections preclude the use of the hardware UART on the Arduino being shared between the programming interface and other circuits.  But the RS232 IC connections could be isolated by using 1K resistors, which is exactly what RN4C and D do in the original schematic.

Comments

  1. shan salman says:

    Do we need rs232 to communicate withother microcontrollers or small serial enabled devices? or is it just for the pc?

    • Jerry Lopez says:

      Shan, if you want to communicate between two micro’s then you would either connect them directly
      at the digital (TTL) level, TX – RX and RX-TX from device to device. This can only work the micros are
      close togather and usually not practable.
      The ‘normal’ manner is to use the RS-232 type devices at each device as shown in the hack.
      If I program a UNO to spit out seria; data, then I use the pin(s) 0 and 1 on the Arduino board and power the
      Arduino from a walwart PS and the USB connector is not used in that case.

  2. The Arduino Uno comes with a second microcontroller that converts USB signals to logic level serial data. The serial data is used to program a bootloader in the main microcontroller on the Arduino Uno. If your computer has a USB port you don’t need to do any of this.

    This hack shown here bypasses the USB to serial data conversion and the second microcontroller. Other Arduino products also use the serial only interface, and some Arduino products incorporate the USB conversion into the main microcontroller (no serial at all).

    The main reason I did this was to see how easy it was to remove the USB converting microcontroller from an Arduino-clone design.

  3. Jerry Lopez says:

    I too am interested in just using the serial port for Arduino UNO programming.
    I notice that the Arduino UNO seems to require DTR tied to the uC RESET pin (?).
    That must be a specific part of how the bootloader and Arduino communicate????
    Or , is that just for the normal serial I/O handshaking? I don’t think I have ever seen
    DTR controlling the uC reset pin.
    I was thinking that I could use a regular prototype board that already has the
    RS-232 Max232 type chip installed. Here I am thinking of using an Olimex 28 pin
    prototype PCBA.

    I always thought that a bootloader stored in the uC only needed serial data.
    Also, not sure how you would get the Arduino software to select the serial port to use.
    I am thinking now of using a Linux PC that has only USB port(s), but I also have a few USB-Serial
    adapters that I usually don’t have any issues when using with legacy serial devices.

    I hope to hear some clarification as your hack looks pretty weill documented.
    Just not sure about DTR – Reset.

    Thanks in advance.

  4. Jerry,

    It seems as though the Arduino Uno allows the bootloader to be enabled if you send specific commands just after a reset. This is pretty common in “safe” serial bootloader designs. I’ve designed some that wait few seconds on power-up and if the bootloader command isn’t received the program proceeds to its main loop. This prevents random serial commands from accidentally accessing the bootloader and reprogramming your micocontroller with junk.

    I assume that the DTR is being used to reset the Atmel microcontroller to give the programming device (computer) access to the serial bootloader just after a reset. The DTR signal is not commonly used to reset microcontrollers.

    You should also be able to use the reset button and programming software to manually enable/access the bootloader without the DTR connection. Just press reset, and then send the programming string from the PC. The down side is that you’ll probably have to try this a few times to get the timing straight.

    The Arduino software should recognize any enabled serial port. I’m pretty sure I used a USB to RS232 converter, and then an RS232 IC on a breadboard, since my laptop had no serial port.

    Lon

  5. Doesn’t work for me so far. It seems as if the Arduino Software wouldn’t send the DTR signal. If I send it manually with a terminal application, the Arduino is reset. Any ideas?

    • Lenny,

      It’s probably a timing issue. The Arduino needs to enter reset and then the programming interface should begin the programming process. If you used a different capacitor that could be the problem. What indicates that you have a problem, and are you using the Arduino programming environment.

      Lon

  6. Hi.. . . . I tried the same circuit and upladed the sketch of blink led but its not blinking but glowing continously. . . moreover its giving same output on all pins rather than only one provrammed for. . . I had already bootloaded it using arduino uno kit. . .it said bootloaded successfully
    Thanks

  7. Anuj,

    You might take a look at the DTR signal to verify that the device isn’t going into a continuous reset which might cause the I/o lines to do what you’re describing. Other than that the value capacitor might be something to look at. When I wrote this I think the Arduino programming environment was 1.0.2 and now it is at 1.0.5. It’s possible that they adjusted the timing in the software. I’ll try to dig out the Arduino I modified and see if I can do this again. Pretty busy though so I’m not sure exactly when I could do that.

    Lon

  8. Lon,

    Have you been able to verify of changing the IDE environment changes the DTR reset timing? I swear I got this working 6 months ago, but when I built this again, it does not work.

    • Hi Andrew,
      I haven’t had time to go back and look at this. I did add a USB-to-serial bootloader to one of our products that basically makes use of the same circuit. It’s on our Firstbot product and the schematic can be found application notes page (link to docs is at the page below)

      http://www.solutions-cubed.com/firstbot

      While this circuit uses a USB converter, everything associated with the TTL side of the interface would be the same as an RS232 application. You could also try to use the RS232 circuit with the Arduino Pro or Pro-Mini (Tools>Board in the IDE). That board works with the 1.05 IDE and it may be that there are timing differences established in the settings for different styles of boards.

      Last thing you could try would be to vary the cap value connected to DTR and see if you have any better luck.

      Lon

Speak Your Mind

*