1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Microcontroller Programming in Mac OS X (AVR Butterfly mainly)

Discussion in 'Mac Programming' started by Cromulent, Feb 15, 2009.

  1. macrumors 603


    My Dad has recently given me his old AVR Butterfly and I thought I'd do a little bit of playing around with it. Does anyone know of a decent tool chain that is easy to setup and configure for AVR's on OS X?

    I've found a few tutorials for building my own cross compiler and associated tool chain but it is really quite difficult to spare the time at the moment faffing about with compiling cross compilers. Is there an alternative to AVR Studio on the Mac or some such?

    Any help appreciated. I'm completely new to the world of embedded programming so I'm hoping it will provide a little fun and something a bit different.

    Edit : Hmm just found something that looks promising. Let's hope it actually works.
  2. macrumors 603


    Always happens...

    Every time I post a thread here I immediately find a solution.

    Moderators feel free to delete this thread. For anyone else looking for a solution the answer lies here:

  3. macrumors 6502a

    Thanks for the link. Very interesting.
    Are the instructions working for you?
  4. macrumors 603


  5. macrumors 603


    Okay AVRMacPack which I linked above seems to compile AVR code properly. I've also found a serial terminal called goSerial to communicate with the device which I can't get to work unfortunately.

    I have absolutely no idea how I am supposed to upload the code to the AVR device. I know how to do it on Windows but under Mac OS X it seems somewhat more complex involving avrdude and usbasp or some such.

    I might see if I can get stuff going under Windows just to make sure things are working then I can see what is going wrong on the Mac side.

    If anyone has any experience with this I would appreciated some help :).
  6. macrumors 6502

    No experience under mac, easier to use windows VM, but try this http://www.ipnas.org/garnir/avr
  7. macrumors regular

    Use avrdude. The exact command depends on the device and programmer you're using. Here is what I use: (example for an AVRISP mkII programmer, an ATmega168, and object code in a file called main.hex):
    avrdude -c avrispmkII -P usb -p atmega168 -U flash:w:main.hex:i
    The AVRMacPack main page (http://www.obdev.at/products/avrmacpack/index.html) has a good example at the bottom. I'd recommend working that into a Makefile.
  8. macrumors 603


    Thanks for the information. But I've been doing that for hours, here is what my avrdude command looks like but I just don't know what I am doing wrong.

    avrdude -c butterfly -P /dev/tty.usbserial -p atmega169 -U flash:w:main.hex:i
    and here is the relevant area in the Makefile:

    DEVICE     = atmega169
    CLOCK      = 8000000
    PROGRAMMER = -c butterfly -P /dev/tty.usbserial
    OBJECTS    = main.o
    FUSES      = -U hfuse:w:0xd9:m -U lfuse:w:0x24:m
    I have no idea if it is the fuse bits that are causing the issue but I get the following error:

    Connecting to programmer: .avrdude: butterfly_recv(): programmer is not responding
    which is the best of the bunch really. At least it appears to be doing something when I get that error message rather than just immediately terminating.
  9. macrumors 6502

    Sounds like it can't communicate with the Butterfly.

    First check that it is turned on, and if it has a programming mode enable that (I don't recall exactly how the Butterfly works).

    Then look at your USB connection, try option -b 57600 or √ to set the baud rate and make sure your tty device is correct.

    Try this also http://bluebat.dnsalias.org/howto/butterfly/:

    The little butterfly is a great introduction to embedded programming, I had lots of fun with one about 5 years back...don't remember the specifics anymore.

    Great web site is avrfreaks.net
  10. macrumors 603


    Thanks this post helped me find the problem.

    I think the issue is not being able to start the bootloader on the butterfly. God knows how I am going to fix that. I found a link to download the bootloader program but as you need the bootloader running to flash the AVR it seems like a catch 22 situation. You need the bootloader running to install the bootloader.

    Back to the drawing board.
  11. macrumors 6502

    You can probably download it using the JTAG interface, if you have a programmer, or perhaps check the AVR documentation to see if there is a way to reset the device. The bootloader is supposed to be protected but if your father has a JTAG programmer then he may have overwritten it...but then you can restore it since you would have a JTAG programmer.

    Take a long hard look at the manual, perhaps the answer is there.

Share This Page