Full Version : AVR BUTTERFLY Q&A FAQ
avr >>BEGINNERS & BUTTERFLIES >>AVR BUTTERFLY Q&A FAQ


AVR_Admin- 05-09-2006
BUTTERFLY AUTOSTARTING USER PROGRAM:

I have the Butterfly. It's easy to program with just an RS232 cable and WinAVR. At least that's what I thought.

Now I need to program it so it will run my program after a reset, instead of running the "bootloader" program.

It seems I could do that by changing a fuse or changing the "bootloader". If I understand the situation correctly I will need to buy some hardware to do this. Like the stk500. Is this correct?

QUOTE
Yes, you do need a programmer. The stk500 might be overkill (but is nice to have I guess). You can get a serial programmer for < $10. For a bit more, $40 or so, you can get a JTAG type device that also supports debugging.


QUOTE
I use the ATAVRISP for programming my Butterfly. It costs $29 (US) and I got mine from Digi-Key. They had a huge inventory when I bought mine a few weeks ago.


I thought that it would be possible to program the AVR butterfly using only RS232. There are several web sites suggesting that this is true.
For example: <http://www.dwelch.com/avr/> Isn't this correct?


QUOTE
Yes you can program the Butterfly with the serial port. I have done so. But when you reset the thing (or power it on), it always runs the "bootloader". To exit the bootloader and run your code, you must press the joystick. This is okay for many uses but for some uses it is necessary that the Butterfly run the user's program automatically at power-on.

The Atmel chips are complicated beasts. The only reason you can program it with the serial port is because there is a small "bootloader" program that is resident in a special part of the program memory (flash). You can't change this program via the serial port. There is a "fuse" in the chip that specifies whether the reset interrupt vector for the bootloader is used, or the reset interrupt vector for the user program is used. You can't change the fuse via the serial port either.


I don't really want to get rid of the bootloader. I just want it to run my program when it's powered on. I think there are at least two ways to do this and both require some programming hardware.

I can change the fuse so it will run my program after reset. I can then get to the bootloader from my program by jumping to it when I want to update the software. If my program gets corrupted, I can use the programming hardware to change the fuse back to the original setting.

Another approach would be to change the bootloader program. If it would check a joystick switch initially, and jump to the user program if the switch wasn't closed, this would work and would allow use of the bootloader by pressing and holding the joystick when resetting the board. I do think I will buy the ATAVRISP.

There is a JTAGAVR device selling for $37.95 that looks interesting but unless someone here will recommend it, I'll stick with Atmel's ISP thing.

I never used JTAG and I don't need it, but it would be nice to have if it works. But the procedure and hardware required to update the microcode has scared me off of that thing.

QUOTE
If you just need to get out of the bootloader it might be enough to ground PB6 which is where the "UP" switch is connected. Works for me here. You can no longer use UP in your application though.


Naa. That's too easy Now why didn't I think of that? It looks like a simple jumper would do it. PB6 is next to ground at the port B header connector.



AVR_Admin- 05-09-2006
BUTTERFLY CONNECTING ADC:

This is probably pretty basic, but I'm a software guy just starting out on this project. I want to connect a sensor to one of the Atmel Butterfly spare A to D inputs. The sensor I am connecting requires a 10k load. Does this mean I that all I need to do is put a 10k resistor on the negative side of the sensor and connect it to ground, or is there more to it than that?

QUOTE
Based on what you have said I would say the 10k resistor has to go in parallel with the sensor. In other words one end of the resistor goes to ground and one end goes to the input on the Butterfly that you intend to connect your sensor to.

It might be a good idea to give us the manufacturer and model number of the sensor you have (or plan to use). This would enable someone here to provide more useful information for you.


It is the teledyne r-17. Thanks for the speedy response.

QUOTE
1. If the sensor has an integrated power source (battery) , and the sensor puts out various voltages (relative to a common ground) then the 10k load could be the A/D channnel minimum impedance.

2. If the sensor has to be powered from an external source (like the LM35 temp sensor) then then you must put a maximum 10k resistor between Vdd and the sensor and tie the grounds toghether.




