VS1053B breakout Full size SD

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
bahnlab
 
Posts: 19
Joined: Tue Aug 27, 2013 2:05 pm

VS1053B breakout Full size SD

Post by bahnlab »

Hello,
So I'm currently working on an audio project that deals with birds in boxes atm and was considering the VS1053B breakout paired up with an arduino mini to record songs the birds sing on the top of their boxes in the field then play the songs that other birds sing at their own boxes at that bird. We're using these neat little wifi SD cards to hop the audio around from box to box and that portion all works nicely, what we've got trouble with is this audio business. We've currently utterly failed at getting audio in using a geeetech breakout of the same chip, and then found the adafruit one. So... before we order them up there's two hurdles. We really can't use a micro-SD and we need to record and play songs in the same sketch. There's some forum discussion on here about trouble with recording and playback in the same sketch that seems to have just died off http://forums.adafruit.com/viewtopic.ph ... 53#p238470. I was wondering if that ever got resolved, as well as if anyone has adapted a microSD slot to work on a full size SD (which is what is available for our wifiSD cards)?

User avatar
jonlab
 
Posts: 51
Joined: Mon Jun 03, 2013 4:15 am

Re: VS1053B breakout Full size SD

Post by jonlab »

Hi !

I am using the VS1053B breakout board on my project and audio recording and playback works very well (ADPCM WAV). I had to figure out a few things, but now everything works. I posted a few about that.
I think that putting another full size SD breakout board on the same hardware SPI bus will work. You will just be using this one instead of the integrated one.

User avatar
bahnlab
 
Posts: 19
Joined: Tue Aug 27, 2013 2:05 pm

Re: VS1053B breakout Full size SD

Post by bahnlab »

Does Adafruit make a fullsize SD breakout? I don't seem to be finding one. I see the micro. So then I would just put that on the same SPI?

User avatar
jonlab
 
Posts: 51
Joined: Mon Jun 03, 2013 4:15 am

Re: VS1053B breakout Full size SD

Post by jonlab »

You need one dedicated line for your SD card, the Chip Select.
You can keep the PIN 4 (I think this is the default for SD card), just connect to the SD card instead of the "SD CS" of the VS1053B.
And all the other pins will be shared : MISO, MOSI and CLK.

User avatar
bahnlab
 
Posts: 19
Joined: Tue Aug 27, 2013 2:05 pm

Re: VS1053B breakout Full size SD

Post by bahnlab »

