Arduino library for WTV020-SD-16P audio module

ntmcguff:
Here is my example of a Star Wars Blaster with 8 RGB LEDs, 3 74HC595 shift registers and the WTV020-SD-16P sound card. The sound files are from onesky.

74HC595 shift registers wiring: http://www.arduino.cc/en/Tutorial/ShiftOut

Blaster4 - YouTube

//  Name    : Blaster4                                          //

//  Author  : Norman McGuffey                                   //
//  Date    : 16 Feb 2013                                       //
//  Version : 1.0                                               //
//  Notes   : Code for using 3 74HC595 Shift Registers with     //
//          : 8 - 5mm Superbright CC RGB LEDs on E-11 Blaster   //
//          : Sound using WTV020-SD-16P microSD audio module    //

int resetPin2 = 2;  // Pin D2 connected to WTV20 /Reset (Pin 1)
int clockPin2 = 3;  // Pin D3 connected to WTV20 P04 (clock)(Pin 7)
int dataPin2 = 4;   // Pin D4 connected to WTV20 P05 (data)(Pin 10)
int button1Pin = 6; // Pin D6 connected to Trigger Switch
int button2Pin = 7; // Pin D7 connected to Select Switch
int latchPin = 8;   // Pin D8 connected to ST_CP (PIN 12)of 74HC595
int dataPin = 11;   // Pin D11 connected to DS (PIN 14) of 74HC595
int clockPin = 12;  // Pin D12 connected to SH_CP (PIN 11)of 74HC595
int LEDPin = 13;    // Pin D13 connected to LED
int button1State = 0;
int button2State = 0;
int button2Count = 1;

const unsigned int VOLUME_0 = 0xFFF0;
const unsigned int VOLUME_1 = 0xFFF1;
const unsigned int VOLUME_2 = 0xFFF2;
const unsigned int VOLUME_3 = 0xFFF3;
const unsigned int VOLUME_4 = 0xFFF4;
const unsigned int VOLUME_5 = 0xFFF5;
const unsigned int VOLUME_6 = 0xFFF6;
const unsigned int VOLUME_7 = 0xFFF7;

const unsigned int PLAY_PAUSE = 0xFFFE;
const unsigned int STOP = 0xFFFF;

byte dataRED;
byte dataGREEN;
byte dataBLUE;
int dataArrayRED[] = {1,8,64,0,0,0,0,0,0};
int dataArrayGREEN[] = {0,0,0,2,16,128,0,0,0};
int dataArrayBLUE[] = {0,0,0,0,0,0,4,32,0};

void setup() {
 pinMode(clockPin2, OUTPUT);
 pinMode(dataPin2, OUTPUT);
 pinMode(resetPin2, OUTPUT);
 pinMode(LEDPin, OUTPUT);
 
 digitalWrite(clockPin2, HIGH);
 digitalWrite(dataPin2, LOW);

pinMode(latchPin, OUTPUT);
 pinMode(button1Pin, INPUT);
 pinMode(button2Pin, INPUT);
 
 digitalWrite(resetPin2, HIGH);
 delay(100);
 digitalWrite(resetPin2, LOW);
 delay(10);
 digitalWrite(resetPin2, HIGH);
 delay(100);
 delay(500);
 sendCommand(0xFFF6);

digitalWrite(LEDPin, HIGH);
 delay(50);
 digitalWrite(LEDPin, LOW);
 
 Serial.begin(9600);

}

