Go Down

Topic: Arduino-izing the AVR Butterfly (Read 23096 times) previous topic - next topic


Sep 28, 2008, 09:37 pm Last Edit: Sep 28, 2008, 10:18 pm by JoePardue Reason: 1
[size=12]Arduino-izing the AVR Butterfly[/size]

Forgive me for converting Arduino into a verb, but I think this is actually acknowledging an existing fact: Arduino has evolved into an action rather than a thing.

It seems to me that Arduino started out applying the Wiring IDE, libraries and simplification of C syntax to a specific hardware platform with 14 Digital I/O and 6 Analog I/O pins. There seems to be a movement to retain the Arduino-ness of a device while moving to different pin numbers, such as talk of an ATmega644 or Xmega Arduino.

Personally, I think that this transition has the potential of either destroying the core value of the Arduino brand, or cementing is as the best way to get started with physical computing. I hope to be able to participate in this process by porting everything Arduino to the AVR Butterfly platform. But, I am very new with the Arduino, so I will need guidance.

[size=12]What you lose by using an AVR Butterfly[/size]
Most of the available Butterfly pins are multipurpose so if you want to use them one way, you lose the ability to use them another way (see Butterfly Alternate Pin Use in the download menu of www.smileymicros.com).

For instance, the digital I/O pins on Port D which conform to Arduino pins 0 to 7 are available on the Butterfly for general purpose I/O on a 10 pin dual row pad (8 signal, 1 Vcc, 1 Gnd), but these lines are also used for LCD pins 9,11-16,18 so if you use them for digital I/O you will see the pin state reflected in those LCD elements. This probably won't hurt anything since LCDs use very little current, they won't affect the I/O for the alternate use. There is some concern that the LCD may be damaged if you keep a DC voltage on them for too long, but in my experience (and I have a lot with these things) I have yet to see any damage occur. Then again, I've never plugged one of these pins into a wall socket, something I'm sure some newbie will try.

Also, in order to get 14 digital I/O pins, it will be necessary to re-map Arduino pins 12 and 13 to Port E where we have pins 4,5,6 available.

Finally, we lose 2 of the 6 Analog pins.

[size=12]What we gain by using the AVR Butterfly[/size]
We gain three Analog pins that are connected to sensors: a resister divider for measuring voltage, a NTC resistor for measuring temperature, and a light dependent resistor for measuring light. The latter can be left off the board and the pad can be used to replace one of the two analog pins we lost above.

We gain the 5-way joystick button and a piezo speaker (both at the expense of re-mapping pins form Port B to Port E).

We gain the LCD with the caveat that we can only use it if we are willing to sacrifice 8 of the 15 digital I/O pins in order to be able to use the LCD.

We gain a real-time-clock since we have a 32.768 kHz crystal that is used for calibrating the internal oscillator and can be used for accurate counting of seconds.
What needs to be done.[/size]

A Butterfly-Arduino library should be written to allow Arduino-style use of the LCD, joystick, speaker, sensors, and real-time-clock.

Investigate the clock speed to conform to Arduino. I'm not sure how easy it is to adjust Arduiono libraries for clock speeds other than 16 MHz, nor do I know off the top of my head how to adjust the Butterfly to run at 16 MHz which at first glance I think should be doable, but I'll have to dig a bit to see how.[edit]The ATmega169 in the Butterfly can be calibrated to 8 MHz, so I'll need to figure out how to make the Arduino libraries work at lower clock speeds.[/edit]

If it is possible to Arduino-ize the Butterfly, then I need to learn more about how to get this chimera approved by the owners of the Arduino imprimatur. I would like early information on this process since I was already well on my way to creating something similar and if what I am doing is not actually Arduino-able then I should get back on that track and not waste anymore time here.

Oh, and I promise that even though my last name is Pardue, I will not to call this thing Parduino.

So, what do you folks think?



There are several Ardunio variants that operate at 8MHz.  In theory, you can use pretty much any clock speed with quite minor modifcations.  Whether sketchs will will depends on how much they stick to the arduino APIs, and how much they make assumptions.

Are there existing libraries for the Butterfly's actual peripherals that an Arduino-like library should be compatible with?


I'm still tinkering under the hood of Arduino and at this point I have a pile of blackened oily parts laying about the garage floor and I'm hoping I can remember what goes where when I reassemble the thing. I'll probably drill all the way down into Processing before I allow that I understand the underlying infrastructure enough to trust that I know what I'm doing, so this may take a while. A lot of what I am seeing looks simple enough, but there are still some WTFs that I have to figure out before I feel confident.

