For pleasure of my lovely near ones, I made my own DIY Christmas wish card. But I improved it with electronics. I print it twice to paper. In between of two layers of paper I added microcontroller, LEDs, LED strips and loudspeaker. And glued these together at the end. Before glueing all together, I soldered and programmed microcontroller to play beautiful song (stored in SPI Flash memory) and made some beautiful transitions of LED patterns. LEDs and LED strips are positioned to look like a decoration and chain on the Christmas tree which is shown on cover picture. Before going to details, let’s look at final result:
Inside the card, is (was) empty page. You can use it for writing personal message inside which I did before giving.
At the end of article, there is everything you need to crate your own one. You can of course adjust it and modify it. Since it is complete DIY, you can for example add family photo to it for make it even more personal.
AestheticsTemplate is not my own design. I am electronics guy, not a designer. I used free open licensed post card available at My-Free-Printable-Cards.com. You can of course use whatever template you want, including your own design. I chosen this Christmas tree because it perfectly fits to using LED strips and light bulbs.
Similarly, sound is free and comes from Pixabay.
Thank you both for sharing such beautiful resources under open licenses.
Electronics CircuitIn opposition, electronic part is solely my own work down to every single AVR instruction in firmware (no 3rd party libraries used).
Under the top layer of paper, there is hand soldered and circuit attached by adhesive tape:
While looks easy, at the end, hand soldering took me several hours. Since there is no PCB, circuit is flexible, and you can (slightly) bend the wish card. Some more detailed photos from soldering process:
Here is the schematics. You can download in PDF at the end of article. It is handy for soldering.
It contains AVR32DD20 microcontroller which drives whole circuit.
Because microcontroller DAC has not enough current capability to drive speaker directly, there is high-current ST TSB582IDT Operational Amplifier. You can use amplifier designed especially for audio applications, but I used this one for easy solderability and consider it good enough for this application. It is configured as unity gain amplifier, for reducing unnecessary components as much as possible.
LEDs and LED strips are connected to the MCU over resistors which limits current and sets their brightness. Brightness is later controller by MCU using pulse width modulation (PWM).
Because song is long and do not fit few kilobytes of MCU flash, there is external Winbond W25Q64FV SPI Flash memory which contains the song. MCU continuously read it and play it. Song is in the flash memory stored directly as WAV file. Format must be mono, 16-bit, and signed data. You can use audacity for converting audio file to this format.
For powering, there are two CR2032 batteries connected in series making about 6.5V power supply. This supply drives audio amplifier. Because MCU and Flash requires lover voltage, there is linear regulator which converts it to 3.3V for these peripherals.
Flash Memory PreparationI used W25Q SPI Flash memory of size 64 Mb which is capable of storing WAV files up to 95 second long. You can upgrade up to 128 Mb compatible Flash and approximately double sound duration capacity. Because I do not have dedicated SPI Flash programmer, I programmed it using Raspberry Pi and open-source flashrom utility. If you want to do it in the same way, follow SPI0 pinout at https://pinout.xyz/. Before soldering to circuit, I connected it using test clips to Raspberry Pi GPIOs, but if you have SOIC clips dedicated to that purpose, you can use that and save some time.
Before flashing, you need to convert audio file to WAV format, mono, 44100 Hz, 16-bit signed format as mentioned above. Once you have WAV in correct format, you need it pad it with zeroes to match capacity of flash memory. I did it using following commands:
FILE=audio_file.wav
FLASH_Mb=64
dd if=/dev/zero of="$FILE.padded" bs=$((1024 * 1024)) count=$(($FLASH_Mb / 8))
dd if="$FILE" of="$FILE.padded" conv=notrunc
flashrom -p linux_spi:dev=/dev/spidev0.0,spispeed=4096 -c "W25Q${FLASH_Mb}.V" -v "$FILE.padded"FirmwareFirmware for AVR32DD20 microcontroller is written in C. It continuously loads data from Flash and using Timer it periodically updates DAC value which play the audio song. At the same time, it adjusts LED brightness according to predefined pattern. For controlling two of them there is additional timer which generates PWM signals at different frequencies which do not interfere with sensitive audio signals. Because of limited PWM channel count limitation, rest of small SMT LEDs are driven using low-frequency PWM generated using software and not a timer. For reading FLASH memory, it uses my own small library. Firmware utilizes following MCU peripherals pretty extensively:
- PORTA – LEDs and LED strips
- PORTD – Audio signal (PD6), timing debug pin (PD7) and some SPI Flash pins are there
- PORTC – Some SPI Flash pins are there
- CLKCTRL – Uses internal 24 MHz clock source and divides it down to 12 MHz.
- TCB0 (Timer/Counter Type B) – Used for periodically generate interrupt for audio generation and LED soft PWM update purposes (approx. 44.1 kHz)
- TCD0 (Timer/Counter Type D) – Used for high frequency PWM for LED strips connected at PA4 and PA5
- DAC0 (Digital to Analog Converter) – Used for generating audio signal
- VREF (Voltage Reference) – 1.024V Voltage Reference for DAC
- SPI0 – SPI for retrieving data from Flash memory
Firmware is open source and whole code (including W25Q Flash library) is my own. You can download firmware sources as well as prebuilt HEX file at the end of this article.
Firmware FlashingFor flashing firmware to MCU you can use any UPDI programmer. If you do not have any, you can use USB-to-UART programmer and open-source pymcuprog. You can use following commands to program firmware. You need to update COM number of your USB-to-Serial adapter and you need to properly specify path to downloaded HEX file. On Linux you need to adjust both to match Linux conventions.
python -m venv .avrpyprog
.\.avrpyprog\Scripts\activate
pip install pymcuprog
pymcuprog.exe -t uart -u COM4 -d avr32dd20 write -f "C:\...\ChristmassPostcardAVR32DD20.hex" --erase –verifyClosingThank you for reading this article as far. In this article I shown Christmas wish card which I gave to my love ones. Article contains all you need to create your own. Feel free to use or modify it. At last, I would like to wish you and your friends all best in upcoming year.












Comments