void loop() {

button2State = digitalRead(button2Pin);
 if (button2State == HIGH) {
   sendCommand(0x000);
   button2Count = button2Count +1;
   if (button2Count > 5) {
     button2Count = 1;
   }
   for (int x=0; x < button2Count; x++){
      digitalWrite(LEDPin, HIGH);
      delay(100);
      digitalWrite(LEDPin, LOW);
      delay(200);
   }
   delay(500);
   }
 
 button1State = digitalRead(button1Pin);
 
 if (button1State == HIGH) {    
  switch (button2Count) {
  case 1:
     { // Color = Red
     sendCommand(0x001);
     int dataArrayRED[] = {1,8,64,0,0,0,0,0,0};
     int dataArrayGREEN[] = {0,0,0,2,16,128,0,0,0};
     int dataArrayBLUE[] = {32,32,32,32,32,32,36,32,0};
     for (int j = 0; j < 9; j++) {
        dataRED = dataArrayRED[j];
        dataGREEN = dataArrayGREEN[j];
        dataBLUE = dataArrayBLUE[j];
        digitalWrite(latchPin, 0);
        shiftOut(dataPin, clockPin, dataBLUE);
        shiftOut(dataPin, clockPin, dataGREEN);  
        shiftOut(dataPin, clockPin, dataRED);
        digitalWrite(latchPin, 1);
        delay(60);}
      break;}
 case 2:
      { // Color = Blue
      sendCommand(0x002);
      int dataArrayRED[] = {4,32,0,0,0,0,0,0,0};
      int dataArrayGREEN[] = {0,0,1,8,64,0,0,0,0};
      int dataArrayBLUE[] = {128,128,128,128,128,130,144,128,0};
      for (int j = 0; j < 9; j++) {
        dataRED = dataArrayRED[j];
        dataGREEN = dataArrayGREEN[j];
        dataBLUE = dataArrayBLUE[j];
        digitalWrite(latchPin, 0);
        shiftOut(dataPin, clockPin, dataBLUE);
        shiftOut(dataPin, clockPin, dataGREEN);  
        shiftOut(dataPin, clockPin, dataRED);
        digitalWrite(latchPin, 1);
        delay(100);}
      break;}
   case 3:
      { // Color = Green
      sendCommand(0x003);
      int dataArrayRED[] = {2,16,128,0,0,0,0,0,0};
      int dataArrayGREEN[] = {0,0,0,4,32,0,0,0,0};
      int dataArrayBLUE[] = {64,64,64,64,64,65,72,64,0};
      for (int j = 0; j < 9; j++) {
        dataRED = dataArrayRED[j];
        dataGREEN = dataArrayGREEN[j];
        dataBLUE = dataArrayBLUE[j];
        digitalWrite(latchPin, 0);
        shiftOut(dataPin, clockPin, dataBLUE);
        shiftOut(dataPin, clockPin, dataGREEN);  
        shiftOut(dataPin, clockPin, dataRED);
        digitalWrite(latchPin, 1);
        delay(90);}
      break;}
   case 4:
      { // Color = Purple
      sendCommand(0x004);
      int dataArrayRED[] = {5,40,64,0,0,0,0,0,0};
      int dataArrayGREEN[] = {0,0,1,10,80,128,0,0,0};
      int dataArrayBLUE[] = {160,160,160,160,160,162,180,160,0};
        for (int j = 0; j < 9; j++) {
        dataRED = dataArrayRED[j];
        dataGREEN = dataArrayGREEN[j];
        dataBLUE = dataArrayBLUE[j];
        digitalWrite(latchPin, 0);
        shiftOut(dataPin, clockPin, dataBLUE);
        shiftOut(dataPin, clockPin, dataGREEN);  
        shiftOut(dataPin, clockPin, dataRED);
        digitalWrite(latchPin, 1);
        delay(90);}
      break;}
   case 5:
      { // Color = Orange
      sendCommand(0x005);
      int dataArrayRED[] = {3,24,192,0,0,0,0,0,0};
      int dataArrayGREEN[] = {0,0,0,6,48,128,0,0,0};
      int dataArrayBLUE[] = {96,96,96,96,96,97,108,96,0};
      for (int j = 0; j < 9; j++) {
        dataRED = dataArrayRED[j];
        dataGREEN = dataArrayGREEN[j];
        dataBLUE = dataArrayBLUE[j];
        digitalWrite(latchPin, 0);
        shiftOut(dataPin, clockPin, dataBLUE);
        shiftOut(dataPin, clockPin, dataGREEN);  
        shiftOut(dataPin, clockPin, dataRED);
        digitalWrite(latchPin, 1);
        delay(75);}
      break;}
  }
 }
}