Just to make sure before purchasing the board (because we've had issues with other things not reading our SD cards). The wifi SD card we are using is a Toshiba Flash Air Generation 2. They are a SDHC class ten card. They aren't MMC or whatever. Here's Toshiba's spec sheet: http://www.toshiba-components.com/Flash ... ifications We were NOT able to initialize them in the other boards but we were able to get other cards to work using the Sdfat library in an arduino uno, but our situation is pretty solidly stuck with these wifi cards any idea if they will work? Also I formatted using the adafruit recommended format utility.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: VS1053B breakout Full size SD

Post by adafruit_support_mike »

I'm afraid we don't have a full-sized SD breakout, only the micro-SD size.

We do have the Data Logging Shield (http://www.adafruit.com/products/1141) which has a full-sized SD carrier and an RTC. I don't know how well that matches your needs, but it does make connections to an Arduino pretty easy.

User avatar
bahnlab
 
Posts: 19
Joined: Tue Aug 27, 2013 2:05 pm

Re: VS1053B breakout Full size SD

Post by bahnlab »

Is it possible to use the data logging shield with the VS1053B breakout logging recordings onto the SD of the datalogging shield, and playing audio off the SD of the data logging shield??

Also, the shield is for a full size Arduino. Our plan was to use an Arduino mini pro. Is it possible to connect the mini to the datalogging shield?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: VS1053B breakout Full size SD

Post by adafruit_support_mike »

You can use the Data Logger's SD card with the VS1053B, yes.

In all our designs, the SD card is basically the same independent circuit that you can use or ignore as you please. There's nothing in the code or hardware that requires the Arduino to know that the SD card circuit is on a specific piece of hardware, so it's just an anonymous data source.

WRT connecting a Pro Mini, it's possible, but would be more like mounting the Arduino on the shield than the other way around. Just ignore the pin header that comes with the shield and solder jumpers from the holes in the shield to the corresponding holes in the Pro Mini.

You might find it more convenient to solder female header into the prototyping area on the shield and plug the Arduino into that: http://www.adafruit.com/products/598. Then you could keep all the jumpers on the shield and have the Arduino as a pluggable device.

One general warning: The Pro Mini uses the ATmega168 microcontroller, which has less Flash program memory and SRAM than larger Arduinos. Keep an eye on your code size and resource usage to avoid strange hangs and crashes.

User avatar
bahnlab
 
Posts: 19
Joined: Tue Aug 27, 2013 2:05 pm

Re: VS1053B breakout Full size SD

Post by bahnlab »

Thanks for the help. I think we have everything we need to go ahead and order up the VS1053B and a datashield and begin testing.

User avatar
bahnlab
 
Posts: 19
Joined: Tue Aug 27, 2013 2:05 pm

Re: VS1053B breakout Full size SD

Post by bahnlab »

Well, things are looking good for the most part, except we've hit our first stumbling block with audio in to the SD of the datalogger.

Currently we are working with an UNO datalogger VS1053B breakout combination.

The datalogger RTC works fine, and the datalogger SD works fine, however we run into issues when using them in combination with the VS1053B.

When we hook up the VS1053B as described in the tutorial for a simple audio player (we are working up to recording). We get interesting results from the SDfat library quickstart example for testing a card. If we select pin 10 as the chip select pin then we are given info about the card inserted into the datalogger. If we on the other hand select pin 4 we are given information about the card inserted into the VS1053B.

This is great news and means that we can read from either card. There's a caveat to doing this, pin 10 is used in the simple audio player tutorials. So I pulled the CS from pin 10 and stuck it into pin 2 or 3.

Quick question about the datalogger, what pins are in use by the logger itself besides pin 10 (SD and RTC)?

Now on to recording. I am working through the example recording sketch but there is a great deal going on with a button thrown into the mix. I haven't come across what I need to do to for example record for ten seconds.
Still trying to wrap my head around what is going on in the recording sketch. No idea what this words waiting business means. Any advice from those familiar with recording on the device is welcome. I've also got a question if simultaneous recording and playback is possible? Not essential but I notice the use of interrupts in one of the sketches that allows for running other things while audio plays. What happens if I put code in there that initiates a recording (whatever that may be)?

User avatar
adafruit_support_bill
 
Posts: 88092
Joined: Sat Feb 07, 2009 10:11 am

Re: VS1053B breakout Full size SD

Post by adafruit_support_bill »

Quick question about the datalogger, what pins are in use by the logger itself besides pin 10 (SD and RTC)?
Pins 11,12 and 13 are used for SPI to the SD card. Pin 10 is the default SPI Chip Select. SDA and SCL (A4 and A5 on an UNO) are used for i2c communication to the RTC.

This chip is capable of a lot, but I'm not sure about the possibility of simultaneous recording and playback. That would be a good question for the folks at VLSI : http://www.vsdsp-forum.com/phpbb/index.php

User avatar
jonlab
 
Posts: 51
Joined: Mon Jun 03, 2013 4:15 am

Re: VS1053B breakout Full size SD

Post by jonlab »

About recording with the VS1053B, here is my journey into this :
http://forums.adafruit.com/viewtopic.php?f=19&t=50885

User avatar
bahnlab
 
Posts: 19
Joined: Tue Aug 27, 2013 2:05 pm

Re: VS1053B breakout Full size SD

Post by bahnlab »

So far I've had great success with playback on the breakout from my SD on the datalogger.

What I've not had very much luck with is the recording aspect. I've got a bit of sample code below modified from Lady Ada's and the LED blink with millis from the playground. The idea is pretty simple, record for a set interval, write that to the SD, make another recording. It's that last bit that is the hang up. I get one recording, then lots of empty .ogg recordings, same number of words, same size on the SD, same lack of data in each one. Only the first recording on powerup has anything in it. I see where jonlab had a similar issue, but with wav. I don't quite understand how to solve it, or why it happens, or that bit about DREQ not getting fully changed, or if that even applies here. I'm flummoxed?

Code: Select all

#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

// define the pins used
#define RESET 9      // VS1053 reset pin (output)
#define CS 2       // VS1053 chip select pin (output)
#define DCS 8        // VS1053 Data/command select pin (output)
#define CARDCS 10     // Card chip select pin
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin

#define REC_BUTTON 7

Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(RESET, CS, DCS, DREQ, CARDCS);

File recording;  // the file we will save our recording to
#define RECBUFFSIZE 128  // 64 or 128 bytes.
uint8_t recording_buffer[RECBUFFSIZE];


//Adapted from Blink without delay example


// Variables will change:
long previousMillis = 0;        
long currentMillis = 0;
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 30000;           // interval at which to blink (milliseconds)

void setup() {
  Serial.begin(9600);
  Serial.println("Adafruit VS1053 Ogg Recording Test");

  delay(2000);

  // initialise the music player
  if (!musicPlayer.begin()) {
    Serial.println("VS1053 not found");
    while (1);  // don't do anything more
  }

  musicPlayer.sineTest(0x44, 500);    // Make a tone to indicate VS1053 is working
 
  if (!SD.begin(CARDCS)) {
    Serial.println("SD failed, or not present");
    while (1);  // don't do anything more
  }
  Serial.println("SD OK!");
  
  // Set volume for left, right channels. lower numbers == louder volume!
  musicPlayer.setVolume(1,1);
  
  
  // load plugin from SD card! We'll use mono 44.1KHz, high quality
  if (! musicPlayer.prepareRecordOgg("v44k1q05.img")) {
     Serial.println("Couldn't load plugin!");
     while (1);    
  }
}

uint8_t isRecording = false;

void loop() {
  currentMillis = millis();
  if (!isRecording) {
    Serial.println("Begin recording");
    isRecording = true;
    
    // Check if the file exists already
    char filename[15];
    strcpy(filename, "RECORD00.OGG");
    for (uint8_t i = 0; i < 100; i++) {
      filename[6] = '0' + i/10;
      filename[7] = '0' + i%10;
      // create if does not exist, do not open existing, write, sync after write
      if (! SD.exists(filename)) {
        break;
      }
    }
    Serial.print("Recording to "); Serial.println(filename);
    recording = SD.open(filename, FILE_WRITE);
    if (! recording) {
       Serial.println("Couldn't open file to record!");
       while (1);
    }
    musicPlayer.startRecordOgg(true); // use microphone (for linein, pass in 'false')
   
  }
  if (isRecording)
    saveRecordedData(isRecording);
  if (isRecording && currentMillis - previousMillis > interval) {
    Serial.println("End recording");
    musicPlayer.stopRecordOgg();
    isRecording = false;
    // flush all the data!
    saveRecordedData(isRecording);
    // close it up
    recording.close();
    delay(1000);
    previousMillis = currentMillis;
    delay(1000);
  }  
}

uint16_t saveRecordedData(boolean isrecord) {
  uint16_t written = 0;
  
    // read how many words are waiting for us
  uint16_t wordswaiting = musicPlayer.recordedWordsWaiting();
  
  // try to process 256 words (512 bytes) at a time, for best speed
  while (wordswaiting > 256) {
    //Serial.print("Waiting: "); Serial.println(wordswaiting);
    // for example 128 bytes x 4 loops = 512 bytes
    for (int x=0; x < 512/RECBUFFSIZE; x++) {
      // fill the buffer!
      for (uint16_t addr=0; addr < RECBUFFSIZE; addr+=2) {
        uint16_t t = musicPlayer.recordedReadWord();
        //Serial.println(t, HEX);
        recording_buffer[addr] = t >> 8; 
        recording_buffer[addr+1] = t;
      }
      if (! recording.write(recording_buffer, RECBUFFSIZE)) {
            Serial.print("Couldn't write "); Serial.println(RECBUFFSIZE); 
            while (1);
      }
    }
    // flush 512 bytes at a time
    recording.flush();
    written += 256;
    wordswaiting -= 256;
  }
  
  wordswaiting = musicPlayer.recordedWordsWaiting();
  if (!isrecord) {
    Serial.print(wordswaiting); Serial.println(" remaining");
    // wrapping up the recording!
    uint16_t addr = 0;
    for (int x=0; x < wordswaiting-1; x++) {
      // fill the buffer!
      uint16_t t = musicPlayer.recordedReadWord();
      recording_buffer[addr] = t >> 8; 
      recording_buffer[addr+1] = t;
      if (addr > RECBUFFSIZE) {
          if (! recording.write(recording_buffer, RECBUFFSIZE)) {
                Serial.println("Couldn't write!");
                while (1);
          }
          recording.flush();
          addr = 0;
      }
    }
    if (addr != 0) {
      if (!recording.write(recording_buffer, addr)) {
        Serial.println("Couldn't write!"); while (1);
      }
      written += addr;
    }
    musicPlayer.sciRead(VS1053_SCI_AICTRL3);
    if (! (musicPlayer.sciRead(VS1053_SCI_AICTRL3) & _BV(2))) {
       recording.write(musicPlayer.recordedReadWord() & 0xFF);
       written++;
    }
    recording.flush();
  }

  return written;
}

User avatar
csnate
 
Posts: 1
Joined: Sat Apr 19, 2014 11:33 am

Re: VS1053B breakout Full size SD

Post by csnate »

We have successfully gotten a recording. I am working with 'bahnlab' on the project. Using an RFID reader, we want to begin recording when an RFID tag is scanned.

We need to log RFID reads and begin recording upon a tag being read. However, both of us are at a loss. Before I began working with the VS1053 codec board and attempting to implement the recording, I did have the RFID tag logging to an SD card. However, as soon as I added the ability to record, I lost the RFID logging functionality. I think it has something to do with the SD card library that either I am missing or we've hit a limitation.

I've committed a copy of what we currently have working to a bitbucket repository. The sketch is quite large, but the audio recording does work. Any help is greatly appreciated.

The link to the 'dev' branch, where we are currently working is here: https://bitbucket.org/csnate/bird-recor ... ino?at=dev

Z_R_M
 
Posts: 1
Joined: Sat Jul 05, 2014 5:44 pm

Re: VS1053B breakout Full size SD

Post by Z_R_M »

Hi, I've hit the same wall of only one recording, but here's the way out:
the manual says you have to restart the module and reload the settings. after a recording plus set a few flags - but since the good people of adafruit have already done this for us, all you need to do in order to reset is add:
musicPlayer.softReset();
after your: recording.close();
but this seems unstable it will work for a few times but with unpredictable results - you'll get files with proper size but not all will be recognized as ogg files.

the stable solution is to copy the setup function to prepare the module (it has its own reset inside):
saveRecordedData(isRecording);
// close it up
recording.close();
if (! musicPlayer.prepareRecordOgg("v44k1q05.img")) {
Serial.println("Couldn't load plugin!");
while (1);
}
this will be a stable solution that hasn't failed for me so far (well i use

p.s. you might want to play with volume of the recording in your app - since it seems you'll have different volumes from different boxes.
I recommend editing the function "Adafruit_VS1053::startRecordOgg" so that it will have:
sciWrite(VS1053_SCI_AICTRL0, 1024);
/* Rec level: 1024 = 1. If 0, use AGC */
sciWrite(VS1053_SCI_AICTRL1, 0);
/* Maximum AGC level: 1024 = 1. Only used if SCI_AICTRL1 is set to 0. */
sciWrite(VS1053_SCI_AICTRL2, AGC_level);
/* Miscellaneous bits that also must be set before recording. */
sciWrite(VS1053_SCI_AICTRL3, 0);

that way you can get a similar volume from all birds (it might matter... I don't know) play with AGC_level to get the desired level.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”