Quite some time ago I was blogging about the hw-627 motor controller.
So I was wondering if I could also use this module as well to play music and drive a small speaker. This would be cool because we could get stereo output since the module supports two output devices.
Here is a simple Arduino sketch which using my Audio Tools Library with an ESP32 Microcontroller:
The Arduino Sketch
#include "AudioTools.h"
#include "AudioCodecs/CodecMP3Helix.h"
#include "BabyElephantWalk60_mp3.h"
using namespace audio_tools;
MemoryStream mp3(BabyElephantWalk60_mp3, BabyElephantWalk60_mp3_len); // input
AnalogAudioStream out; // final output
EncodedAudioStream decoded(out, new MP3DecoderHelix()); // output to decoder
StreamCopy copier(decoded, mp3); // copy in to out
void setup(){
Serial.begin(115200);
AudioLogger::instance().begin(Serial, AudioLogger::Info);
// update audio info with info from decoder
decoded.setNotifyAudioChange(out);
// begin processing
auto cfg = out.defaultConfig();
out.begin(cfg);
decoded.begin();
}
void loop(){
if (mp3) {
copier.copy();
} else {
auto info = decoded.decoder().audioInfo();
LOGI("The audio rate from the mp3 file is %d", info.sample_rate);
LOGI("The channels from the mp3 file is %d", info.channels);
out.end();
stop();
}
}
The Wiring
ESP32 | HW-627 | Speaker1 | Speaker2 |
---|---|---|---|
VIN | VCC | ||
GND | GND | ||
GND | IN2 | ||
GND | IN4 | ||
3V | EEP | ||
D25 | IN1 | ||
D26 | IN3 | ||
OUT1 | + | ||
OUT2 | – | ||
OUT3 | + | ||
OUT4 | – |
After wiring everything up and deploying the sketch I was indeed getting the music playing on both speakers! You can not expect to get HIFI but nevertheless it is good to know about this solution approach…
The Source Code
The full example can be found on Github!
1 Comment
Ron · 4. May 2022 at 12:46
Maybe I’m wrong, but aren’t you restricting the movement of the speakers in one direction (pushing or pulling instead of pushing and pulling) by pulling IN2 and IN4 permanently to GND? In my opinion it would be better to use the potential of the motor-controller to generate some sort of AC-signal for the speakers