Using a M5Stack Atom Echo with Audio-Tools #2202
-
Hello, /**
* @file streams-i2s-i2s-2.ino
* @brief Copy audio from I2S to I2S: We use 2 different i2s ports!
* @author Phil Schatzmann
* @copyright GPLv3
*/
#define DEFAULT_SAMPLE_RATE 16000
#define DEFAULT_CHANNELS 1
#define DEFAULT_BITS_PER_SAMPLE 16
#include <Arduino.h>
#include "AudioTools.h"
#include "AudioTools/Communication/ESPNowStream.h"
#include "Button2.h"
#define BUTTON_PIN 39
Button2 button;
AudioInfo info(16000, 1, 16);
ESPNowStream now;
const char* peers[] = { "ff:ff:ff:ff:ff:ff" };
I2SStream in;
StreamCopy copier_in(now, in); // copies sound into i2s
auto config_in = in.defaultConfig(RX_MODE);
I2SStream out;
StreamCopy copier_out(out, now); // copies sound into i2s
auto config_out = out.defaultConfig(TX_MODE);
bool in_mode = false;
void pressed(Button2& btn) {
out.end();
in.begin(config_in);
in_mode = true;
}
void released(Button2& btn) {
in.end();
out.begin(config_out);
in_mode = false;
}
// Arduino Setup
void setup(void) {
Serial.begin(115200);
auto cfg_now = now.defaultConfig();
cfg_now.broadcast_msg = true;
now.begin(cfg_now);
now.addPeers(peers);
// start I2S in
Serial.println("starting I2S...");
config_in.copyFrom(info);
config_out.port_no = 0;
config_in.signal_type = PDM;
config_in.pin_bck = 19;
config_in.pin_data = 23;
config_in.pin_ws = -1;
// start I2S out
config_out.copyFrom(info);
config_out.port_no = 1;
config_out.pin_bck = 19;
config_out.pin_data = 22;
config_out.pin_ws = 33;
config_out.channel_format = audio_tools::I2SChannelSelect::Right;
out.begin(config_out);
button.begin(BUTTON_PIN); //, INPUT, false
button.setPressedHandler(pressed);
button.setReleasedHandler(released);
out.begin(config_out);
}
// Arduino loop - copy sound to out
void loop() {
button.loop();
if (in_mode) {
copier_in.copy();
} else {
copier_out.copy();
}
} The only thing is what i hear is some clicking on the other side. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 7 replies
-
That's way too complicated to start with. |
Beta Was this translation helpful? Give feedback.
-
I have cleaned up the code above having only a button and the audio components. |
Beta Was this translation helpful? Give feedback.
-
I have minimalist the code as much as i could and tried many examples, like the "streams-i2s_pdm-serial.ino" and i do not receive any audio via the serial port. Using the following configuration: auto cfg = i2sStream.defaultConfig(RX_MODE);
cfg.copyFrom(info);
cfg.signal_type = PDM;
cfg.pin_bck = 19;
cfg.pin_data = 23;
cfg.pin_data_rx = 23;
//cfg.use_apll = false;
//cfg.auto_clear = false;
cfg.pin_ws = -1; // not used
cfg.channel_format = audio_tools::I2SChannelSelect::Right;
i2sStream.begin(cfg); When i do not set the pin_blk and pin_data i see some random data but not from the mic. |
Beta Was this translation helpful? Give feedback.
-
Since I do not know what a M5Stack Atom Echo exactly is you will need to share some more info. Usually all necessary information is printed nicely on your board. Can you provide me with a readable picture ? Did you manage to have the speaker working and you just have problems with the microphone now ? |
Beta Was this translation helpful? Give feedback.
-
I found an issue with the ESPNowStream API. |
Beta Was this translation helpful? Give feedback.
I was basically looking for the pin information and device information that is printed on the device. The URL has a diagram that provides this.
If this is working then I guess you are using a very old ESP32 core version. Check in the Arduino Board Manager, select ESP32.
The actual version is 3.3.2! With that pin_ws (=lrck) must be 33; If you record a sine wave, the Arduino Serial Plotter should show you a sine wave as well...