Mic Issues - VS1053 "Music Maker" w/ Uno R3

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Mars102
 
Posts: 5
Joined: Tue Oct 18, 2022 6:41 pm

Mic Issues - VS1053 "Music Maker" w/ Uno R3

Post by Mars102 »

Hello, I’m having trouble picking up sound from microphone inputs (-/+) on my Adafruit “Music Maker.” I’m just trying to get “record_ogg” to work (I’d prefer to record WAV files though). The code works fine (what’s the $34 about?) and it’s recording fine: beep, two second pause after pressing record button, recording, plus all of the serial monitor messages). I think it’s the raw mic input (soldered wires directly to the headset microphone). I have access to a multimeter if it comes to some kinda circuitry, but only 330/10K ohm resistors. When I ‘play’ the recording back using Audacity for Mac it’s mostly static with slight ‘blips’ in the waveform when talking loudly.

I’ve some experience with the Teensy 4.0 and Audio Shield 4.0 using Audio/Bounce/Wire/TimeLib.h libraries. It’s a BANNED voice mailbox. The shield/teensy boards were directly soldered to a rotary phone mechanical hang-up switch, rotary dial, and speaker/microphone using original wiring powered by 3xAAAs.

And I’ve other questions like am I using the best library? Adafruit_VS1053.h doesn’t have WAV record functions it seems. And what’s up with requiring a plug-in for the Ogg @ 44100? I’d prefer WAV files with a slightly lower sampling rate if need be. It should function well for everything else though. Anyway, I’ve attached some photos and would appreciate any help, thanks!

P.S. - I know my wiring is atrocious... I'm working off parts I had from the first project :)

Code: Select all

/*************************************************** 
  This is an example for the Adafruit VS1053 Codec Breakout

  Designed specifically to work with the Adafruit VS1053 Codec Breakout 
  ----> https://www.adafruit.com/products/1381

  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/

// This is a very beta demo of Ogg Vorbis recording. It works...
// Connect a button to digital 7 on the Arduino and use that to
// start and stop recording.

// A mic or line-in connection is required. See page 13 of the 
// datasheet for wiring

// Don't forget to copy the v44k1q05.img patch to your micro SD 
// card before running this example!


// include SPI, MP3 and SD libraries
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

// These are the pins used for the breakout example
#define BREAKOUT_RESET  9      // VS1053 reset pin (output)
#define BREAKOUT_CS     10     // VS1053 chip select pin (output)
#define BREAKOUT_DCS    8      // VS1053 Data/command select pin (output)
// These are the pins used for the music maker shield
#define SHIELD_RESET  -1      // VS1053 reset pin (unused!)
#define SHIELD_CS     7      // VS1053 chip select pin (output)
#define SHIELD_DCS    6      // VS1053 Data/command select pin (output)

// These are common pins between breakout and shield
#define CARDCS 4     // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin

#define REC_BUTTON 0 //////////CHANGED

Adafruit_VS1053_FilePlayer musicPlayer = 
  // create breakout-example object!
  //Adafruit_VS1053_FilePlayer(BREAKOUT_RESET, BREAKOUT_CS, BREAKOUT_DCS, DREQ, CARDCS);
  // create shield-example object!
  Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_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];

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

  // 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(10,10);
  
  // when the button is pressed, record!
  pinMode(REC_BUTTON, INPUT);
  digitalWrite(REC_BUTTON, HIGH);
  
  /*/ 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() {  
  if (!isRecording && !digitalRead(REC_BUTTON)) {
    Serial.println("Begin recording");
    isRecording = true;
    musicPlayer.prepareRecordOgg("v44k1q05.img"); /////////////UPDATED
    // 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 && digitalRead(REC_BUTTON)) {
    Serial.println("End recording");
    musicPlayer.stopRecordOgg();
    isRecording = false;
    // flush all the data!
    saveRecordedData(isRecording);
    // close it up
    recording.close();
    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) & (1 << 2))) {
       recording.write(musicPlayer.recordedReadWord() & 0xFF);
       written++;
    }
    recording.flush();
  }

  return written;
}
Attachments
IMG_0170.jpg
IMG_0170.jpg (286.76 KiB) Viewed 243 times
IMG_0172.jpg
IMG_0172.jpg (276.9 KiB) Viewed 244 times
IMG_0169.jpg
IMG_0169.jpg (257.94 KiB) Viewed 244 times

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

Re: Mic Issues - VS1053 "Music Maker" w/ Uno R3

Post by adafruit_support_bill »

Have you measured the signals coming out of your handset microphone with an oscilloscope? The carbon mic BANNED used in old handsets have much much higher output voltages than a standard line-level mic output.

User avatar
Mars102
 
Posts: 5
Joined: Tue Oct 18, 2022 6:41 pm

Re: Mic Issues - VS1053 "Music Maker" w/ Uno R3

Post by Mars102 »

Hello, this is a great idea. However, the oscilloscope I had was gifted to a friend and I’m not sure I’d remember how to use it if I still had it. I attached the leads to mic - and mic + instead of Line-In because I thought it’d need amplification since it’s no longer connected to a power source of any kind. I could use the breadboard and created a closed circuit with the leads from the microphone and play around with different resisters in series and see if that’d improve or otherwise change recording quality?

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

Re: Mic Issues - VS1053 "Music Maker" w/ Uno R3

Post by adafruit_support_bill »

The carbon microphones used in most old phone handsets are quite different from a modern electret or condenser mic. You will need a power source and some additional circuitry. Here is an example: https://www.instructables.com/Telephone ... icrophone/

User avatar
Mars102
 
Posts: 5
Joined: Tue Oct 18, 2022 6:41 pm

Re: Mic Issues - VS1053 "Music Maker" w/ Uno R3

Post by Mars102 »

I will give this a shot this week and report back. Would I be better replacing the carbon mic with a tiny mic from a modern landline phone? I believe I’d use Line in on the shield as well as ground. A phone mic would (should?) have a mic with a built-in amplifier, right? I’m thinking something cheap like a VTech CD1103WH.

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

Re: Mic Issues - VS1053 "Music Maker" w/ Uno R3

Post by adafruit_support_bill »

I didn't find any specs on the VTech microphone. Your best bet would be to go with a microphone module with a line-level output like this one: https://www.adafruit.com/product/1713

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

Re: Mic Issues - VS1053 "Music Maker" w/ Uno R3

Post by adafruit_support_bill »

I didn't find any specs on the VTech microphone. Your best bet would be to go with a microphone module with a line-level output like this one: https://www.adafruit.com/product/1713

User avatar
Mars102
 
Posts: 5
Joined: Tue Oct 18, 2022 6:41 pm

Re: Mic Issues - VS1053 "Music Maker" w/ Uno R3

Post by Mars102 »

I'm able to record on Arduino Uno w/ Adafruit's "Music Maker" shield with a carbon microphone. Well, it records but quiet or loud recordings are not the best. I'll try and refine it. I've attached a photo of the circuitry - it'd be great if someone could improve on it. I used a separate circuit to eliminate noise from the Uno.
Attachments
IMG_0216 copy.jpg
IMG_0216 copy.jpg (790.79 KiB) Viewed 163 times

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

Return to “Arduino Shields from Adafruit”