how to use external flash memory with audio shield ?

Status
Not open for further replies.

emmanuel63

Well-known member
Hello,

Sorry if this question has been asked before.

I want to use an external flash memory ship (W25Q128JV) to play audio samples (SD card is not fast enough for a polyphonic player).
I have solder the ship on the audio shield.

How do I copy files on the flash memory ? Do I have to use the "copyFromSD" sketch or is there other ways to add files on the ship ?
It's the first time I use PlayFlashRaw, so any advice is welcome !

Thanks,
Emmanuel
 
I haven't done any timing tests, but I have to imagine that the flash memory is going to be roughly the same speed as a good SD card on the audio shield.

The reason is both the SD card and the flash memory use single bit SPI transfers on the audio shield. With the flash memory (and newer SD cards) you can use a quad interface (SPI4) that transfers 4 bits at a time, instead of a single bit. Unfortunately the audio shield doesn't connect all of the bits.

If you have a Teensy 3.5 or 3.6, you would want to use the built-in SD card reader instead of the one on the audio shield. If you are using the Teensy 4.0, you would need to connect the bottom 8 pins to a micro SD card reader via soldering (there are various approaches to this).

You might want to look at this thread:

As I said in the thread, I wasn't able to personally get the flash to work when using a 3.6 audio adapter to play songs. I could access the flash memory it via the Teensy Transfer tool (which until 1.49 beta 3 you could not run on the Teensy 4.0). I've been meaning to get back to it, using a Teensy 4.0 audio shield.

There is also an older link for doing the 4-bit parallel mode from some time ago. Instead of using the audio shield, you want to use an adapter that brings out all 8 pins, such as:

Here is the Teensy Transfer tool that would allow you to copy files to/from your computer to the flash memory:
 
As I said in the thread, I wasn't able to personally get the flash to work when using a 3.6 audio adapter to play songs. I could access the flash memory it via the Teensy Transfer tool (which until 1.49 beta 3 you could not run on the Teensy 4.0). I've been meaning to get back to it, using a Teensy 4.0 audio shield.
FWIW, I just soldered the flash card onto the T4 shield and it works on a T4.

Here is the Teensy Transfer tool that would allow you to copy files to/from your computer to the flash memory:
Unfortunately TeensyTransfer does not work on the Teensy 4.0. Using Teensydunio 1.49 beta 4, you can attempt to build it, since the Teensy 4.0 now has RAW HID support. But TeensyTransfer.h includes mk20dx128.h which is not available in the Teensy 4.0 environment. Since TeensyTransfer was last modified 3 years ago, it isn't surprising there isn't T4 support in it. I was able to mount the T4 audio shield on a Teensy 3.5 to run TeensyTransfer, and then move it back to the Teensy 4.0.

I did use the ListFiles serial flash example, and it did list the files.

I ran the following program and it played the files:
Code:
// Simple WAV file player example
//
// Three types of output may be used, by configuring the code below.
//
//   1: Digital I2S - Normally used with the audio shield:
//         http://www.pjrc.com/store/teensy3_audio.html
//
//   2: Digital S/PDIF - Connect pin 22 to a S/PDIF transmitter
//         https://www.oshpark.com/shared_projects/KcDBKHta
//
//   3: Analog DAC - Connect the DAC pin to an amplified speaker
//         http://www.pjrc.com/teensy/gui/?info=AudioOutputAnalog
//
// To configure the output type, first uncomment one of the three
// output objects.  If not using the audio shield, comment out
// the sgtl5000_1 lines in setup(), so it does not wait forever
// trying to configure the SGTL5000 codec chip.
//
// The SD card may connect to different pins, depending on the
// hardware you are using.  Uncomment or configure the SD card
// pins to match your hardware.
//
// Data files to put on your SD card can be downloaded here:
//   http://www.pjrc.com/teensy/td_libs_AudioDataFiles.html
//
// This example code is in the public domain.

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

AudioPlaySerialflashRaw		playRaw;

#define USE_PROP_SHIELD		0
#define USE_ANALOG_DAC		0
#define USE_ANALOG_DACS		0
#define USE_SPDIF		0
#define USE_AUDIO_SHIELD	1
#define USE_I2S			1
#define USE_AUDIO_SPI		0

// Output devices
#if USE_I2S || USE_AUDIO_SHIELD
AudioOutputI2S			audioOutput;
#if USE_AUDIO_SHIELD
AudioControlSGTL5000		sgtl5000;
#endif
#endif

#if USE_SPDIF
AudioOutputSPDIF		audioOutput;
#endif

#if USE_ANALOG_DAC || USE_PROP_SHIELD
AudioOutputAnalog		audioOutput;
#endif

#if USE_ANALOG_DACS
AudioOutputAnalogStereo		audioOutput;
#endif

AudioConnection			patchCord1 (playRaw, 0, audioOutput, 0);

// Use these with the Teensy Audio Shield
#if (USE_AUDIO_SHIELD || USE_AUDIO_SPI) && !defined(__IMXRT1062__)
#define MOSI_PIN		 7
#define SCK_PIN			14

