Butterfly -> Arduino

I have an AVR Butterfly sitting on my desk and was wondering if there is any way to use the arduino language and IDE with it. Is the bootloader 168-specific or can it deal with a 169?
Has anyone tried this ?

I looked at doing this, and noticed that the big problem is that all the pins on the butterfly are USED. You might think that you could put some sockets in the headers and implement your 13+6 arduino IOs, since the 169 starts with so many more pins than than the 168, but all the 169 pins are CONNECTED to something. (Many are connected to the LCD, and you really don't want non-LCD waveforms on those pins if you don't want the LCD display to die an untimely death...)

So I gave up on the idea.

I'm a bit late coming to the party, but I thought I'd start by saying that the statement about limits on Butterfly pins isn't exactly correct. You can see what I've got to say about this in detail at:

[TUT] [HARD] Butterfly Alternate Pin Uses

In brief, the LCD shared pins will only have a problem is the output is DC and for an extended period of time. I use these pins to run a variety of DIP switch and LED experiments and while the LCD elements do dance, they don't seem to degrade. You can also get access to some of the JTAG pins for ADC.

I think the Butterfly would be an excellent platform for the Arduino philosophy and will be looking deeper into this myself.

[edit]Oh, bother, this is my first post so I can't add an URL so I'll put that in the next post[/edit]

Smiley

Let's see if it will take it now:
[TUT] [HARD] Butterfly Alternate Pin Uses
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=45064

Smiley

(In case people don't know, "Smiley Micros" is THE major 3rd party distributors of AVR Butterflies, along with assorted accessories, books, and educational kits based on the Butterfly.)
His presence here in arduino-land bodes ... interesting things, perhaps?

Thanks smiley and westfw, the www.smileymicros.com site looks to have lots of useful butterfly information and stuff.

If either of you are looking to get arduino code running on the butterfly I would be happy to try and help. I have a butterfly on my desk waiting for an interesting challenge.

Well, I can't commit to anything for sure, but I have taken several days to dig into Arduino/Wiring/Processing since I was well on my way to reinventing the wheel on 'novice friendly microcontroller engineering' with some recent work that I've been doing.

It looks like to me that the folks who have generated all this have a keen insight into the things novices want to do and have come up with ways around the many traps that prevent the novice from doing those things.

I have read several philosophical statements by the originators that make me want to sigh, 'Home at last!'. Especially after arguing with some of the buggers on AVRFreaks who think you should be able to read the data book, memorize the AVR assembly language, and program in C on a PC before even touching the microcontroller.

I've had folks there really bash ideas that I've put forward, that are very similar to the sorts of stuff that the Wiring/Arduino folks are doing so well. I think a bright and interested person with no technical background can be blinking LEDs and reading switches in a couple of hours, and be downright dangerous in a couple of days. And have fun learning this stuff.

It feels great to see a community that validates your personal prejudices. :slight_smile:

Anyway, I'm reading through some stuff and trying to see if I can bend the pins_arduino.c file into something that will work for the Butterfly and still be compatible with the Arduino philosophy.

I want to get a much better background on all this before talking too much more.

Smiley

I wasn't sure where to post this so I put it in the Hardware Development forum: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1222630663
It discusses what I'm planning on trying with the Butterfly - and I sure would like some feedback.

Smiley

Welcome to the Arduino Forums O Great AVR Freaks Refugee Smiley--even though you may not be as inexperienced as most of us here, I hope you feel free to stick around. :smiley:

It's also cool to read an experienced AVR developer wanting to enable as many people as possible to use it AVRs as a tool--I guess that's why you wrote a book... :slight_smile:

--Phil.

P.S. I found a copy of Nuts & Volts in New Zealand last week and noticed your second AVR column in it.

Thanks for the welcome :slight_smile:

I'm glad to see that Nuts&Volts is in New Zealand, I didn't realize that it is international. You can get a copy of these articles on my website, one month after they appear in the print edition.

Smiley

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//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.

OTHER NOTES:

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
    bfly.name=Butterfly

bfly.upload.protocol=butterfly
bfly.upload.maximum_size=14336
bfly.upload.speed=19200

bfly.bootloader.low_fuses=0xE2
bfly.bootloader.high_fuses=0x98
bfly.bootloader.extended_fuses=0xFF
bfly.bootloader.path=butterfly
bfly.bootloader.file=bf_boot.hex
bfly.bootloader.unlock_bits=0x3F
bfly.bootloader.lock_bits=0x0F

bfly.build.mcu=atmega169

  • 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

www.brokentoaster.com/arduino012_butterfly.zip

Nick,

Great news that you are doing this. I'll look at this in a few days. I've also been working on something similar off and on for a while, so it will help to look at what you are doing when I can get back to it. I suspect we may be duplicating some efforts, but let me check what you've done and I'll get back to you. No use both of us doing this.

And you are the guy with the dangly cigaretted on AVRFreaks aren't you?

Smiley

I'm really new with microcontrollers so please bear with me if I ask really stupid questions.

Nick, the work you did sounds great and since I have a Butterfly, I was thinking to give it a try. One question though: using your Arduino-like modifications, can I still use the serial cable I regularly use to program my Butterfly? Or do I need a parallel one (of which I had one when I fixed the 0x940c error but I misplaced it somehow).

BTW, thanks Smiley for your posts on avrfreaks, they helped me a lot to fix my Butterfly when I thought it was dead for good with the 0x940c error.

Thanks for your work and for reading.

using your Arduino-like modifications, can I still use the serial cable I regularly use to program my Butterfly?

I'm not Nick, but yes you can use the regular serial cable (that's what I'm doing and it's working).