I'm not sure about the libraries yet. I, of course, intend to use what is already available, but I think I'll have to build my own for the Butterfly LCD since it is a weirdly custom job and probably something for the joystick, the piezo speaker, and the voltage, temperature, and light sensors.



I'm not sure about the libraries yet.

You might want to take a look at the Arduino Libraries for the Orangutan and 3pi Robot and follow the development discussion for them in past forum posts. I see the situations as being similar--adapting an existing board to work within the Arduino environment.



Funny, I was just following Smiley's guide to using the Butterfly as a development platform and got the idea to go looking for Arduino stuff for the Butterfly, and what do I find? Here he is again, doing the work for me. Cool! :)

Guess I'll have to fight with C for a while longer. In the meantime, I sure hope this project works out, I'd love to use it!


Hi Guys,

Just want to add my support to this project I have thought that the butterfly would be a perfect candidate for the Arduino platform ever since I heard about the platform.

I hope to port my MP3 player to the Arduino platform to expand its flexibility and also the usefulness of the code to others.

If you want any testing done or assistance converting code then send me an email. I have experience hacking the butterfly for some time and a logic analyser within reach.


Make an 'ardorfly' sounds like a really good plan. I've bought a butterfly, and had a good time building a coolwire halloween display using the butterfly carrier, but my new arduino is a lot easier to program.

Happy to beta test whatever comes along. 8-)


What would be the minimum necessary to get the Arduino IDE to a state where it could compile simple blinking LED programs and upload them to the butterfly via the serial port?

I'd like to get just this working, without worrying too much about making it fancy and remapping port pins or providing access to the butterfly's various features.


I think the butterfly can actually print out "hello world" instead of blinking an LED :)

more gcc avr butterfly stuff here:

It looks pretty straight forward, though that does not imply that I think it is the right thing to do.  Smiley is right in that multiple chip support can fracture the community.  

I think the 169 is similar enough to the 168 that  they can play well together, no through hole option though but a pre-assembled butterfly makes a real nice beginners package.

The 644 however adds so many pins and functions that don't benefit the 168 core that I don't see that fully integrating with the IDE without costing the beginners some headache as they wade through arduino.cc with article after article about this one specific chip and what it can do, when it does not even apply to their hardware.

Of course if you make it easy to use a butterfly, then you make assumptions about what accessories are at which port addresses.  Which is awesome for beginners with a butterfly, but alienates the blink crowd as they wade through arduino article after article about temperature readings and piezo sound notes based on the butterfly addresses.

But I definitely like the concept of a "standard computing device", with a display of known capacity and some buttons at known port addresses.  I've seen a few 168 based ones but the 169 built in lcd controller is nice and low power is a cool angle.  

So it's a lot to think about anyway.  Doing it is the easy part :)


Really what I'm after right now is just a quick hack to get the Arduino stuff loading to and running on the Butterfly, regardless of what libraries end up working. I'm so fed up with the usual open source tool chains and libraries that I just want the simplicity of Arduino. I want to write programs, not infrastructure.

Since the fanciest controller I've got beside the butterfly is a 2313, if I'm going to do it its going to be the butterfly.

At the moment I'm not sure what to do about getting the Arduino IDE talking to the butterfly. avrdude reports an error 'not in sync: resp=03f'. Guess I'll have to chase that down today.


well, if you can get some c working with gcc and avrdude from the command line then you are pretty much there.  But it is fundamentally an infrastructure change to introduce the butterfly to arduino, so you kinda have to expect some infrastructure discussion before we can talk about how to program it.

Like I don't know if the butterfly bootloader is compatible with arduino even, or if all the registers/ports have the same names or anything.  

But it looks like it is well integrated with avrstudio (which is a nice IDE btw), have you looks at that at all if you are in a hurry?



I'm currently using AVRStudio with WinAVR and am compiling to the Butterfly using the AVRStudio's 'AVR Prog' (which mysteriously cannot see the Butterfly on the serial port on every other attempt). Still working out how to get the clock and timers to do what I want.

I've also got AVRDUDE working on Ubuntu with my ancient parallel port STK200 AVRISP dongle (which involved fabricating a 10-pin to 6 pin adapter ::) ). This was necessary to reload the Butterfly bootloader and fix the 0x940c issue (thanks to Smiley and others who worked that out)).