void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {

int i=0;
 int pinState;
 pinMode(myClockPin, OUTPUT);
 pinMode(myDataPin, OUTPUT);

digitalWrite(myDataPin, 0);
 digitalWrite(myClockPin, 0);
 
 for (i=7; i>=0; i--)  {
   digitalWrite(myClockPin, 0);
   
   if ( myDataOut & (1<<i) ) {
     pinState= 1;
   }
   else {
     pinState= 0;
   }
   digitalWrite(myDataPin, pinState);
   digitalWrite(myClockPin, 1);
   digitalWrite(myDataPin, 0);
 }
   digitalWrite(myClockPin, 0);
}

void blinkAll_3Bytes(int n, int d) {
 digitalWrite(latchPin, 0);
 shiftOut(dataPin, clockPin, 0);
 shiftOut(dataPin, clockPin, 0);
 digitalWrite(latchPin, 1);
 delay(200);
 for (int x = 0; x < n; x++) {
   digitalWrite(latchPin, 0);
   shiftOut(dataPin, clockPin, 0);
   shiftOut(dataPin, clockPin, 0);
   shiftOut(dataPin, clockPin, 1);
   digitalWrite(latchPin, 1);
   delay(50);
   digitalWrite(latchPin, 0);
   shiftOut(dataPin, clockPin, 0);
   shiftOut(dataPin, clockPin, 0);
   shiftOut(dataPin, clockPin, 0);
   digitalWrite(latchPin, 1);
   delay(200);
 }
}
void sendCommand(int addr)
{
 digitalWrite(clockPin2, LOW);
 delay(2);
 for (int i=15; i>=0; i--)
 {
   delayMicroseconds(200);
   if((addr>>i)&0x0001 >0)
     {
       digitalWrite(dataPin2, HIGH);
      }
   else
      {
        digitalWrite(dataPin2, LOW);
      }
   delayMicroseconds(200);
   digitalWrite(clockPin2, HIGH);
   delayMicroseconds(200);
   
   if(i>0)
   digitalWrite(dataPin2, LOW);
   else
   digitalWrite(dataPin2, HIGH);
   delayMicroseconds(200);
   
   if(i>0)
   digitalWrite(clockPin2, LOW);
   else
   digitalWrite(clockPin2, HIGH);
 }
 delay(30);
}

very well!
did you post your video in whitearmor forum too?
http://www.whitearmor.net/forum/topic/19322-arduino-a-cheap-board-for-e11-blaster-effects/page__st__120

onesky,

I posted on whitearmour forum in a new topic here:

Sorry I originally wrote in Spanish ( Maybe it was because of frustration =( )

In English now...

I'm so sorry to tell you about none of two modules is working at all. =(

I used THREE completelly NEW SD Kingston cards I got from:
( http://www.ebay.es/itm/221194347559?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649 )

Also a 1Gb Sandisk SD SanDisk from:
( http://www.ebay.es/itm/160983521327?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649 )

On the TWO modules I got from:
( http://www.ebay.es/itm/150916490980?ssPageName=STRK:MEWAX:IT&_trksid=p3984.m1423.l2649 )
(v.1.5 powered 3.3v from Arduino Leonardo power output).

...and nothing on the speaker, not even a single click.

I think I'll move my project to a different device (maybe the one from SparkFun).
Current ones make me feel NO confidence on them at all.

NOTE:
The TWO modules, Kingston and Sandisk SDs are available to you for running tests, just let me know...

Ciao,
Rafa.

..and then there are two of us.

I also got two modules. Tried 5 different 1GB/2GB cards. Tried both 3.3 and 5V.
Cards formatted FAT16 with SD's utilitie (and others)
Example-files copied one by one.. and in 'bulk'. Tried renaming files to 0.ad4 .. 00.ad4 and 000.ad4 - NOTHING!
Verified with osc.scope that timing for reset , clk and dta is exactly according to datasheet.
NO sound - (not even a tiny litte 'pip')

--busy-line show some kind of life as it drops for a while after sending commands.

... Time to trash this shit ? or is there a "magic" SD-card out there?

I had better luck to make a player with shiftregister 74xx595 and a R2R net.
This plays 8bits PCM files at speeds ut to 16Ksamples/sec. (interruptdriven)
Audacity converts to my req. format without a problem.

knut, Narvik, Norway

EDIT 29.3.
I am waiting for new memory cards 128K and 256K.
(since they are not to be found in Norway, they will cross the globe..)

And again, this module is VERY PESKY about the uSD card that reads. I tried a lot of them until got one that did work.

EA3BIL and knut_ny,

Have you tried the module as a stand alone and not connected to the arduino?

The module only likes SanDisk MicroSD cards. It is a little tricky getting the microSD card into the slot properly. You have to open up the card slot and place it into position. You can not just slide it in from the end.

Mine was not working with the arduino and I tried it in stand alone and got it to work. Reference wiring diagram in the previous posts. I then was successful in getting it to work with the arduino.

ntmcguff,

I noticed about how tricky is to get the card correctly positioned on it...

Yes I did try to run it on StandAlone mode (aka mp3 player), same results, no sound at all (remember two modules tested, etc...)

I finally made the decision and moved to SparkFun WTV020-SD module.
(at least this one works on StandAlone mode with ALL sd's)...

I'll keep you all up-to-date about the results on using Rebel's library with it.

hello guys

first post for me...

ive been trying to get the module working for some time today... and finally got it making sounds.
thx for all the information in this post, was very helpful!

except for the issue ive faced! Everything was hooked up correctly, formatted the sd-card (SanDisk 64mb) in fat16.. etc..

But nothing happened.. I only noticed that the busyPin-LED was glowing all the time... first i thought this might be normal, but it is not!
Even if it did react to buttons ive pressed or code changes iv made! But at that point of trying i didnt know that it aint normal, so i started looking for the problem:

  • formated the SD-card x-times
  • soldered the jumper to 5v tested, and then again back to 3.3v
  • destroyed a in ear headphone to get the speaker
  • took differend .ad4 files
  • hooked everthing up again
  • used different code snippets
  • readed every post ive found
    -....

As a last desperated try i was just pressing slighty against the bottom side(between pin 8 and 9) of the sd-card, while it was mounted into the slot.
AND, some reaction, the busyPin-LED was turning off.. as i pressed some buttons i noticed sounds...!
Finally it worked for me.. :slight_smile:

So my conclusion is, that the SD-card might not have decent contact to the module, even if it looks fitted!

Hopefully this might help someone... like your posts helped me!

Necesito una ayuda, he visto que el creador de la libreria es argentino asi que lo escribire en español para explicarme mejor y luego lo intentare traducir.

Compre este modulo:

http://letsmakerobots.com/files/WTV020_manual_V1.3.pdf

Doy por hecho que es el mismo que usan todos ustedes. Estoy intentando conectarlo de manera aislada (el punto 8.8 del datasheet)solo vcc, gnd, el led de estado, reset ,play/stop y el altavoz.
Cuando arranca parpadea el led y se mantiene encendido, el reset parece que funciona pero cuando le doy al play se escucha como ruido y se apaga el led, y un 1-2 seg mas tarde deja de sonar y se enciende el led. Se que el modulo es muy especial con las sd, he probado 4: una kingston y una scandisk de 2gb, una de 256mb y una de 4 gb tracens y con cada unos de se escucha un tipo de ruido diferente. He probado con varios altavoces y buzers, los grandes son de 8 ohmnios y 3w y 1w respectivamente.
Tambien he probado con diferentes audios, algunos ejemplos que habeis puesto aqui y otros de youtube

Otra cosa que necesito que me expliquies que es eso de los modos que viene en el datasheet. Parecen distintas formas de conectarlo pero no entiendo como el boton play/stop puede estar en diferentes pines en cada modo y sin que haya que configurarlo con algun jumper.

In english:

I´m trying to conect the module like point 8.8 of datasheet. Reset works but when a press play, led go off and i heard a noise for 1-2 second, then stop and led go on. I try with 4 differents sd (two of 2gb kingstom and scandisk, one of 256mb and other of 4gb)

I try with 2 speakers of 8 ohms and 3w and 1w, and somes buzzer and little speakers. I try with mnay audio example form hear an otrher from youtube

hi
thanx 4 adding this library it seems that it is going to help us sooo much in our project XD
but i need to learn more and understand more things about this library
i bought this https://www.sparkfun.com/products/11125
i need to control playing the content of the sd card using arduino
for example play song 1 when some action happens or song 2 when other action happens
could u help me ^___^
i will be sooo thankful :slight_smile: :blush:

Hi,
I may be being thick here but can anybody send me a download link for this library.

Thanks :slight_smile:

It's attached to the first post on the first page of this thread.

rulicos:
I´m trying to conect the module like point 8.8 of datasheet. Reset works but when a press play, led go off and i heard a noise for 1-2 second, then stop and led go on. I try with 4 differents sd (two of 2gb kingstom and scandisk, one of 256mb and other of 4gb)

I try with 2 speakers of 8 ohms and 3w and 1w, and somes buzzer and little speakers. I try with mnay audio example form hear an otrher from youtube

I think ALL problems with this module are because of the power supply. SD cards need more than 3.3V to work (it's in their specification).

Using this power supply, all my problems disappeared:

wtv_power.png

Hey, Thanks for the library.

I am using Audio-Sound Breakout - WTV020SD from spark fun (https://www.sparkfun.com/products/11125), people recommend to use your library to control this module.

I first tested the model without arduino, simply grounded the play pin and it worked, I can hear sound coming from the speaker. however it didnt work with the library.

I'm not sure if I connected the right pin. according to the library, the pin 2 on arduino goes to reset on the module; pin 3 to DCLK, pin 4 to DIN, pin 5 to BUSY. and connect VCC to external 5v power.

is this correct?

thank you !

best

the-rebel-agent:
Welcome and you are clear to go. Just be careful about the micro SD card you are using. Got a lot of pain in the b... figuring out why mine did not work from the start.

I hope you share on that later in this thread!
Learning traps to avoid after stepping in so many is why I read so many posts!

Waytronic-Jasmine(Li):

djole_ru:
Hello!
I have a question!
How to manually change modes on vtv020-sd-16p,all ekys are on/off(loop),key 5 group of voice...
Thanks!!!

I want to ask which control mode module do you use?for example ,If you buy 2-wire series mode can not us key 5 group of voice,control mode is fixed when we program main chip,and you need tell supplier what you want,i think they will give you correct control mode module.

Please. On eBay the supplier tells little. This is typical and notice it says "MP3":

Nothing about mode. This one also uses mini-SD I don't find easily, nor adapter mini to micro-SD so this module says 'problems' to me.

I am having problems enough with the VS1003 modules I got. Yes there is software for other modules with the same chip that do almost what I want. In the meantime I have someone who wants dozens of Arduino-controlled sound players.

What I find that "works out of the box" is expensive and the rest are take your chances when buying and see how many hours before you get it to work if ever. Does that sound like any way to sell a lot of anything here?

HELLO,
this page helped me alot when I started using WTV020. i had used it as both stand alone mp3 player and interfaced with arduino (using arduino UNO and arduino mega 2560 both!). it was working pretty well. but now when I am trying to play the module, all I hear is a slight beep. nothing else. thje connections are pretty fine and so is SD card. can anyone suggest me what can be the problem? How can i get it working again! please help me out.

Kindly explain in English. I don't understand the language

I finally got mine to work. All this time is was an incompatible memory card. The data sheet should give some examples of working cards to use, that way we know what to get, the first time.