AVR_Admin- 05-09-2006
BUTTERFLY RESET/RESTARTING:

I wrote some code to do some testing for my project using the butterfly and forgot to leave the bootFunc code in. I programmed the butterfly thru the use of the bootloader on the original code, now my butterfly doesnt' look like it's working with the new code and I've lost the capabilities to program it too.

Is there a way for me to get access back into the butterfly without the need of the JTAGICE, AVRISP, STK500?? I just wanted to know if there was any other way I could just reprogram my butterfly back to normal using just serial, but I think my work's got an AVRISP, but I'm not sure if it has a 6 pin or 10 pin cable and I won't be able to get there for a couple of days.

QUOTE
Toggle Power (Remove/Insert Battery), this will start the Bootloader. Do not push the joystick "up" (which would cause an application start) but keep it pressed ("enter") and select AVR-Studio/AVRProg.


Thank you for you help!


AVR_Admin- 05-09-2006
BUTTERFLY PORT E VOLTAGE:

When I set some port E pins as output on my mega169 they immediately have a high level. I expected the output level would be low, until I set them high.

When I run my software on the simulator, the output pins are low.

Is there something wrong with my mega169?

QUOTE
There are internal pullup resistors to vcc.... so when the output is off, the pin gets pulled up. When you turn it on, it pulls down to ground.


It's not the pullups. They can't source this much current and they wouldn't be enabled when the pin direction is out. At least I don't think so.

I didn't explain the situation very well. I can set the output high or low but I expected these pins to start out low.

I think I have the answer though. The PORTE register is 0xff when my program gets control. On the Butterfly my program doesn't get control from reset directly. It gets control from the "bootloader" program. So I guess the "bootloader" is setting the PORTE register to all one bits.

The bootloader reads some of the switches on the joystick and some of the port E pins are used for that. So the guy that wrote the bootloader probably set all the pins high to make sure he got the right ones.

CODE

From the BF-Bootloader-Code:

