The Useless Machine and the Sonic Grenade

Note: this page is a work in progress (which means I'm still revising the circuit) that provides additional additional details for the following video:

Circuit Diagram

Note: since publishing the video, I've made some changes to the circuit to solve a few issues that cropped up.  First, I've replaced the MIC94091YC6 with a TPS27082LDDCR, as the MIC94091YC6 's SC-70 package was just too tedious to solder.  Also, the MIC94091YC6 includes a "discharge" feature that causes some problems in this circuit (I didn't look closely enough at the data sheet and ordered the wrong part.)  I addition, I've replaced the 1K resistor with a diode and both diodes are now just regular switching diodes, as the circuit doesn't need Schottky diodes, and changed the 1 Meg resistor (R2) to 100K.  To avoid a possible latch up issue, I've added another 100K resistor (R4) between the switch and pin 3 of the ATtiny85.  And, I've added a 100K resistor (R5) between pins 4 and 6 of the TPS27082, as required by the data sheet.  In practice, I'm fairly sure resistors R4 and R3 are probably not needed, but I added them as a precaution.

Preliminary PCB

I've sent a first cut of a PCB layout to OSH Park and should get back finished boards in a week or so, as I used the new swift service option.  The current layout (subject to change if I messed something up) is shown below and includes solder in terminal block to attach the battery pack, speaker, switch and LED.  The DF Player Mini is designed to plug into two 1x8 female headers and straddle the other parts, as the modules usually come with male headers already attached.  Resistor R1 is chosen to fit the LED you select, but should be around 200-300 Ohms.  Note: I'm using a switch that has the LED built into it and also has an internal resistor.  So, I'll just use a zero Ohm shunt as R1.

Update: 1-10-2017 - Had to revise PCB to include the 100K resistor (R5 in schematic above) to the right of the TPS27082 (again, didn't read the data sheet closely enough.)

Controlling the DF Player Mini

There are several inexpensive sound player modules available on eBay but, after experimenting with several of them, I chose the DF Player Mini because it supports playback MP3 files at a variety of sampling rates (8KHz, 11.025KHz, 12KHz, 16KHz, 22.05KHz, 24KHz, 32KHz, 44.1KHz and 48KHz), supports TF cards up to 32 GB using either FT16, or FAT32 file systems, has a built in 3 watt amplifier (with 30 volume levels) and is fairly easy to control via 9600 baud, Async Serial commands.  To help identify the DF Player Mini, here are photos of the top and bottom sides:

    

There's a lot of information about the DF Player Mini module, here.  There are several Arduino libraries available to drive it but none of them seemed to support status callbacks from the module, which I needed to detect when a sound file finishes playing.  So, I decided to just write my own code using the Arduino IDE.  The complete source code is available for download below as a zipped folder containing an Arduino .ino file.  To use the code, you'll first need to install support for the ATTiny85 microprocessor.  To do this, follow the instructions you can find, here.  It shows both how to install support for the ATtiny85, but also how to use an Arduino UNO as a programmer for the ATtiny85.  I suggest you try out and master the Blink example first to make sure you understand the process.

My code uses two C functions, sendCmd() and trackFinished(), to control and monitor the status of the DF Player Mini.  Here's the code for both of these:

byte recBuf[10];

void sendCmd (byte cmd, unsigned int arg) {

  byte sendBuf[] = {0x7E, 0xFF, 06, 00, 00, 00, 00, 00, 00, 0xEF};

  sendBuf[3] = cmd;                 // Command

  sendBuf[4] = 0;                   // 1 if ACK requested, else 0

  sendBuf[5] = (byte) (arg >> 8);   // Arg high byte

  sendBuf[6] = (byte) (arg & 0xFF); // Arg low byte

  unsigned int crc = 0;

  for (int ii = 1; ii < 7; ii++) {

    crc += sendBuf[ii];

  }

  crc = -crc;

  sendBuf[7] = (byte) (crc >> 8);   // high byte of checksum

  sendBuf[8] = (byte) (crc & 0xFF); // low byte of checksum

  for (int ii = 0; ii < sizeof(sendBuf); ii++) {

    soft.write(sendBuf[ii]);

  }

}

boolean trackFinished () {

  if (soft.available()) {

    byte cc = soft.read();

    if (recCount == 0) {

      if (cc == 0x7E) {

        recBuf[recCount++] = cc;

      }

    } else {

      recBuf[recCount++] = cc;

      if (recCount >= 10) {

        recCount = 0;

        // Verify Checksum

        unsigned int crc = 0;

        for (int ii = 1; ii < 7; ii++) {

          crc += (unsigned int) recBuf[ii] & 0xFF;

        }

        crc = -crc;

        byte crcHi = (crc >> 8) & 0xFF;

        byte crcLo = crc & 0xFF;

        if (recBuf[7] == crcHi || recBuf[8] == crcLo) {

          // CRC is OK

          if (recBuf[3] == 0x3D) {

            return true;

          }

        }

      }

    }

  }

  return false;

}

The DF Player Mini expects to receive a 10 byte command packet and sends back a nearly identical 10 byte packet to indicate status changes in the player, such as end of track, or removal or insertion of the TF card.  The code in trackFinished() only implements enough code to process the return packet that indicates the end of a track, but line that reads "if (recBuf[3] == 0x3D)" is where it checks for the end of track code.  The response code for ejecting the TF card is 0x3B and the code for inserting a TF card is 0x3A.

Generating A Shepard Tone File

While researching Shepard Tones, I came across this web site, which lets you dynamically generate a customized Shepard Tone file.  The author charges a small fee (about $5, I think) to generate a 5 minute sequence, which is what I chose to do.  To respect the authors rights, I am not publishing the file I generated so, if you chose to use the same approach for your sonic grenade, you'll need to use this site to generate your own custom file, or come up with your own alternative.  One note, the DF Player Mini and my ATtiny code expects this file to me placed in a folder off the TF card's root named "mp3" and be named 0001.mp3.

The Shepard Tone generator page is part of a whole collection of noise generator pages you can access here.  The generators available include ones for Distant Thunder, Rain Noise, Desert Wind, Orchestron and many others.  However, there is a time limit on how many generators you can sample in one session due to the bandwidth requirements of the site.