Remove your Arduino’s external oscillator to gain a free pair of IO pins

2free-arduino-io-pins

[Mark] from SpikenzieLabs was wrapping up a project using an Arduino the other day and found himself in need of a few more I/O pins. He could have added extra circuitry to the project, but he decided to see if he could gain a few pins by removing a few components instead.

He put together one of his Minuino boards, but rather than installing the crystal and its associated capacitors, he added a couple of pin headers in their place. It’s well known that the internal clock on the chip is not as precise as a crystal, but [Mark’s] project was not that time sensitive, so he had no problem sacrificing the oscillator for a few extra pins.

With his new I/O pins in place, he merely needed to tell the ATmega chip which clock it should be using, and he was well on his way. While this might not be the best solution for all projects out there, if you are building something that values pincount over precision, this hack is for you.

Check out the video below to see [Mark’s] hack in action.

[via HackedGadgets]

Comments

  1. Felicitus says:

    Why didn’t he simply use a regular Atmel? They’re cheaper and can run the Arduino software anyways.

  2. CrashSerious says:

    This is a standard configuration. It just uses the internal oscillator. The downfall is it runs slower. ~8Mhz, if I recall correctly.

    • svofski says:

      Internal RC oscillator is specified up to 8MHz, but in reality it can be calibrated to run at up to 12MHz. V-USB has code that does this.

      HaD, please, work on your terminology. ATmega can be configured to run off an external clock, but it never was used here. The oscillator was and still is internal. He had originally an internal oscillator with external crystal. Then he switched the configuration to use the internal calibrated RC oscillator and removed the crystal, thus freeing 2 more pins for I/O. But crystal != oscillator. It’s only a part of it that defines frequency.

      Still breaking my head, since when this is news, but nevermind.

  3. macegr says:

    Heh, just the other day I scrounged some parts in the lab and built up one of those Minuino boards Mark gave me in New York. I actually didn’t have through-hole 16MHz crystal and had to pull one off another dead board…should have thought of this idea!

    As an aside…the PCB is crazy thick, feels so weird…

  4. Jeremy says:

    Does the arduino ide still work for loading code onto it? Aside from adjusting the clockspeed, I know that the internal oscillator isn’t recommended for serial communication because it can drift with temperature.

    • svofski says:

      Unless you’re stressing your chip with temperatures that change by dozens of degrees, RC oscillator is perfectly fine for serial comms. In fact, it’s more flexible. You may need to calibrate it.

    • jbiehler says:

      You also take a pretty big hit in clock accuracy by using the internal oscillator versus an external crystal or even a resonator. Thats what is nice about the Teesnys. Paul used a high quality crystal and the trace lengths are optimized for the crystal. This means a very stable oscillator and it shows in his frequency measurement sketch.

  5. Joe says:

    I do support inginuity, but at some point there comes a time when it is time to put down the arduino and pick up an actual amtel, pic or whatnot. Idk just my opinion.

  6. DrLuke says:

    If you implement a software-reset, you can also turn the reset pin into an IO pin.

    • Daid says:

      Not if you want to use the ISP feature. And I think you would also need a high voltage programmer to disable the reset pin function.

      • Jeremy says:

        No, you need a highvoltage programmer to *reenable* it.

      • NewCommentor1283 says:

        hehe! XD he’s right, its a catch 22 of AVR’s …

        its that way with several features of the device assuming you dont own a dev board with all programming methods in place.

        ICSP enable (if u own only ICSP programmer)
        JTAG enable (if u own only jtag programmer)
        clock-selection (if you dont own any crystals…lol)
        bootloader (if u dont own any programmers at all)

        plus the reset setting we are talking about!
        did i miss any catch 22’s ??? lol theres too many, oh wait, BOD if ur dev board is 3.3v with a 3.3or5 volt capable chip.

        BUT FEAR NOT!
        HackADay will help you sort it all out using search “unbrick AVR” and “unbrick” all your AVRs you have :)

        PPS: as for the chicken and egg situation of only HAVING one AVR, you can reverse engeneer the code and write x86 dos executable to use parallel port on old computer, er, i mean, port Arduino to x86, big project :P

        (ASSUMING U DONT HAVE LPT PORT:)
        or with the addition of a few logic chips, use a “spare” IDE cable as a parallel port instead and write windows 2k/xp code :) muuuuch better
        THAT you can search HAD for “IDE stk200″
        but make it more then 8 bits instead of 4 bits to mimic standard LPT port wirings. IDE is 16 bit.

  7. bio says:

    how nessary is the external crystal?

    this would make it so much simpler to shove arduinos in to circuits

    • Garbz says:

      Unnecessary.

      External oscillators are often required if you want to do software USB (and don’t want to overclock), use the fast capabilities of your chip (16MHz), need an accurate clock for rock solid high speed serial transfers, or are doing any sensitive timing applications (and this does not include building clocks where a RTC is often a better option).

      I’ve only really needed an external oscillator once. Plus using the internal oscillator, the clock div option, and a few other tricks you can get your power consumption down really low.

  8. lamer says:

    how will this affect 9600 serial communication?
    with temperature changes?

    /Lamer

    • Garbz says:

      It provides you the option to improve it. 9600 baud gives a 0.2% error rate with a 16MHz clock as provided on the board. The internal RC oscillator can be configured down to 7.3728MHz giving you a 0% error at at any standard board rate.

      It’s quite stable too.

  9. Brian says:

    I’m not quite sure what’s going´on here. You get featuret on HAD to drive a microcontroller without a crystal? wow, it swept me off my feet.

    • svofski says:

      That’s the effect of the cargo cult that Arduino is causing. People don’t know Atmel from AVR, Arduino from microcontroller, resonator from oscillator and now they have discovered fuse settings. Oh boy, what they will think of next!

  10. Kinda lame post, I guess everyone knew you can program a microcontroller in different ways and that they usually have internal oscillators too.

  11. Malikaii says:

    Not everyone knew that.

  12. Troy says:

    Good idea, however the video should have gone in to a little more “arduino” detail here.

    How do I set the fuses using the Ardiuino IDE, etc.

    How do I reconfigure the IDE so that I can use these additional two pins.

    • Daid says:

      “How do I set the fuses using the Ardiuino IDE, etc.” You can’t. Arduino is strictly bootloader, and a bootloader cannot change fuses.
      “How do I reconfigure the IDE so that I can use these additional two pins.” The same way you SHOULD use the other pins. With the correct registers.

      • Troy says:

        I don’t think this is entirely correct.

        “You can’t”
        Last time I used the burn boot loader option in the IDE the fuses were also set. I understand they are referred to from the board.txt file and set. Something here would just need to be modified depending on the chip used.

        “Arduino is strictly bootloader”
        There is a lot more to Arduino than the bootloader. Libraries, IDE, etc.

        “the same way you SHOULD use the other pins. With the correct registers.”
        Isnt the whole point of the arduino ide/libraries to not have to use the port registers? Otherwise i’d just program straight avr-gcc.

  13. Brad Goodman says:

    This did not work for me. I was able to upload the bootloader, but when I then went to upload a sketch to the chip via serial, the program always failed.

    What I did do that finally *worked* was as follows:

    I built a new version of the Optiboot, which is set to 8MHz OSC and 57600 baud. You can download it here: https://s3.amazonaws.com/s3.bradgoodman.com/optiboot_atmega8-16-noxtal.hex

    I added this board-type to the (aforementioned) boards.txt file with the following lines:

    opti8-bkg.name=Arduino Optiboot-Atmega8-16-BKGnoxtal
    opti8-bkg.upload.protocol=arduino
    opti8-bkg.upload.maximum_size=7680
    opti8-bkg.upload.speed=57600
    opti8-bkg.bootloader.low_fuses=0xa4
    opti8-bkg.bootloader.high_fuses=0xcc
    opti8-bkg.bootloader.path=optiboot
    opti8-bkg.bootloader.file=optiboot_atmega8-16-noxtal.hex
    opti8-bkg.bootloader.unlock_bits=0x3F
    opti8-bkg.bootloader.lock_bits=0x0F
    opti8-bkg.build.mcu=atmega8
    opti8-bkg.build.f_cpu=8000000L
    opti8-bkg.build.core=arduino
    opti8-bkg.build.variant=standar

    The only modifications here are the “upload speed”, “f_cpu” and “low fuses”. In this configration, place the firmware file in the bootloaders/optiboot directory. This worked like a charm!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 96,459 other followers