a computer scientist’s thoughts
RSS icon Email icon Home icon
  • Using Arduino IDE without an Arduino

    Posted on July 16th, 2009 Eric No comments

    Arduino is essentially an AVR microcontroller interfaced with an USB/Serial chip to compter. It’s not hard to build your own arduino, and there are a lot of resources on the internet about this. See this.

    However, all these tricks requires you to buy an USB interface such that you can program your arduino. That small chip or cable usually costs you more than 20 dollars. For a cheap person like me, I don’t want to do that. However, the arduino IDE is really handy. I love to program in it, even though I use VIM a lot, I still want to use this IDE to program my AVR. So I really want to use this IDE such that I can upload the file to the arduino with one click. However, I don’t want to invest any money on the buying an arduino, since I know it’s just a uC with interface, and I usually use my uC in a naked way.

    I know that the IDE uses avr-gcc and avrdude.Avr-gcc compiles any thing into a standard hex file to the avr uC. Thus, the IDE didn’t do anything special here. The avrdude program supports way more programming methods to an AVR chip than the Arduino way (usb/serial). Thus, it is possible to make a cheap ass ISP programmer to the uC, and then modify the IDE such that it calls avrdude with the function you want.

    To make things easier, I give a very simpler version to make a cheap arduino (I will call it naked avr chip with battery included):

    An AVR uC, for instance, ATMEGA8L ($3 here? My uncle in China mailed me many. Pick the uC with suffix L, meaning a 3V voltage is high enough for it to work, you don’t need 5V. For using 5V, you might have to buy a 7805 regulator, which I don’t want to.)

    Some LED to test it. (Radio Shack, around $3 for 20, any LED will be good. They are cheap and robust, you don’t need transistors to protect them, or your uC)

    A 2-AA battery box (Radio Shack, less than $2)

    A breadboard and some jump wire  (ebay, 20$ for both, free shipping, find the best deal)

    You don’t need a 20Mhz clock and capacitors around it, you can just use the clock inside the AVR chip.

    —————–

    If you want to DIY an DB-25 ISP programmer cable:

    A DB-25 connector (male, you plug it to your computer’s parallel port)

    Some wire

    To see these simple steps to make a parallel port programmer, see this link:

    You can also buy one online, for like $8.

    Connect your ISP to your AVR correctly (you can find the instructions easily online), you don’t need any resistor or any capacitor whatever on the breadboard, seriously. Again, your AVR is robust enough to handle things under 3V voltage AA battery power. 3V voltage won’t destroy your LED either, so don’t even bother connecting your LED to a transistor (I know it’s suggested, but I just want to show you that you can be lazy here. Every transistor/capacitor on the breadboard will scare away half hobbists ).

    OK, here is the real hack.

    1. To burn the bootloader down, choose your board, and your cable (w/ parallel programmer, depends on your ISP cable), you can see that there is a menu item for it. You can see if it works. Mine doesn’t, because my cable is called stk200, and arduino assumes another interface. What I did was go to your hardware/tools folder, you will find avrdude there. I changed avrdude to avrdude1 and then write a bash script called avrdude and calls avadude. In this way, I use echo $* to see the command line passed to avrdude. I then changed the fifth option to -t stk200, which is my ISP programmer protocol.

    Actually it’s not that important to burn bootloader, especially everytime you actually use ISP programmer instead of using the bootloader. I write it here because I hacked it and in case you want to burn the bootloader for your AVR in Arduino environment.

    2. To upload. I tried to click the “Upload to uC with I/O” button in the IDE. It complains that there is no Serial port. Of course there is not, because I don’t use it :) . I also found the exception stack saying something about AvrdudeUploader. Haha, that’s it. So, I checked the souce code out from arduino website using:

    svn checkout http://arduino.googlecode.com/svn/trunk/ arduino-read-only

    Then, you edit app/AvrdudeUploader.java, you will find a function called “uploadViaBootloader“, that’s exactly the function that IDE calls to upload the program. Here, comment out the String protocol = line, change it to something like

    String protocol = “your_protocol”;

    Assign it to the protocol you use ( for instance, I use stk200, or the parallel cable protocol). Remove the line with comment “don’t erase” (yes, erase it :) , remove the whole “if (Preference.get…)” chuck, and remove the link that contains “upload.speed“, then go to the build/linux folder, ececute the make and dist script. It will create a folder called arduino-0016 something, and you can go inside to the lib/ director, copy all the “.jar” files to the install director of your arduion install directory.

    Now, do everything you want on your naked avr, using arduino IDE ;)

    (I quick tip, Arduino uses pin 13 as the default LED pin. It it used as SCK pin for the programmer, so, when you test “Blink”, you’d better use another pin, otherwise, unplug your programmer from the uC. The programmer draw sink the current such that you won’t see the blinking light.

    I will post some photos later about my hack.

    Happy hacking.

    Leave a reply