__C_task void main(void)
{
   ...
   PORTB = 0xFF;       // Enable pullup on
   PORTE = 0xFF;
   ...


Okay, just as I suspected. I looked briefly for the bootloader source but all I found was the app note 109 stuff that didn't read switches.


AVR_Admin- 05-09-2006
BUTTERFLY LCD DISPLAY OF CURRENCY:

Hello all, I am new to the embedded programming realm. I am trying to make a cashless smart card system to take the place of bill acceptors in the vending industry. I was wondering if the AVR Butterfly board is a logical solution to use to communicate with a smart card reader/writer over the rs-232 protocol.

I have noticed that many smart card reader/writers come with drivers the are designed for the pc. In my scenario, I don't have a pc that will be doing the communicating. I need a microcontroller board with an LCD display to display the dollar amounts stored on the smart cards.

I am about to purchase the butterfly kit along with a rs-232 card reader/writer. I was just wondering if this is the right way to go........

Any advice would be greatly appreciated. Thank You!!


QUOTE
I am not familiar at all with what you are trying to do but the first thing that popped into my head was whether 6 digits would be sufficient. The Butterfly can only display 6 digits. I don't know whether you need to display 2 digits of cents (or whatever your currency is).

Thinking about it further as I write this I realize that still allows $9999.99 which would certainly cover my bank account  . But, who knows, maybe you still need more than 6 digits total.


Will it allow the six digits along with the dollar sign and the dicimal point????

QUOTE
No, unfortunately there is no dollar sign or decimal point. There are other special symbols available...just not the ones you need apparently  .

You might want to check out application note AVR065. Page 6 contains a diagram of the available characters/symbols.



AVR_Admin- 05-09-2006
BUTTERFLY PROGRAMMING VIA CODEVISION & STK500:

I have a butterfly connected to an stk500 via the isp connector and I am having problems programming it.

It worked once but I think I may have not programmed the clock select fuses correctly and now I cannot program it again through the isp port.
Is there a way to reset the fuses so that it uses the internal clock.
I have tried to read the fuse settings with AVR Studio but it says there is a problem reading the fuse settings.
I used Codevision to program it initially.



QUOTE
What are the chances you selected Ext. Clock or Ext. Oscillator (can't remember the exact terminology)? If you did you will need to supply an external clock signal. The JTAG connector has a pin for this but you may need to remove one or two zero ohm resistors and maybe make a jumper or two. Do you know where to find the Butterfly schematic? If the Butterfly came with a CD the schematic should be in the Butterfly User Guide (not the Quick Start but the full user guide).

Another possible problem is VTG (from the STK500) contention with the Butterfly battery supplied Vcc.

Another possible problem is the STK500 clock speed needs to be lowered. This can be done on the Board tab of the STK500 window in Studio.



AVR_Admin- 05-09-2006
BUTTERFLY RS232 CONNECTION TO TERMINAL:


I just bought my butterfly and hooked everything up through USART. To test my serial connection, i went into the NAME application within the butterfly and typed out my name in HyperTerminal and it worked fine. It got my name and wrote it on the screen.

I then tried programming the latest version (revision 6) onto the butterfly and that worked fine too. I read the flash and eeprom first to keep as a backup of the original image.

Aparently, however, in my terminal program, i'm supposed to be able to also RECEIVE text from the machine. If i click it in, i'm supposed to receive ?????, which i dont. I cannot receive anything from it. If my receive was broken, how was it able to read the EEPROM and Flash (with valid data in the files), but not send debug info like that?

Anyone know what i might be doing wrong?

QUOTE
I'd recommend that you use Bray's terminal instead.



Yeah, i followed your instructions, and didnt get the ???? when you said i would. After checking everything 100 times, i tried sending and that worked and also programming worked... i wonder what could be wrong.

QUOTE
Lots of complaints about using HyperTerminal so I switched to Brays terminal. Did you try that?


Yes, i did try bray's terminal and am having the same results. Have you seen this before though? where you can only send and not receive?


QUOTE
If the AVR Prog in AVR Studio detected the Butterfly, then the PC has to be receiving from the Butterfly, so the Butterfly must be sending the ?????'s. And since you tried both HyperTerminal and Bray's Terminal, and they didn't see the ?????'s this represents an impossible situation, which is often the case when debugging, what you are seeing simply can't be happening, but it is. So, I'm going to have to do some guessing, I know you've already tried most of this but...

Were you holding down the center of the joystick? It could be that the joystick center is defective. Try shorting PB4 (remember numbering starts with PB0) to ground which gives the same input a pushing the center in.

Retry AVR Studio and see if AVR Prog still detects the Butterfly
If so, triple check all the settings on Brays Studio and try again.
If not, turn everything off and reboot your PC and try it all again.

If it still doesn't work, I'd resolder the RS-232 joints hoping for some magic, then retry everything in sequence carefully.



Wow! ok. By doing a bunch of shorting of pins i indirectly fixed my problem. As with all of these "impossible" errors, its a user error. I assumed the device had to have "AVR BUTTERFLY" scrolling while pressing center. Little did i know that it had to actually be reset with nothing on the screen for it to work



AVR_Admin- 05-09-2006
BUTTERFLY CLOCK SPEED:

I don't manage to determine the clock frequency of the ATMEGA169 in the AVR Butterfly board.

I have read the datasheet for atmega169 and the user guide for the Butterfly back and forth to no avail.

Here is what I know:

there is a 32kHz xtal connected to TOSC1
The lock bits at 0xE2 CKSEL read external crystal, 3 - 8 MHz, which matches the "Advanced..." screen of AvrProg.

The clock prescaler CLKPS reads 02, meaning a clock division factor = 4

ASSR reads 0x08, ie bit4 is false, ext. clock NOT selected, bit 3 is set, async timer2 clocked from TOSC1 pin.

Does that mean the MCU runs at 32kHz devided by 4 (prescaler) = 8kHz.

I simply cannot imagine that it runs a factor 1000 slower than what is possible (8MHz if run from the internal RC clock)

Where is it described and how can I verify the cPU clock?

QUOTE
From the Bootloader code it seems that it runs 2Mhz
The setting the UBBR0L = 12 seems to indicate 9600 baud but he also selects // Enable 2x speed
so this is prob 19200 @ 2Mhz



CODE

   // boost IntRC to 2Mhz to achieve 19200 baudrate
   CLKPR = (1<<CLKPCE);        // set Clock Prescaler Change Enable
   // set prescaler = 4, Inter RC 8Mhz / 4 = 2Mhz
   CLKPR = (1<<CLKPS1);    

   UBRR0H = 0;//(unsigned char)(baudrate>>8);
   UBRR0L = 12;//(unsigned char)baudrate;

   // Enable 2x speed
   UCSR0A = (1<<U2X0);



QUOTE
Are you reading the lock bits or the fuse bits?

If you use a capable program such as AVRStudio that deciphers the bits for you, I would think that the standard Butterfly is fused with the internal oscillator divided down by CLKPR. As suggested, 8MHz/4.



QUOTE
The ATmega169 has an 8mHz internal oscillator that is very precise, but due to manufacturing variables, not very accruate. If you tried to build a clock with it you could gain or lose hours a day. So the Butterfly designers put the external 32768Hz watch crystal which is much cheaper than cpu speed crystals to use to calibrate the oscillator and to provide a real time clock. The internal oscillator adjustment variable can be changed so that the oscillator counts 8M while the watch crystal input counts to 32768, making the oscillator very accurate. For an RTC application the watch crystal is counted, rather than the internal oscillator. For using the USART at 19200 baud (the Butterfly software rate) the internal oscillator is divided by 4 to 2 mHz which is what is needed to get an accurate 19200 baud from the USART. Look at the Butterfly software for the oscillator calibration function and the USART initiation functions and then look at the 169 data sheet to see what their variable settings actually do on the chip.


QUOTE
I expect the main reason for having the 32kHz XTAL on the Butterfly is the option to drive a timer in async-mode so the AVR can enter a "deep" sleep-mode and also keep the RTC up to date. When active the ATmega169 on the Butterfly is set to calibrated FOSC=1MHz ( 8/8 ) by the presintalled application for power-saving reasons and raised to 2MHz ( 8/4 ) for UART-operation to minimize the baudrate error (BF is set to 9600 with U2X IRC).


I expect the main reason for having the 32kHz XTAL on the Butterfly is the option to drive a timer in async-mode so the AVR can enter a "deep" sleep-mode and also keep the RTC up to date.

First: I was told that the internal oscillator is not accurate enough for an RTC, so wouldn't the main reason for having it be to have an accurate RTC period, not just so it can sleep.

Second: Isn't the internal oscillator even uncalibrated accurate enough for 19200 USART communications?


QUOTE
Typically, AVR internal oscillators vary in frequency with changes in supply voltage and temperature. Newer AVRs have flatter curves for temperature, but the probability of getting rock-solid serial comms over the entire temperature and supply voltage range is slim. I haven't dug through all the Butterfly code, but I believe they are doing "dynamic" re-tune of the internal oscillator using the 32k as a referenced timebase. This is very commonly done on TI MSP430, and I did it in one of our Mega48 battery apps with good results.

Search your datasheet for "U2X" and all will be revealed. It is a 2x doubling of the UART baud rate; IIRC they do it by cutting the samples/bit? Whatever. Anyway, if your clock frequency is not one of the "magic" numbers, a better match can sometimes be made with the U2X, in this case UBRR for 9600 plus U2X may give a better match than UBRR for 19200 and no U2X.


QUOTE
Yes, the internal RC-Oscil. is not accucate enough to clock an RTC if not "tuned". In fact the "default" Application-Code "tunes" the internal RC with the 32kHz XTAL as described by Lee. It's not done to drive the RTC with the main-clock since RTC is always driven by the 32kHz XTAL (Timer2 Async-Mode). The reason for "tuning" should be an accurate UART-Timing. It would be possible to drive the RTC accuratly with an "FOSC"-XTAL but this is not a good idea if you whant to use power-down sleep-mode (see Datasheet Sleep-Modes/Power-Up Ints)

I haven't tested the UART without calibration. In fact all my BF-code includes a copy of the Application "RC-Oscil. tuning-code" which is called after a reset and from time to time before a UART-Communication. I' using the UART with 9600*2 at 2MHz and "fall-back" to 1MHz when there is not UART-communication for a better power-saving. It's like Atmel does it in the Application and Bootloader-code. 19200 "without" calibration is not enough information to say if it's "accurate enough" Information about FOSC and U2X is also needed.


QUOTE
The default application/bootloader sets the UBRR to 9600 for 2 MHz and enables U2X for 19200 "effective baud-rate". It's like Lee has already explained. From the ATmega169-Datasheet:

at 1MHz and U2X=0, 9600 und 19200: >=7% Error
at 2Mhz and U2X=0, 9600: ok, 19200 7% Error
at 2Mhz and U2X=1 19200: ok

So if the frequency should be as low as possible (power saving) and Baud-rate should be >9600: F_OSC 2MHz, UBRR to 9600 and U2X=1 is a good choice to get 19200.




AVR_Admin- 05-09-2006
BUTTERFLY PIEZO OR SPEAKER SOUNDS:

Recently someone asked me if I could implement a simple application that, among other things, emits a "wolf whistle". (Is "wolf whistle" strictly a North American term, or is it a well known term internationally?) The application is a "joke" item.

Anyway, my friend had the idea that it could be stored as a WAV file (or some other audio format), but I am thinking that it should be fairly simple to implement it as an algorithm, instead, all in firmware. The whistle could be emitted via a piezo transducer with, maybe, a simple RC filter between the AVR pin output and the piezo (maybe an op-amp to boost it, if needed).

Has anyone ever done this, or know where I can find some "wolf whistle" parametric details (frequency, timing, rise and fall rates, etc.) on the web?

QUOTE

Cant do it with a piezo... they only resonate at aone narrow freq.. off the top of my head, I'll spec it... "sweep from 1k to 2k in 500ms. slilence for 500ms. sweep from 1k to 1.5k in 500ms, sweep from 1.5k to 1k in 500ms"



Thanks for the reply. I figured it would be something like that (off the top of my own head!) But I was wondering if the frequency sweep would be linear or if it would be some kind of curve (logarithmic, sine, or something). Anyway, it's probably so simple I could even do it in assembler!


Any ideas on what to use for a cheap transducer if a piezo will not do?

QUOTE
To make a simple tone from an AVR output, connect the output to a small speaker through a resistor say 200 ohms (5v/200ohms --20mA; actually less current due to the speaker's AC impedance). A transistor, op amp, or LM386 buffer will make the sound louder.




AVR_Admin- 05-09-2006
BUTTERFLY PROGRAMMING:

I´ll get straight to the point.
I´ve toyed around with my Avr Butterfly for a while and just started to try sending software to it. The guide I used was the Quick Start Guide by Joe Pardue, it´s a good one I might add.
Now, when I downloaded the code I must have clicked EEPROM instead of FLASH, the programming worked and the Cylon LED worked as well.
But how do I get the original boot menu back?


QUOTE
I doubt that you've broken your bootloader even if you did inadvertently write to EEPROM.

You can quickly check that the Bootloader is running by openning Bray's Terminal, connecting as in the instructions, cycle power to the Butterfly and then press the joystick to the center button. You should see a series of ????? in the input window.

I'm guessing that all you need to do is turn power off to the Butterfly, turn it back on, make sure that no terminal program is talking to the Butterfly, then hold the joystick center button down and simultaneously click on the AVRProg button in AVRStudio.


The ???s are appearing ok and the AVRProg window appears ok..
What I´d like to do now is to get the old Butterfly LCD meny back. I can re-download the Cylon blinky to the flash but when I try to re-download it to the EEPROM the AVRProg-window freezes and has to be terminated. Any guess?

QUOTE
You don't download to the EEPROM, you download to the flash.

Just download the Butterfly source code .hex file that MJThomas ported to the WinAVR tool set. That should restore the Butterfly, except that the intial LCD message is different in that it mentons GCC, I think. Anyway, you will want to get used to compiling and loading the GCC port of the Butterfly code because it provides an outstanding learning tool and you can modify and reuse sections of it.


I got i working again
A humble thank you is in order. That was a sure reminder of my youth and all those broken PCs I left behind in the learning process



AVR_Admin- 05-09-2006
AUTOSTARTING BUTTERFLY USER PROGRAM:


I have an application running on the butterfly using WinAVR. How can I make it start automatically instead of having to push the up joystick?
I see that there is a fuse that makes it jump to my application directly, but the data book states the Boot Reset Fuse cannot be programmed from MCU, so do I need to hook up STK500 directly instead of using serial port and AVRProg? (I'm lazy.) Is there a way to do this over the serial port?
Also, why does the boot loader require the joystick be held down(enter) to get AVRProg to work? Is there a bootloader for Gcc that doesn't require this?
Maybe the idea is a bootloader that looks for AVRProg briefly and then jumps to application code. Does this exist?

QUOTE
Look at the Butterfly bootloader source code. The joystick position is arbitrary and you can rewrite it to do whatever you want including wait and jump. Yes there is a GCC port of the Butterfly source including the Bootloader,


What I wanted to do was have a way to have the butterfly automatically run my application without having to press the UP JOYSTICK command, and I wanted to be able to do it using the serial port programming.

BUT, You can't overwrite the boot loader using the boot loader, can you?

I made modifications to the boot loader so it would time out after sending a few "?" and run my app.

But when I tried to load the program it croaked and then my butterfly became unusable until I restored the original boot loader code using the ISP 6 pin header on the STK500.

I tried it again and the same thing happened. Then I tried flashing my modified boot loader using the STK500 and it worked.

The program that is writing the flash is executing from the flash which I'm trying to write. Probably a very bad idea.

I guess you could do something heroic like write a boot loader that ran in the application area and use that to update the real boot loader but I think that is too much work for dumb old me to ponder.

I did make a very easy modification to the boot loader so it puts out 25 question marks (to start the AVRProg if present) and then jumps to the application code (if not present). It's a bit difficult timing wise to force a reset by lifting the battery while you click on AVRProg with the mouse but it is do-able. (A reset switch would be a LOT easier!) So now my application can be field updated by anyone with a pc and serial cable.

It was very simple to do this modification once I figured out that I had to use the ISP to program the boot loader, but if anybody is interested I'm happy to post the mod.

QUOTE
You can ground the PB6 pin (which is where the UP switch is connected) and keep the original bootloader. Alas, you will then not be able to use "UP" in your application.



AVR_Admin- 05-09-2006
BUTTERFLY TEMPERATURES:

I've been playing with my Butterfly, and my temperature reading is high by about 10 degrees Farenheit.

Right now in my house it reads 81 degrees F and 27 degrees C, and it's probably about 70 degrees F.

Has anybody else had this problem? I can't think of a good solution since I think I would have to change many values to recalibrate it.

I can code it with GCC if anybody has any ideas.

QUOTE
Remember to start with a "cold" board, not one that has been running for a while. Board-mounted temperature sensors are usually measuring the temperautre of the board, not the air, and the board can warm up in operation.

That said, 10 degrees does sound like a lot. If the Butterfly is battery-driven, the board probably doesn't warm up as much as our 24VAC boards with relays, LEDs, backlight, etc. From the BOM, what sensor is used? What does the datasheet for the device say about the nominal accuracy? How is the conversion done to display units?


QUOTE
temperature sensor its a NTC NCP18WF104J03RB from MURATA
black right to piezo under a bigger grey one (!?) and its a smd one....

maybe needs replacement (faulty)
however NTC ,even if it can, its not designed for a very accurancy
thermometer...
(even if atmel guys did it by far better that i will do with specisif hardware  )

btw it gives 2-3 celcius higher to normal to me too and getting warmer by time (after 2-3 minutes 5 about celcuis more)

When you were 'playing with' did you change the temperature lookup tables?


I found a solution, and I am surprised at how accurate it is now! I walked up to see if if matched my thermostat and it read the exact same temp, and then I drove around with it with my top down and it matched my car temp exactly.

I just adjusted the ADCresult value if the ADC was reading tempurature. If you are familiar with some of the GCC Butterfly code you may know what I'm talking about. I added 70 to ADCresult.


AVR_Admin- 05-09-2006
ACCESSING BUTTERFLY ADC PINS:

Can't figure out how to access the analog comparator of the mega169 chip on the AVR Butterfly. I have been looking at the mega169 data sheet and what I need are pins 4 and 5. According to the avr butterfly these pins are connected to the joystick??

I need to feed a signal to the analog comparator on the mega169. I would also like to set a reference voltage. Has anyone any idea of these pin connections as I cant see it? What pin on the butterfly do I connect my signal to get it to the analog compartor?

QUOTE
It doesn't appear that PE2 and PE3 are brought out to any header pins. Unless you want to solder directly to the joystick or the mega169 (better be a good solderer  ) you are kind of out of luck.



I am going to solder directly onto the joystick pads.

I still have a problem-from looking at the joystick schematic I can see there is 6 pins but how do you know which pins are which on the butterfly??

On the joystick on the butterfly there are 3 pins on top of the joystick and 3 pins below the joystick. Which pins are PE2 and PE3?? I have tried to attach the schematic but it is not working for me.

CODE
ALPS SKRHABE010. Its in japanese, but I found this in a pdf file:

1 = PB6
2 = PB4
3 = PE2
4 = PB7
5 = GND
6 = PE3


Unless I am totally daft Atmel did not follow the drawing above. I have pins 4 and 6 reversed from the above drawing, in other words the pins go 1, 2, 3, 4, 5 and 6 in a counter clockwise fashion. I measure PE2 connected as shown above to pin 3, but PE3 is connected to the diagonally opposite pin (pin 4 as shown above, not pin 6 as the schematic states). I measure PB7 connected to the pin directly opposite pin 3 (pin 6 as shown above, not pin 4 as the schematic states).

QUOTE
I don't read japanese, but this could say 'bottom view'.

I'm way to shaky to buz this out with an ohmmeter, 

AVR_Admin- 05-10-2006
BACKLIGHTING BUTTERFLY LCD:

So, I would like to backlight the LCD on the Butterfly.

I have some surface mount LEDs that I could do some side lighting with, but I don't think it would turn out that well.

I am thinking about using the Butterfly in my car and mount it into the dash. So, of course, I would need some backlighting.

Anybody have any ideas? Has anybody tried this?

QUOTE
The datasheet for the LCD specifies the rear polariser as being transflective. That means it should be possible to backlight it. You can find the datasheet for the LCD in the STK502 User Guide, Figure 4.1 (version 11/02). I haven't actually tried it, though
.


The datasheet for the LCD specifies the rear polariser as being transflective.
Could somebody explain what transreflective means?

QUOTE
The rear polariser (typically) comes in three different versions: reflective, transflective and transmissive.

Reflective means there is a mirror surface behind the rear polariser. The lcd can only be used with front (i.e. ambient lighting) since no light can pass through the rear mirror.
Transmissive means there is no mirror surface behind the rear polariser and the lcd must always be used with backlighting.
Transflective is a combination of the first two. It has a partially transparent mirror so the lcd can be used with either front (ambient) light or backlight. The disadvantage is that the backlight is not as bright as for a transmissive lcd with the same backlight.


QUOTE
The Butterfly LCD is mounted on the PCB with the ATmega 169, piezo, and assorted other stuff behind it so backlighting is out. Side lighting might work if you can accept a kind of crappy light spread. I have a white LED flashlight and put the LED up to the side and it sort of works, but you'll have to try it and see.


QUOTE
Could unsolder the LCD and mount it in a socket (made from 2 times single row of pins). That will provide some additional height. Could be enough for a LED light box to fit in behind.


Wow, how would you suggest I desolder the LCD? I would be afraid of ruining the whole board. I have a tempurature controlled iron, but I don't have a hot air reworking station.


AVR_Admin- 05-10-2006
BUTTERFLY JOYSTICK USAGE:

I've been trying to use the joystick of the Butterfly for a while but I have some problems...

As I have understood in the datasheet (ATmega169), there are a lot of external interrupts (PCINTx) on PortB and PortC. The joystick is connected on these ports.

So, here is my code :

CODE
.org 0x0000
  rjmp Reset  ; Reset vector
.org 0x004
       jmp one
.org 0x006
  jmp two

.include "m169def.inc"
.def TEMP=r16
.def TIME=r17
.def VAL=r18
.def TEMP2=r19


reset:
   
 ;**Initialisation de la Stack
  ldi   TEMP,low(RAMEND)
  out   SPL,TEMP     ; Initialisation de la pile à    
  ldi   TEMP,high(RAMEND)  ; l'adresse haute de la SRAM
  out   SPH,TEMP

   ldi TIME,0xFF
  out DDRB,TIME
  out PORTE,TIME
  ldi TIME, $00
  out DDRE,TIME
  ldi TEMP,0b00000001
  sts EICRA,TEMP

  ldi TEMP,0b11000000
  out EIMSK,TEMP
  ldi TEMP,0b11111100
  sts PCMSK1,TEMP
  ldi TEMP,0xFF
  sts PCMSK0,TEMP
   
   
loop:
  rjmp loop
   
one:
  ldi TIME,0b00000001
  out PORTB,TIME
  reti
two:
  ldi TIME,0b00000010
  out PORTB,TIME
  reti


It should light up a led on PORTB1 when I push the joystick right or left and light another one up when I push it on the other directions.

It works fine with left/write but it does nothing with the other directions...
So, I tried to put another switch on PB6 and with it, it works!!

So, am I wrong with the code? Is there someting special to do with this joystick?

BTW, I hear the buzzer when leds are on... I don't know why.

QUOTE
I am trying to program a Butterfly with WinAVR and i managed to use the up and down directions and not the left right. well there is nothing special i think that you have to do. just pull them up before using them. the buzzer is connected to PORTB5, so probably you done sth to that pin.



QUOTE
The only problem with the schematics is that it doesn't tell you which direction is connected to which port pin. I had made some notes at one time (used the trusty ole DVM) but now I can't find the damn notes. Anyway, a few minutes with a DVM is all you need.

BTW, it would have been nice if Atmel had put a little extra effort into the Joystick section of the above manual and included which directions are connected to which port pins. But maybe I missed this somewhere in that manual, in which case I apologize for whining
.

Yes, I think there is no enough docs about the butterfly!
I've already looked at the document and thanks for the buzzer! I disabled PB5 and I don't hear it anymore

But for the interrupt, it still doesn't work!
I've changed my code :

CODE
.org 0x0000
  rjmp Reset  ; Reset vector
.org 0x0004
  jmp one

.org 0x0006
  jmp two

.include "m169def.inc"
.def TEMP=r16
.def TIME=r17
.def VAL=r18
.def TEMP2=r19


reset:
   
 ;**Initialisation de la Stack
  ldi   TEMP,low(RAMEND)
  out   SPL,TEMP     ; Initialisation de la pile à    
  ldi   TEMP,high(RAMEND)  ; l'adresse haute de la SRAM
  out   SPH,TEMP

  ldi TEMP,0b11000000
  out EIMSK,TEMP

  ldi TEMP,0b11010000
  sts PCMSK1,TEMP

  ldi TEMP,0b00001100
  sts PCMSK0,TEMP

  ldi TEMP,0b11010111
  out DDRB,TEMP
  ldi TEMP,0b00000100
  out PORTB,TEMP
  ldi TEMP,0b00001100
  sei
   
loop:
  rjmp loop
   
one:
  ldi TIME,0b00000101
  out PORTB,TIME
  reti
two:
  ldi TIME,0b00000110
  out PORTB,TIME
  reti



But it's still the same : With left/right, ok but with up/down, nothing!
Nothing? No! In fact, it works only the first time, when I push up the joystick, PB2 light on but after, I can't get any interrupt from it.
But with an external switch, it's ok !

QUOTE
Your code makes PB4,PB6 and PB7 outputs - you need to have them be inputs. You also need pullup enabled for them (and for PE2, PE3).


Oh yes!!! Thanks a lot! You've found my problem : PULLUPS!
Here is what I put :

CODE
  ldi TEMP,0b11010000
  out PORTB,TEMP
  ldi TEMP,0b00001100
  out PORTE,TEMP


And it works! Thanks again!



Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.