Go Down

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


Added an LCD driver. It is descended from Print so you can use LCD.print() and LCD.println() to output numbers. You can also print strings this way, but it's inefficient, better to use the provided prints(). I should override print() with the prints() code.

Here is the example sketch:

Code: [Select]

#include <butterfly_temp.h>
#include <LCD_Driver.h>
#include <timer2_RTC.h>

void setup()
 // Print a string from program memory. Faster than print,
 // and uses less ram than prints
 delay( 3000 );
 // Print a string from RAM. Faster than print, and can
 // print strings that are not set at compile time.
 LCD.prints("TEMP Sensor");
 delay( 3000 );
 // Set up the RTC timer to call the secTick() function every second.
 Timer2RTC::init( secTick );

void secTick()
 // print() and println() functions can also be used to print
 // strings, and are not as efficient as prints(). However, both
 // will append to whatever is on the display. println() will cause
 // the display to be cleared before the next character is printed.
 LCD.print( TempSense.getTemp(FAHRENHEIT) );
 LCD.println( " F" );

void loop()

Nick Lott

Dec 24, 2008, 08:01 am Last Edit: Dec 24, 2008, 04:02 pm by Brokentoaster Reason: 1
Nice work Dave. Sorry I had some last minute deadlines for work and my website got hacked which left me with no free time at all this last week or so.

I will check the code on my mac an make sure we are all still working.

[edit]Tested it and it all seems to work fine. Having trouble with my butterfly not erasing properly before programming but this is probably a separate issue with my setup. Keep up the great work.  :)[/edit]


I'm working on a Dataflash library and I'm looking for some opinions on what sort of interface I should give it. In keeping with Arduino project principles I want to make it very easy to use, but I don't want to dumb it down too much.

I can of course expose the basic routines for power users to have direct access, but what are some ideas for a simpler interface for beginners?

Nick Lott

I'd like the library to be able to (if the user wants) take care of things like using the rom evenly i.e remembering the page last written when the application first started and also using the buffers effectively.

I guess the usefulness of that all depends on the application. In my butterfly logger application I've always meant to keep a record of the page last written in the eeprom so everytime I reboot the device or reconfigure the code it doesn't write to the first page of flash each time.

I normally select a page and write to the buffer until it is full. When I reach the end of a buffer I write the buffer to the flash and read the next page into the buffer.

The chip on the butterfly has 2 buffers which each can hold a page of rom. You could write a library routine that only writes /flushes the data to the rom when needed, i.e. you have reached end of page in a sequential write or you have started working on a different page in memory.

I would think one of the best things a library could do for a new user is abstract away from these details so you can simply read and write to any address in flash and the library will handle the writing efficiently, avoiding unnecessarily rewriting the same page in flash.

how does something like the following look

Code: [Select]
flash.read(page, addr, *data,length) // read length bytes from page into memory at data
flash.write(page,addr, *data,length) // write length bytes from memory at data into memory
flash.writebyte(page,addr,byte) // write byte at addr in current page
flash.readbyte(page,addr)  // read byte at addr in current page
flash.flush // write the current buffer to flash

Hope this gives you some ideas. If you wanted you could even remove the whole ideas of pages and use a linear address space across the rom. Let me know if you want me to test it :) . Love the cricket example by the way. nice work.


you could implement a next fit or best fit algorithm. (http://www.developerfusion.com/article/5540/bin-packing/5/)

just my 2 cents... sunny

Go Up