#else
#define MOSI_PIN		11
#define SCK_PIN			13
#endif

//#define FLASH_CHIP_SELECT	 4
#define FLASH_CHIP_SELECT	 6
#define PROP_SHIELD_AUDIO	 5

void setup ()
{
  while (!Serial && millis () < 3000UL)
    ;

  Serial.begin (9600);

  //uncomment these if you have other SPI chips connected
  //to keep them disabled while using only SerialFlash
  pinMode (10, INPUT_PULLUP);

  if (MOSI_PIN != 7)
    SPI.setMOSI (MOSI_PIN);

  if (SCK_PIN != 13)
    SPI.setSCK (SCK_PIN);

  SPI.begin ();

  eeprom_initialize ();

  // Audio connections require memory to work.  For more
  // detailed information, see the MemoryAndCpuUsage example
  AudioMemory (8);

  // Comment these out if not using the audio adaptor board.
  // This may wait forever if the SDA & SCL pins lack
  // pullup resistors
#if USE_AUDIO_SHIELD
  sgtl5000.enable ();
  sgtl5000.volume (0.5f);
#endif

  // Enable the amplifier on the prop shield
#if USE_PROP_SHIELD
  pinMode (PROP_SHIELD_AUDIO, OUTPUT);
  digitalWrite (PROP_SHIELD_AUDIO, HIGH);
#endif

  Serial.printf ("MOSI = %d, SCK = %d, CS = %d%s%s%s%s%s%s%s\n",
		 MOSI_PIN,
		 SCK_PIN,
		 FLASH_CHIP_SELECT,
		 (USE_I2S || USE_AUDIO_SHIELD)		? ", i2s"		: "",
		 (USE_ANALOG_DAC || USE_PROP_SHIELD)	? ", dac"		: "",
		 USE_ANALOG_DACS			? ", dacs"		: "",
		 USE_SPDIF				? ", S/PDIF"		: "",
		 USE_AUDIO_SHIELD			? ", audio shield"	: "",
		 USE_PROP_SHIELD			? ", prop shield"	: "",
		 USE_AUDIO_SPI				? ", audio spi"		: "");

  // Start SerialFlash
  if (!SerialFlash.begin (FLASH_CHIP_SELECT)) {
    while (1)
      {
	Serial.println ("Cannot access SPI Flash chip");
	delay (1000);
      }
  }
}

void playFile (const char *filename)
{
  Serial.printf ("Playing file: %s\n", filename);

  // Start playing the file.  This sketch continues to
  // run while the file plays.
  playRaw.play (filename);

  // A brief delay for the library read WAV info
  delay (5);

  // Simply wait for the file to finish playing.
  while (playRaw.isPlaying ()) {
    // uncomment these lines if you audio shield
    // has the optional volume pot soldered
    //float vol = analogRead(15);
    //vol = vol / 1024;
    // sgtl5000_1.volume(vol);
  }
}


void loop() {
  playFile ("SDTEST1.RAW");	// filenames are always uppercase 8.3 format
  delay (500);
  playFile ("SDTEST2.RAW");
  delay (500);
  playFile ("SDTEST3.RAW");
  delay (500);
  playFile ("SDTEST4.RAW");
  delay (1500);
}


// HISTORY
// $Log: Audio_Shield_Flash_RAWplayer.ino,v $
// Revision 1.7  2019/11/14 16:42:23  michaelmeissner
// Fix typo in last change; Move SPI.begin; Add more printf
//
// Revision 1.6  2019/11/14 16:28:41  michaelmeissner
// Add option to use the audio shield SPI but not the audio shield output.
//
// Revision 1.5  2019/11/14 15:10:03  michaelmeissner
// Use correct .RAW names; add initialization; print more information.
//
// Revision 1.4  2019/11/14 14:49:46  michaelmeissner
// Add various output options.
//
// Revision 1.3  2019/11/12 16:29:14  michaelmeissner
// Reformat, add ext. flash define
//
// Revision 1.2  2019/11/11 06:40:57  michaelmeissner
// Add INPUT_PULLUP to the SD drive
//
// Revision 1.1  2019/11/11 06:24:29  michaelmeissner
// Initial version.
//
 
Hello Michael,
Thank you very much for the code, that will help me a lot.
I am able to copy files trom SD to flash memory using the "copyFromSD" sketch. I tried the teensyTransfer tool, with no success. The app freezes when open in Terminal. I am on MacOS Mojave. Looks like the app is not supported by newer OS on Mac. Or I use it the wrong way, which is very likely... Here is what I do :
- I open Teensytransfer in Terminal
- I open teensytransfertool.ino and set USB on Raw HID
- I try to compile and upload the sketch to teensy (3.2), but I get an error message (the compiler cannot access TeensyTransfer.h).

Tis is not very important since "copyFromSD" sketch is working for me, but if you have some directions to use teensy transfer tool, I will appreciate.

Thank you
Emmanuel
 
Status
Not open for further replies.
Back
Top