element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • Store
    Store
    • Visit Your Store
    • Choose Another Store
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
Personal Blogs
  • Members
  • More
Personal Blogs
Legacy Personal Blogs Merry Birthday to You
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: fustini
  • Date Created: 24 Jan 2012 9:04 PM Date Created
  • Views 903 views
  • Likes 1 like
  • Comments 8 comments
  • avr
  • make
  • diy
  • birthday
  • attiny
Related
Recommended

Merry Birthday to You

fustini
fustini
24 Jan 2012

Howdy,

 

I had a great time making SMD LED Christmas cards (which double as tree ornaments) back in December:

image

However, I only managed to make 3 out of 13 in time after parts and PCBs finally arrived.  My mom's birthday is today so a couple of weeks ago I decided I'd repurpose one of the remaining PCBs to make a musical Birthday card:

image

I found this card at Walgreens, and it seemed pretty fitting.  The speaker was scavenged from a different electronic Hallmark card.  I originally tried a couple piezo speakers I had in my parts bin, but it sounded much better.  The speaker leads are connected to the pads for one of the LEDs.  The board is designed with a series resistor connected to each LED.  I only had 390 ohms SMD resistors, and speaker was softer than I wanted with that resistance.  So I removed the SMD resistor, shorted that pads with solder, and then soldered a through-hole resistor between one speaker lead and LED pad.  I wish I would have taken a picture of the other side of the board as I'm having trouble remembering the value, but I believe it was 82 ohm.

 

I also soldered 4 LEDs onto the board to give a visual effect beneath the illustrated phone on the front of the card:

image

The LEDs and speaker are all controlled by the same AVR pin, so the LEDs blink in rhythm with the melody.  Unfortunately, only the yellow LED was bright enough to be seen through the card.  The tactile switch on the board is positioned under the bottom of the illustrated phone's keypad.  The Happy Birthday melody will play once when that switch is pressed, and then the chip will go to sleep until pressed again.

 

I used this source code from Nerd Kits as the basis for playing Happy Birthday:

 

http://www.nerdkits.com/videos/musicbox1/

 

However, I had to make some changes as it was written for an AVR ATtiny26 while my board uses a ATtiny13.  The challenge was to determine which delay value on the ATtiny13 generated an A5 note which is 880Hz.  I set the fuses so that that ATiny13 runs as 9.6MHz on internal RC with no clock divider.  If not already set, the fuses can be set via avrdude (note that I am using an Adafruit USBtinyISP programmer):

 

avrdude -c usbtiny -p attiny13 -i 5 -U hfuse:w:0xFF:m -U lfuse:w:0x7A:m

 

And, for reference, this is how I would compile the source code and program the AVR:

 

avr-gcc -mmcu=attiny13 -Os -o happycard.out happycard.c
avr-objcopy -O ihex -R .eeprom happycard.out happycard.hex
sudo avrdude -c usbtiny -p attiny13 -U flash:w:happycard.hex

 

The Nerdkits code uses the standard AVR libc delay functions to handle the timing of playing notes.  However, when attempting to use them in my ATtiny13 program, I ran into cryptic avr-gcc errors.  After some searching, I discovered this was an indication that I had run out of Flash memory to store the program code after linking that library.   I was surprised but the ATtiny13 is a minimalist part with only 1K flash memory and 64 bytes internal SRAM.

 

Thus, I decided would construct my own simple microsecond delay loop.  Unfortunately, I couldn't get the duration of my microsecond delay function below 1.23 microseconds (which I observed with my scope, the Rigol DS1052E).  While I may have been able to optimize it, I decided I would just modify the note definitions from the Nerd Kit source code to compensate.  I did so by copying the #define statements for the notes into a separate text file, processed with this perl one-liner and then copied the adjusted #define's back into the source code:

 

cat notes.txt | perl -ne 'chomp; ($a, $b, $c) = split(/ /); print "$a $b " . int(($c/.81)) . "\n";'

 

I then modified the source code to output just a single note, A5, and check the frequency with my scope (a DMM with a Hz function would also work).  I was within a few Hz of 880, so I was satisfied.

 

After adding all the notes back from the Nerd Kits code, I noticed the melody didn't sound quite right.  I looked up the sheet music for a happy birthday from a couple sources online and decided to adjust the duration of a couple notes accordingly.  I also added a brief break in between playing each note.  With these changes, the melody sounded much more accurate.

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

I've attached the source code, happycard.c, to this blog post.

 

 

Cheers,

Drew

http://twitter.com/pdp7

 

 

 

Attachments:
happycard.c.zip
  • Sign in to reply

Top Comments

  • mcb1
    mcb1 over 10 years ago in reply to fustini +2
    You might like the ones we get Year 7 (11/12yr olds) to put together (not the smd parts). Most of these pupils have never touched a soldering iron, but by the end of the day they have a working Tree that…
  • mcb1
    mcb1 over 10 years ago in reply to fustini +1
    Drew (Sorry didn't mark the conversation) Not at this point. They are made for Futureintech ( http://www.futureintech.org.nz/inschools.cfm ) and we have just put together the 2013 program which is 260…
  • mcb1
    mcb1 over 10 years ago +1
    Nico Nice suggestion.... The Tree is part of Futureintech that promote the uptake of technology at a tertiary level. http://www.futureintech.org.nz/inschools.cfm If E14 was to manufacture, it means the…
  • mcb1
    mcb1 over 10 years ago

    Nico

    Nice suggestion....

    The Tree is part of Futureintech that promote the uptake of technology at a tertiary level.

    http://www.futureintech.org.nz/inschools.cfm

     

    If E14 was to manufacture, it means the cost of the kits would be significantly reduced, meaning more students could be reached.

    Currently they are costing NZ$50 each, but if that was down to NZ$20-25 it means twice the number can have access to them.

     

    If there were royalties, ( hopefully a small donation per tree) they would be directed at the Futureintech program called "Project Xmas".

     

    Cheers

    mark


    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • ntewinkel
    ntewinkel over 10 years ago in reply to mcb1

    That might be a good promotional e14 item (with royalties going to Mark image) - as per another recent Thread image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 10 years ago in reply to ntewinkel

    I have the plans to make your own, but not on a pcb like this.

     

    If anyone wants a project for Xmas let me know.

     

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • ntewinkel
    ntewinkel over 10 years ago in reply to mcb1

    Those trees are really cool, Mark! (I also saw the pics on your website earlier with the kids putting them together - awesome!)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 10 years ago in reply to fustini

    Drew

    (Sorry didn't mark the conversation)

     

    Not at this point.

     

    They are made for Futureintech ( http://www.futureintech.org.nz/inschools.cfm ) and we have just put together the 2013 program which is 260 trees for 13 schools.

     

    Personally it would be great if it was something that E14 took on and then the cost to manufacture would be so much lower.

    There is a very comprehensive business plan in order to attract funding (NZ$50 each at the moment)

     

    The E14 NZ rep (David Hardy) has been asked if they can assist with some additional equipment to set up the WN/AA branch for the North island schools program, and I'm hopeful that the response will be positive.

     

    The less we have to spend, the more schools and pupils we can reach.

     

     

    Cheers

    Mark

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2023 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • Facebook
  • Twitter
  • linkedin
  • YouTube