There's something wonky going on with the clock speeds that I haven't worked out yet, but so far so good.
[edit]The wonkyness was entirely me, evidently delay(1) doesn't actually delay for 1mS, but delayMicroseconds(1000) does. It's working great now.[/edit]

evidently delay(1) doesn't actually delay for 1mS

That's an interesting point. delay(n) is implemented in such a way so that the actual delay is betwen n-1 and n milliseconds. I think a better implementation would be to make sure delay waited at least n milliseconds before returning, similar to the way other environments operate.

Mikal

My test looks like this:

      digitalWrite(13, LOW);    
      delayMicroseconds(1000);                   
      digitalWrite(13, HIGH);   
      delay(1);                  
      digitalWrite(13, LOW);   
      delay(2);                  
      digitalWrite(13, HIGH);

and gives me delays of 1.0mS, 0.6mS and 2.0mS

Adjusting to:

void delay(unsigned long ms)
{
    unsigned long start = millis();
      
      while (millis() - [b](start-1)[/b] < ms)
            ;
}

and gives me delays of 1.0mS, 1.5mS and 2.0mS.

It could do something fancier, but either way I think simply noting the issue in the documentation would be sufficient.

I think simply noting the issue in the documentation would be sufficient.

I mildly disagree with this. I think the code should be changed to

while (millis() - start <= ms)

In other environments, the equivalent functions almost always guarantee that the process will delay at least the amount specified. This seems especially important in a microcontroller, where you are quite likely to be driving devices (like EEPROMs) which require minimum delays for correct operation. It seems wrong that when you need a 1ms delay you should have to write

delay(2); // huh?

I don't think most users read the docs for "familiar" functions like delay(). I don't. Did you? :slight_smile:

Mikal

I don't think most users read the docs for "familiar" functions like delay(). I don't. Did you?

Yep. As soon as I noticed that my delays didn't come out right :smiley:

What I really meant about the docs though was that they should mention that the precision of the delay is about 1mS; if you ask for 20mS you can get anything from 19 to 20mS (or 20 to 21 if its updated to guarantee a minimum delay) , depending on when the next millis timer overflow event is.