Hello everyone, im new here, and i have a task from my teacher, to do a audio recorder.
I have "Arduino UNO R3" and "VS1053 MP3 Shield" and thats all.
(Photos: Imgur: The magic of the Internet )
can anyone wrote me a code or give a link to a code.
Nobody here is going to do your homework for you.
Did you look for any examples for a VS1053 shield? What does the manufacturer of the VS1053 board you have been given have to say about their product. Do they have any examples demonstrating the boards features?
Maybe you could look at the Adafruit VS1053:
See if it is compatible with the product you have been given and maybe take a look at the Adafruit examples. There is one called record_ogg that mightbe a starting point for you.
Yes i tried this, but it gives me an error
Code:
#include <SPI.h>
#include <SD.h>
#include <Adafruit_VS1053.h>
#define VS1053_RESET_PIN 8
#define VS1053_CS_PIN 9
#define VS1053_DCS_PIN 7
#define VS1053_DREQ_PIN 1
Adafruit_VS1053 musicPlayer = Adafruit_VS1053(VS1053_RESET_PIN, VS1053_CS_PIN, VS1053_DCS_PIN, VS1053_DREQ_PIN);
void setup() {
Serial.begin(9600);
if (!SD.begin(VS1053_CS_PIN)) {
Serial.println("Error initializing SD card.");
while (1);
}
// Initialize VS1053
if (!musicPlayer.begin()) {
Serial.println("Couldn't find VS1053 on Shield!");
while (1);
}
musicPlayer.sineTest(0x44, 500); // Check sound on headphones
Serial.println("Ready to record audio.");
}
void loop() {
if (musicPlayer.stopped()) {
// If playback is stopped, start recording audio
recordAudio();
}
}
void recordAudio() {
File audioFile = SD.open("recording.wav", FILE_WRITE); // Open file for writing
if (!audioFile) {
Serial.println("Error opening file for writing!");
return;
}
Serial.println("Start recording audio...");
while (!musicPlayer.stopped()) {
if (musicPlayer.readyForData()) {
audioFile.write(musicPlayer.readRegister(Adafruit_VS1053_REG_SCI_HDAT0)); // Write audio data to file
}
}
audioFile.close();
Serial.println("Audio recording completed.");
}
Error:
C:\Users\TimonKO\AppData\Local\Temp\arduino_modified_sketch_440720\MP3Shield_Library_Demo.ino: In function 'void loop()':
MP3Shield_Library_Demo:32:19: error: 'class Adafruit_VS1053' has no member named 'stopped'
if (musicPlayer.stopped()) {
^~~~~~~
C:\Users\TimonKO\AppData\Local\Temp\arduino_modified_sketch_440720\MP3Shield_Library_Demo.ino: In function 'void recordAudio()':
MP3Shield_Library_Demo:48:23: error: 'class Adafruit_VS1053' has no member named 'stopped'
while (!musicPlayer.stopped()) {
^~~~~~~
MP3Shield_Library_Demo:50:35: error: 'class Adafruit_VS1053' has no member named 'readRegister'
audioFile.write(musicPlayer.readRegister(Adafruit_VS1053_REG_SCI_HDAT0)); // Write audio data to file
^~~~~~~~~~~~
MP3Shield_Library_Demo:50:48: error: 'Adafruit_VS1053_REG_SCI_HDAT0' was not declared in this scope
audioFile.write(musicPlayer.readRegister(Adafruit_VS1053_REG_SCI_HDAT0)); // Write audio data to file
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\TimonKO\AppData\Local\Temp\arduino_modified_sketch_440720\MP3Shield_Library_Demo.ino:50:48: note: suggested alternative: 'Adafruit_VS1053_FilePlayer'
audioFile.write(musicPlayer.readRegister(Adafruit_VS1053_REG_SCI_HDAT0)); // Write audio data to file
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Adafruit_VS1053_FilePlayer
exit status 1
'class Adafruit_VS1053' has no member named 'stopped'
and i dont know what to do with this
and i cant use any other board, only that which is on the photo
i also tried this code, it runs but it gives me an error that my SD card is not initializating:
#include <SPI.h>
#include <SD.h>
#include <Adafruit_VS1053.h>
#define VS1053_RESET_PIN 8
#define VS1053_CS_PIN 9
#define VS1053_DCS_PIN 7
#define VS1053_DREQ_PIN 1
Adafruit_VS1053 musicPlayer = Adafruit_VS1053(VS1053_RESET_PIN, VS1053_CS_PIN, VS1053_DCS_PIN, VS1053_DREQ_PIN);
void setup() {
Serial.begin(9600);
// Initializing SD-card
if (!SD.begin()) {
Serial.println("SD-card initialization error!");
while (1);
}
// Initializing VS1053
if (!musicPlayer.begin()) {
Serial.println("VS1053 MP3 Shield initialization error");
while (1);
}
// Setting volume
musicPlayer.setVolume(20, 20);
// Start recording audio
startRecording();
}
void loop() {
// Doing nothing in the endless loop
}
void startRecording() {
// Creating recording file
File recordingFile = SD.open("recording.ogg", FILE_WRITE);
if (!recordingFile) {
Serial.println("Recording file creation error!");
while (1);
}
// Preparing to record audio in Ogg format
if (!musicPlayer.prepareRecordOgg(NULL)) {
Serial.println("Recording preparation error!");
while (1);
}
// Starting recording
musicPlayer.startRecordOgg(false);
// Recording audio
while (true) {
uint16_t wordsWaiting = musicPlayer.recordedWordsWaiting();
if (wordsWaiting > 0) {
uint16_t word = musicPlayer.recordedReadWord();
recordingFile.write((uint8_t*)&word, 2);
}
if (musicPlayer.recordedWordsWaiting() == 0) {
break;
}
}
// Ending recording
musicPlayer.stopRecordOgg();
recordingFile.close();
Serial.println("Recording completed");
}
The Chip Select (i.e. CS) pin is probably not wired to the usual default pin. I did find the Geeetech web page for the VS1053. There is a schematic like this:
That would suggest that the CS pin is pin 9 rather than the default which is usually pin 10. I think you would need to change the call to SD.begin to pass the different CS pin so your code becomes:
if (!SD.begin(9)) {
Serial.println("SD-card initialization error!");
while (1);
}
Note that as pin 10 isn't being used, then it is advisable to set it as a OUTPUT pin as it would default to an INPUT pin on reset and that can cause problems with the SPI interface.
Also, looking at the schematic, I think you should define the DREQ pin as pin 2.
However, looking at the Adafruit library, there is an initialisation that takes 5 parameters rather than the 4 parameters in your Adafruit_VS1053(). The 5th parameter is the pin used for the SD card.
I fixed problems and now it starts and records sound, but when i connect external microphone via 3.5 jack, it still records sound from a its own microphone (i hope you understood)
I also tried to put false here: musicPlayer.startRecordOgg(false);
but still same problem
Do you know what to do?
It's difficult to say as I can't seem to find any real details on your VS1053 board. The Adafruit library (which is for their own VS1053 board) does take a true/false parameter in the startRecordOgg function - where true => onboard mic and false => line-in.
It may be time to ask your teacher for guidance on this specific aspect as it seems that you have the bulk of the audio recorder working.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.