
MAX9814
這個(gè)示例是用MAX9814進(jìn)行錄音,并生成一個(gè)wav文件保存到SD上。如果用ESP8266可以不使用SD卡模塊直接將文件存到云。
BOM
- MAX9814 模塊
- MicroSDCard 模塊
- Arduino Uno
線路圖

電路圖
代碼
這里我使用了一個(gè)叫TMRpcm的庫(kù),這個(gè)庫(kù)在Arduino上非常好用,它本來(lái)是做軟DAC用的,可以用來(lái)擴(kuò)展Arduino進(jìn)行直接的聲音解碼播放。另外TMRpcm里面還有一個(gè)用于錄音的方法,源碼中是被注釋掉的,在安裝該庫(kù)之后需要打開(kāi)源碼庫(kù)中的pcmConfig.h文件將以下的行取消注釋,否則會(huì)編譯不通過(guò):
#define buffSize 128. May need to increase.
#define ENABLE_RECORDING
#define BLOCK_COUNT 10000UL
以下是 Arduino 代碼:
#include <SD.h>
#include <SPI.h>
#include <TMRpcm.h>
#define SD_ChipSelectPin 10 //using digital pin 4 on arduino nano 328, can use other pins
TMRpcm audio; // create an object for use in this sketch
void setup() {
audio.speakerPin = 4;
Serial.begin(115200);
if (!SD.begin(SD_ChipSelectPin)) {
Serial.println("SD Fail");
return;
}else{
Serial.println("SD OK");
}
// The audio library needs to know which CS pin to use for recording
audio.CSPin = SD_ChipSelectPin;
}
void loop() {
if(Serial.available()){ //Send commands over serial to play
char c = Serial.read();
Serial.println(c);
switch(c){
case 'r': audio.startRecording("test.wav",16000,A0); break; //Record at 16khz sample rate on pin A0
case 'R': audio.startRecording("test.wav",16000,A0,1); break; //Record, but with passthrough to speaker.
case 't': audio.startRecording("test.wav",16000,A0,2); break; //Do not record. Output direct to speaker
//Note: If samples are dropped before writing, it
// will not be heard in passthrough mode
case 's': audio.stopRecording("test.wav"); break; //Stop recording
case 'p': audio.play("test.wav"); break; //Play the recording
case '=': audio.volume(1); break; //Increase volume by 1. Does not affect recording
case '-': audio.volume(0); break; //Decrease volume by 1. Does not affect recording
case 'S': audio.stopPlayback(); break; //Stop all playback
}
}
}