boarduino w/ lilypad libs, bootloader and 32.768kHz crystal

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Postby trialex » Sun Jan 27, 2008 8:56 pm

Awesome work. Have ordered a new boarduino to pretty much copy off your work!

I have done a big-ish LED display clock using an arduino. Digits are 1" high, superbright LEDs. Am using arduino-standard crystal, which means I need some tricky code to try and get the timekeeping accurate. It loses time depending on the temperature though. This is why I'm liking your project - the watch crystal I'm hoping will be more accurate. I could never work out how to set the fuses properly and still get arduino functionality - so a massive THANK YOU for spelling out all the fuse / bootloader burning steps.

My clock has the same interface issues. At the moment it just waits for the time to be sent over the serial port during the setup loop. I use a processing sketch to send the time. There are no alarms or any other input options.

The display uses a MAX7219 chip to multiplex the digits. Makes the whole thing super simple - 3 ICs (MAX232, AtMega8, MAX7219) - 6 capacitors - (4 for 232, 2 decoupling) and two resistors (Mega8 reset high, max 7219 current set)


Will take a photo tonight in the dark. Thanks again for your awesome write up.
trialex
 
Posts: 188
Joined: Mon Apr 03, 2006 5:25 pm

Postby trialex » Sun Mar 30, 2008 4:49 pm

Finally got around to taking some photos...

All lit up in a dark room...

Image

Top view...

Image

Back view...

Image

It looks AWESOME at night. The digits are 1" high, very bright.

I use USB to power it, there is no communication over USB though. There is a serial port that I used for debugging, I don't use it any more. The two buttons are for setting the time, it increments the hours and minutes as longs as the button is held during start up. Time wise it loses less than a seconds over 24 hours, which is the longest period I've had my computer switched on.

The 7 segment displays are soldered to my own custom design and etched boards, nothing special, just to go from female headers to the correct segments. The rest of the board is plain stripboard, which was easy to use because each digit is multiplexed, all seg As connected etc, so I use a wire link to connect each segment to a corresponding copper strip.

Code to follow when I've cleaned out the banned and commented it. Thanks again for your code, it kept time to within 2 minutes per 24 hours before! I guess I wasn't using the overflow function correctly when I had a 16Mhz crystal.

Next "upgrade" is to add a RTC with battery backup, so I don't have to set the time each time I turn it on.

[/img]
trialex
 
Posts: 188
Joined: Mon Apr 03, 2006 5:25 pm

Postby trialex » Fri Apr 04, 2008 3:30 am

OK here's my code

Code: Select all
/*              Alex's 7 Segment LED Clock

                Requires 32.768kHz watch crystal in place of arduino's typical 16 MHz crystal
               
                HEAVILY based on mtbf0's code from
                http://forums.ladyada.net/viewtopic.php?t=4418&start=0
                Massive thank you
               
                Use a programmer to program the fuses, use...
                avrdude -p m168 -cusbtiny -U lfuse:w:0xf2:m
                ... assuming you are using the awesome USBTiny ISP
               
                When programming from Arduino IDE use Target = Lilypad
               
                Uses Wayoda's exellent LedControl library. Library and excellent examples at
                http://www.wayoda.org/arduino/ledcontrol/index.html
               
                LED 7 segments are connected to MAX7219 chip segs A-G and digits 0-5

               
*/
#include "LedControl.h"        // Include the LedControl library
LedControl lc=LedControl(12,11,10,1); // Set up an LED object on pins 12,11,10

#define hours_adjust 14        // Input pin for hours adjust button
#define mins_adjust 15         // Input pin for minutes adjust button

int seconds_ones;
int minutes_ones;
int hours_ones;
int seconds_tens;              // Initialise values for tens and ones units of h,m,s
int minutes_tens;              // these are the values actually sent to the LEDs
int hours_tens;
volatile unsigned char tick;
unsigned char seconds = 0;
unsigned char minutes = 0;     // Inititialise actual values for h,m,s
unsigned char hours = 0;
int hours_increase = 0;
int mins_increase = 0;

ISR (TIMER2_OVF_vect) {        // When timer2 overflows...
  tick++;                      // increment tick
  display_time ();             // send the time to the LEDs to be displayed
 
}

void set_time() {              // Function for setting the time
 
  pinMode(hours_adjust,INPUT);  // Set the adjust buttons as inputs
  pinMode(mins_adjust,INPUT);
 
  hours_increase = digitalRead(hours_adjust);  // Read the adjust buttons
  mins_increase = digitalRead(mins_adjust);
 
  while(hours_increase==HIGH || mins_increase==HIGH){  // If either of the adjust buttons are high
   
    if (hours_increase==HIGH){            // Increase hours if hours button pressed
      hours = hours + 1;
    }
    if (mins_increase==HIGH){            // Increase minutes if minutes button pressed
      minutes = minutes + 1;
    }
   
    display_time();                      // Send the time to the LEDs
   
    delay(750);
    hours_increase = digitalRead(hours_adjust);   // Increase the values of hours and/or mins as necessary
    mins_increase = digitalRead(mins_adjust);
  }
}

