Monday, 6 March 2017

Attiny85 Flash Player

1. for her library. I am not using Adafruit trinket player .ino code but rather a basic code developed from below link. Adafruit also use an older version of Winbond memory Winbond 25Q80BV. 
2. Here is where I learn basic to play music from Attiny85

I am going into external Flash memory because using EEPROM is limited in size. 512KB is about the max in 2017 and it is way more expensive. My earlier post on SD player is big in term of physical size. I would want something similar to Attiny85 dip size.

Using Flash library for Attiny85, I choose AdaFruit over SPIFlash library because of AdaFruit very small footprint. AdaFruit sector erase and page write good enough for me.  I do have to make changes to AdaFruit library because I am using a different model of Winbond Flash. I am using the following parts

1. Attiny85 Dip.
2. SD Card adapter with soldered on DIP pins
3. Winbond W25Q64FV. It has 8 MB of memory which is enough for my 20 seconds music. A music that I intend to use on her Barney stuffed toy. If you consider 8000 bytes a second, you can play about 15 min of music on W25Q64FV.
4. A led for testing and status. There is not enough pins on Attiny85 for a led with 2 SPI device (W25Q64FV and microSD).
5. A speaker 2 pin. I made one myself from old toy. You can made one from any toy that produce sound.
6. 2 x 1.5 AA batteries. Heavy duty.

1. A transistor N2222 and 100 Ohm resister to amplify the sound.

1. petit_fatfs.h (I have made changes on it, please see my earlier post on Attiny85 SD player
2. Adafruit_TinyFlash.h (I have make changes to work for my newer Winbond flash memory)

This is the minimum components. I have added a led connected to Attiny85 PB0 (DI) pin and to the ground. It is useful to have only 1 led to see the status of the operation or testing. PB0 is also used for the SPI operation. But you can switch it to output for the Led when you need it and turn it back to SPI  function. See attached source code below. 

The circuit consists of 2 main function. 1) To read music data from microSD card in the SD card adapter and write to the W25Q64FV external Flash memory. 2) To read music data from W25Q64FV and play the speaker. 

The red mini breadboard has the external flash memory W25Q64FV and Attiny85.

The mini white breadboard has the SD adapter and speaker with transistor.

In the video, I am playing Barney I Love You which I intend to put in my daughter Barney toy. My work in electronic is driven by my daughter desire. And when I ask her if you want a barney to sing, she said, "I want a Barney also dance with me." Don't think it is possible like reaching for the moon for your daughter. :)

Source code: 

a) I have changed the Adafruit_TinyFlash.h near the top
  Adafruit_TinyFlash(uint8_t cs = 3); // used to be 3
  Adafruit_TinyFlash(uint8_t cs = 4); // used to be 3
3 is for SD card while 4 is for Flash during the write.

b) I have change the deviceID in Adafruit_TinyFlash.cpp begin function to 0x16 (see data sheet)
return ((manID == 0xEF) && (devID == 0x16)) ? CHIP_BYTES : 0L;

c) I have lengthen the erase wait time in eraseSector function
if(!waitForReady(10000L)) return false; // Datasheet says 400ms 

a) When playing, I have changed the Adafruit_TinyFlash.h near the back to 
  Adafruit_TinyFlash(uint8_t cs = 3); // used to be 3
b) I disconnect the cs line for SD card at PB3. Move the cs line for Flash from PB4 to PB3. 

I find EEPROM easier to program than external Flash memory. Flash needs to be erase before you can write on it. EEPROM does not have this requirement. EEPROM has i2C which is only 2 wire  wire Flash and SD need 4 wires SPI. Only thing is that EEPROM has very limited memory size at about 125k byte at about $5. Flash has about 8M byte at $1.50. And SD has 8G byte at $7.50. For my purpose on a small toy, I would go for Flash at the time being.

Next I will be making 1 wire LCD. It has been make but I would like to study the 595 ic used in it and the these future projects in my spare time.

Far Future Project:
1. Bluetooth to change toy music from iPhone or android
2. Play midi note to Korg TinyPiano
3. Play midi song in Korg TinyPiano and MicroPiano using Attiny85 and W25Q64FV.

No comments:

Post a Comment