Digistump Forums

The Oak by Digistump => Oak Projects => Topic started by: postuma on May 16, 2016, 06:25:46 pm

Title: Oak with the WT588D audio module
Post by: postuma on May 16, 2016, 06:25:46 pm
working on a project to play designated sound files (WAV format only) via the Digistump Oak. Found the Waytronic WT588D module on eBay for a couple of bucks, which outputs files or playlists to either a 0.5W external speaker via PWM, or to amplification via DAC. It's pretty versatile, and output quality is good.

The version I'm using has 8 Mbit of flash, is smaller than the Oak, but does require an external programmer:

(http://www.ars-informatica.ca/eclectic/wp-content/uploads/2016/04/WT588D-16.jpg)

Note that other versions are available: a USB version that does not require the external programmer, costs about a dollar more, and had 32 Mbit flash. Downside: it's larger.

There's some tricks involved in programming this module, so I've detailed the process on my blog: http://www.ars-informatica.ca/eclectic/programming-the-wt588d-sound-module-part-1/ (http://www.ars-informatica.ca/eclectic/programming-the-wt588d-sound-module-part-1/)

I'm using it in one-line serial mode, only using two of the Oak's lines out: VCC to supply it, and a single pin for control. You may wish to dedicate another pin in to pick up the BUSY signal, or one to RESET.

(http://www.ars-informatica.ca/eclectic/wp-content/uploads/2016/05/WT588D-with-oak-fritzing-one-line-serial-1.jpg)

(http://www.ars-informatica.ca/eclectic/wp-content/uploads/2016/04/WT588D-1-line-serial.png)

and the code:

Code: [Select]
/*
Very basic example, WT588D Audio Module in one-line serial mode, controlled by the Digistump Oak
It cycles continuously through 5 sound files, defined by the AudioSequenceID, referred to as an Equation in the VoiceChip software

Neither the RESET or BUSY pins are required for this example, though can of course be used
*/

#define WT588D_DATA   6

byte AudioSequenceID = 0;
byte i;


void setup() {
  pinMode(WT588D_DATA, OUTPUT);
  setVolume(7);                           //set volume level from 0 to 7
}


void loop() {
  WT588DCommand(AudioSequenceID);
  AudioSequenceID++;
  if (AudioSequenceID == 5) AudioSequenceID = 0;
  delay(1500);                            //pause between audio play commands
}


void WT588DCommand(byte WTbyte) {
  digitalWrite(WT588D_DATA, 0);           //pull DATA low to wake up chip, 2-10 msec
  delay(5);

  for( i = 0; i < 8; i++)  {              //read each bit of the AudioSequenceID, and write to data pin
    if (bitRead(WTbyte, i)) {
      digitalWrite(WT588D_DATA, 1);       //then write to data pin
      delayMicroseconds(400);             //2:1 high/low indicates high
      digitalWrite(WT588D_DATA, 0);
      delayMicroseconds(200);
    }
    else {
      digitalWrite(WT588D_DATA, 1);
      delayMicroseconds(200);             //and 1:2 high/low indicates low
      digitalWrite(WT588D_DATA, 0);
      delayMicroseconds(400);
    }
  }
  digitalWrite(WT588D_DATA, 1);
}


void setVolume(byte i) {                  //takes a value of 0-7 for volume control
  WT588DCommand(i+224);         
}
Title: Re: Oak with the WT588D audio module
Post by: postuma on May 18, 2016, 05:11:12 pm
small update: code update to add routines to increase and decrease volume, loop through audio files or playlists, and stop audio.

Code: [Select]
/*
Very basic example, WT588D Audio Module in one-line serial mode, controlled by the Digistump Oak
It cycles continuously through 5 sound files, defined by the AudioSequenceID, referred to as an Equation in the VoiceChip software

Neither the RESET or BUSY pins are required for this example, though can of course be used
*/

#define WT588D_DATA   6

byte AudioSequenceID = 0;
byte volume = 7;                         //set volume level from 0 to 7
byte i;


void setup() {
  pinMode(WT588D_DATA, OUTPUT);
  setVolume(volume);
}


void loop() {
  WT588DCommand(AudioSequenceID);
  AudioSequenceID++;
  if (AudioSequenceID == 5) AudioSequenceID = 0;
  delay(1500);                            //pause between audio play commands
}


void WT588DCommand(byte WTbyte) {
  digitalWrite(WT588D_DATA, 0);           //pull DATA low to wake up chip, 2-10 msec
  delay(5);

  for( i = 0; i < 8; i++)  {              //read each bit of the AudioSequenceID, and write to data pin
    if (bitRead(WTbyte, i)) {
      digitalWrite(WT588D_DATA, 1);       //then write to data pin
      delayMicroseconds(400);             //2:1 high/low indicates high
      digitalWrite(WT588D_DATA, 0);
      delayMicroseconds(200);
    }
    else {
      digitalWrite(WT588D_DATA, 1);
      delayMicroseconds(200);             //and 1:2 high/low indicates low
      digitalWrite(WT588D_DATA, 0);
      delayMicroseconds(400);
    }
  }
  digitalWrite(WT588D_DATA, 1);
}


void setVolume(byte b) {                  //takes a value of 0-7 for volume control
  volume = b;
  WT588DCommand(b+224);         
}

void incVolume() {
  if (!volume >= 7) WT588DCommand(++volume);
}

void decrVolume() {
  if (!volume) WT588DCommand(--volume);
}

void loopAudio() {
  WT588DCommand(242);
}

void stopAudio() {
  WT588DCommand(254);
}
Title: Re: Oak with the WT588D audio module
Post by: postuma on May 26, 2016, 06:23:46 pm
Whoops. The loopAudio and stopAudio functions above do not work in one-line serial mode.

Other advantages with three-line serial mode, versus one-line mode:
Rather than reproduce the schematics, wiring diagram, etc. here - a link to my web site article http://www.ars-informatica.ca/eclectic/programming-the-wt588d-sound-module-part-3-three-line-serial-mode/ (http://www.ars-informatica.ca/eclectic/programming-the-wt588d-sound-module-part-3-three-line-serial-mode/)