void display_time () {                     // Function to display the time
     
    seconds_ones = seconds % 10;           // Get the 1's digit of seconds
    if (seconds>=10){                      // If seconds greater than 10
     seconds_tens = seconds / 10;}         // Get 10's digit of seconds
    else {
      seconds_tens = 0;}                   // Otherwise 10s is 0
     
    minutes_ones = minutes % 10;           // Repeat for minutes
    if (minutes>=10){
     minutes_tens = minutes / 10 ;}
    else {
      minutes_tens = 0;}
   
    hours_ones = hours % 10;               // Repeat for seconds
    if (hours>=10){
     hours_tens = hours / 10 ;}
    else {
      hours_tens = 0;} 
     
    lc.setDigit(0,0,(byte)seconds_ones,false);  // Send digits to LEDs
    lc.setDigit(0,1,(byte)seconds_tens,false);
    lc.setDigit(0,2,(byte)minutes_ones,false);
    lc.setDigit(0,3,(byte)minutes_tens,false);
    lc.setDigit(0,4,(byte)hours_ones,false);
    lc.setDigit(0,5,(byte)hours_tens,false);
}
 

void setup_timer2 () {                  // Set up function
  TCCR2A = 0;
  TCCR2B = 0;                           // stop timer
  TCNT2 = 0;                            // reset timer2 counter
  ASSR = (1 << AS2);                    // select external clock source
  TIMSK2 = (1 << TOIE2);                // enable timer2 overflow interrupt
  TCCR2B = (1 << CS22) | (1 << CS20);   // prescaler = 128, restarts timer
}

void setup () {

   setup_timer2 ();                     // Set up the timer options
   lc.shutdown(0,false);                // Turn on the LEDs
   lc.setIntensity(0,15);               // Set intensity to full
   set_time();                          // Run the time set function
}

void loop () {

if (tick) {                             // If a tick has occured
  seconds = seconds + 1;                // Increment the seconds
  tick = 0;                             // reset the tick flag
  if (seconds>59){                      // If a minute has passed
  seconds = 0;                          // Send seconds back to 0
  minutes = minutes + 1;                // Increment the minutes
  if (minutes >59){                     // If an hour has passed
    hours = hours + 1;                  // Increment the hours
    minutes = 0;                        // Send the minutes back to 0
    if (hours > 23){;                   // If a day has passed 
    hours = 0;                          // Set hours back to 0
   }
  }
}
}
}
 


Thanks again to mtbf0
trialex
 
Posts: 188
Joined: Mon Apr 03, 2006 5:25 pm

Postby Volt Dropper » Thu Apr 24, 2008 12:04 am

trialex, any updates on the accuracy of the RTC doing this?

The reason I ask is that I got a hint there was a problem and started googling. It looks like there is is an error with the datasheet and it's not real accurate without some caps.

Here's one example I found: http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=29418

(do a search on the page for 'watch')

Any comments on this appreciated.
Volt Dropper
 
Posts: 30
Joined: Wed Apr 23, 2008 11:58 pm

Postby trialex » Thu Apr 24, 2008 12:14 am

Hmm... interesting.

Well the post on AVR freaks says it loses 1 hour per year, that's

1 in (24x365 =) 8760 = 0.0114%

Using caps they say brings it to 10 mins in 1 hour.

I'm not stressed about that sort of accuracy - I never have it on for a day or two at a time at the moment.

That said, I actually do have two caps on the crystal - they are there from previous testing using a standard arduino 16MHz crystal. They are out of the suggested range at 22pf though.

I guess if you are stressed about it, definately use caps, they are small and cheap. I'm not too worried about it in mine.
trialex
 
Posts: 188
Joined: Mon Apr 03, 2006 5:25 pm

Postby Volt Dropper » Thu Apr 24, 2008 7:31 pm

From my reading it (sadly) looks like the error is more random than that thread indicated... some chips running fast, others running slow.

It becomes a problem for me because I'm making a clock. :(
Volt Dropper
 
Posts: 30
Joined: Wed Apr 23, 2008 11:58 pm

Re: boarduino w/ lilypad libs, bootloader and 32.768kHz crystal

Postby newb » Mon Jun 08, 2009 11:52 am

Just curious, if accuracy is an issue, have you considered trying to get time from a GPS signal? Or via radio from NIST?
newb
 
Posts: 1
Joined: Mon Jun 08, 2009 11:50 am

Re: boarduino w/ lilypad libs, bootloader and 32.768kHz crystal

Postby Intense » Fri Jul 10, 2009 9:55 am

Hi everybody!! This is my first post here, I'm newbe on arduino boards, but I start rocking!!! :D I used bluetooth module, SHT10 digital sensor, serial communications, pushbutton interrupts...

I have a problem using the 32.768khz crystal. I use a simple code for blink led on pin 13, it works with a 16Mhz board, I can see the led blinking fastly, and when I put the microcontroller in the other board with the 32khz crystal, it doesn't work, the led is dead. I follow in my code the steps you do for set up the timer, but I don't know what is wrong. I will thank any help you can bring me.

Greetings!!!

#include <avr/interrupt.h>
#include <avr/sleep.h>