Now I'm just working with the GCC'd version of the Butterfly software to extend it to what I want, which works, but it's a lot more fiddly than Arduino coding. It's like it's missing some software layers that make it reasonable to use libraries, which is very flexible, but not, IMO, as much fun.

Anyway, to get back to the topic at hand, I suppose a first step would be to check out the bootloader requirements and get the Arduino IDE talking to the Butterfly.

Mark Bramwell

Nov 29, 2008, 06:01 am Last Edit: Nov 29, 2008, 05:14 pm by mbramwel Reason: 1
looks like an interesting board.  I am thinking of ordering one to play with.  The xtal is slow. I would guess that a modification to the bootloader would be required to use the internal 8mhz clock (no xtal required).  I believe some of the existing off-beat arduino boards are 8mhz with no external crystal.  I would suggest try loading their bootloader onto the butterfly to see if it works.

If is does, a new config file could be created to support it properly.

I see the mouser has some.  Lets see if they arrive before xmas...


I have ordered 3 of these.  I plan on making a library for this board because it could be a good teaching tool.  I envision an arduino library with all of the PINS defined with nice names like "Speaker1" and create a few functions like Sound(), Light(), Temperature(), LCD() to make it easy.  I am assuming that I can get a bootloader running in the unit since we can get even a barebones ATMEL running with the bootloader.  I'll work on it over the xmas break (school is out in a week).


Sorry I already posted this in another thread but I thought it worth posting here as well if anyone is interested or if you guys have already done it.

Just done a first pass of the butterfly version of the arduino12
You can download my files from http://www.brokentoaster.com/arduino012_butterfly.zip

Any thoughts or feedback most welcome.

Things you need to do to make it work:

* copy the files & folders into your arduino Hardware directory.

* change preferences.txt to upload.using=butterfly

     This preferences file is found in this folder:

         * /Users/<USERNAME>/Library/Arduino/preferences.txt (Mac)
         * c:\Documents and Settings\<USERNAME>\Application Data\Arduino\preferences.txt (Windows)
         * ~/.arduino/preferences.txt (Linux)

* push the button when uploading starts
* dont hold the button down the entire time.

Things to do in the future:
Butterfly library for
     - temperature
     - flash
     - light sensor
     - speaker
     - LCD
     - Joystick
- check analog pins (jtag port)
- check digital pinouts on port b and D
- check all the timmings
- check it makes sense.      


These are things I've done in the files to make it kind of work. They may or may not be necessary.
I tried using conditional compilation but I wasn't being picked up so I just copied the core and
made changes to that.

* added following to boards.txt to support as a target compilation board




* added Bf_boot to bootloaders dir
     - copied hex from bf_boot up to bootloaders/bf_boot and renamed bf_boot.hex

* removed second external interupt from hardware/cores/arduino/WInterrupts.c: -> changes not picked up??

* changed boards.txt core = butterfly
     - copied arduino core folder and renamed to be buttefly
     - changes to hardware/cores/butterfly/WInterrupts.c
     - changes to hardware/cores/butterfly/wiring.c  TCCR0 - > TCCR0A  
     - changes to hardware/cores/butterfly/wiring_analog.c: In function 'analogWrite':
     - changes to hardware/cores/butterfly/wiring_digital.c: In function 'turnOffPWM':

* added avrispv2 to programmers.txt
* added butterfly to external programmers



The xtal is slow. I would guess that a modification to the bootloader would be required to use the internal 8mhz clock

I'm not sure what you mean. The default Butterfly software uses the Mega's clock prescaler to divide the 8MHz clock down to 1MHz, and then uses the Butterfly's 32kHz RTC crystal to calibrate the clock and set the OSCCAL bits.

If you want the 8MHz clock (or something else) you can change the clock prescaling and tweak the OSCCAL bits to get what you want. When using AVR Studio this is something I do as part of the setup for a program. Not sure how this fits in with the Arduino stuff, but I assume it can be done just as easily.

The bootloader that comes on the Butterfly has certain assumptions built in that might not be ideal for use with Arduino, but I suppose it would be simplest to try to keep it. Replacing it would make it more complicated to use off-the-shelf Butterflys, since it requires an ISP cable to reprogram the bootloader.

Great to see that this is progressing! My only Butterfly is currently occupied doing something else right now, or I'd give Nick's updates a try. Maybe I can do that over the holiday break.

Go Up