volatile int cont;

void setup()
{
pinMode(13,OUTPUT);

TCCR2A=0;
TCCR2B = 0; // this stops the timer
TCNT2 = 0; // reset the timer2 counter
ASSR = (1 << AS2); // select watch crystal as clock source
TIMSK2 = (1 << TOIE2); // enable timer2 interrupt
TCCR2B=(1<<2)|(1<<1)|(1<<0); // set prescaler to 1024, this starts timer

//Power Save Mode
SMCR=(0<<3)|(1<<2)|(1<<1)|(0<<0);

}

ISR(TIMER2_OVF_vect)
{
cont++;
}

void loop()
{

sleep_enable();
//Turn off ADC
ADCSRA=0;
// TWI | TIMER2 | TIMER0 | VOID | TIMER1 | SPI | USART | ADC
PRR=(1<<7)|(0<<6)|(1<<5)|(1<<4)|(1<<3)|(1<<2)|(1<<1)|(1<<0);
sei();
while (cont<2)
{
//Go to Sleep
sleep_mode();
}
//Disable Sleep
sleep_disable();
//Disable interrupts
cli();
cont=0;
digitalWrite(13,!digitalRead(13));


}
Intense
 
Posts: 8
Joined: Fri Jul 10, 2009 9:17 am

Re: boarduino w/ lilypad libs, bootloader and 32.768kHz crystal

Postby mtbf0 » Fri Jul 10, 2009 10:53 am

read the sixth post in this thread for instructions on changing the fuses.

this will cause the chip to run at 8MHz. the lilypad bootloader should then be burned onto the it since the default bootloader assumes that it's running at 16MHz.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1642
Joined: Fri Nov 09, 2007 11:59 pm
Location: oakland ca

Re: boarduino w/ lilypad libs, bootloader and 32.768kHz crystal

Postby Intense » Fri Jul 10, 2009 12:04 pm

Thank you for your help. I tried it, but when I burn the bootloader then occurs the following error: "Could not find USB device 0x1781/0xc9f" but the fact is that I can programm the board... I don't understand what is happenning!!!

Thank you!!
Intense
 
Posts: 8
Joined: Fri Jul 10, 2009 9:17 am

Re: boarduino w/ lilypad libs, bootloader and 32.768kHz crystal

Postby mtbf0 » Fri Jul 10, 2009 7:14 pm

you need an isp programmer both to burn the fuses and to burn the new bootloader. the message you got indicates that you're looking for a usbtinyisp and not finding it.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1642
Joined: Fri Nov 09, 2007 11:59 pm
Location: oakland ca

Re: boarduino w/ lilypad libs, bootloader and 32.768kHz crystal

Postby Intense » Mon Jul 13, 2009 3:41 am

Thank you. I'm looking for build one!!!

Greetings.
Intense
 
Posts: 8
Joined: Fri Jul 10, 2009 9:17 am

Re: boarduino w/ lilypad libs, bootloader and 32.768kHz crystal

Postby Intense » Tue Jul 14, 2009 6:32 am

Hi again!!! I've built one ICSP programmer using parallel port. The scheme is in the next link, but changing the ISP (10 pins) connector with an ICSP (6 pins) for the arduino:

http://wiredworld.tripod.com/tronics/atmel_isp.html

The pinout for the ICSP connector is:

1 -> MISO
2 -> VCC
3 -> SCK
4 -> MOSI
5 -> RST
6 -> GND

Now the problem is that I can't use it with any software: With the ponyprog, the setup is "AVR isp I/O" using parallel port and LPT1, calibrating and selecting device as Atmega168, all is right but trying to any command the answer of the programm is "Device missing or unknown device (-24)".
With the AVRdude using the command "avrdude -p m168 -P LPT1 -c pony-stk200 -U lfuse:w:0xf2:m" (I tried with more programmers) the answer is "failed to open parallel port "LPT1"".
With the AVRStudio there's no way on connecting to the programmer....
With the CodevisionAVR has another communicating error...

I don't know what more to do...
Intense
 
Posts: 8
Joined: Fri Jul 10, 2009 9:17 am

Re: boarduino w/ lilypad libs, bootloader and 32.768kHz crystal

Postby adafruit » Tue Jul 14, 2009 1:37 pm

this forum is for boarduino kit issues
you are having a basic "i dont know how to wire up & program avrs" issue
you will probably get more responses if you post in the Microcontrollers Help forum
User avatar
adafruit
 
Posts: 10491
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

Re: boarduino w/ lilypad libs, bootloader and 32.768kHz crystal

Postby Intense » Wed Jul 15, 2009 2:17 am

You have reason. Thank you very much your help.

Greetings!!!
Intense
 
Posts: 8
Joined: Fri Jul 10, 2009 9:17 am

PreviousNext

Return to Other Arduino products from Adafruit

Who is online

Users browsing this forum: No registered users and 1 guest

Stuff to buy from the Adafruit store and links to product documentation!


New Products [108]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[31]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[34]
LCDs & Displays[48]
Components & Parts[70]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[111]
 
Wireless[14]
Cables[62]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]