-
-
Notifications
You must be signed in to change notification settings - Fork 326
Using a M5Stack Atom Echo with Audio-Tools #2202
-
Hello,
I'm new to Audio-Tools and trying to setup an intercom (walky talky) like script using ESP-NOW using the code below. Sadly i do not get any audio from the one to the other. And i have no idea what i'm missing here.
/** * @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.
All reactions
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...
Replies: 5 comments 7 replies
-
That's way too complicated to start with.
Build your sketch in steps and test each function separately: otherwise you have no clue where the issue is....
Further suggestions can be found in this Wiki
Beta Was this translation helpful? Give feedback.
All reactions
-
I have cleaned up the code above having only a button and the audio components.
Beta Was this translation helpful? Give feedback.
All reactions
-
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.
All reactions
-
@pschatzmann i hope you could me some directions.
I know it should work because i tested it using ESPHome's audio components and it works fine there.
Beta Was this translation helpful? Give feedback.
All reactions
-
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.
All reactions
-
Thanks trying to help me :D
sadly i think Chatgpt was indeed hallucinating, because it would not work :(
ps. I just noticed that in your initial sketch you never call in.begin()...
The in.begin() is called in void pressed(). Just after calling the out.end()
Beta Was this translation helpful? Give feedback.
All reactions
-
So what output did you get when you record a sine wave ?
What info is printed on your device ?
And what esp32 core are you using ?
Beta Was this translation helpful? Give feedback.
All reactions
-
And what esp32 core are you using ?
Here is some documentation about the M5Stack Atom Echo. It is a really small unit using an ESP32-PICO-D4, a SPM1423 (PDM) mic and a NS4168 (I2S) speaker DAC.
https://docs.m5stack.com/en/atom/atomecho
I have been Looking into your code and it seems you are using the pin_bclk to set the .clk value.
Looking at the schema at the above documentation. I figure out you where half right about the ws pin. Instead of using .pin_ws = 19; it should have been .pin_bclk = 33;.
auto config_in = in.defaultConfig(RX_MODE); config_in.copyFrom(info); config_out.port_no = 0; config_in.signal_type = PDM; config_in.pin_bck = 33; config_in.pin_data = 23; config_in.pin_ws = -1; in.begin(config_in);
Now i get some distorted audio using the intercom sketch. That is already a big step forward.
So what output did you get when you record a sine wave ?
I sure the output does work properly, and i did not tried to use the sine wave yet. I will try that as well to see if that is also distorted like the mic data.
What info is printed on your device ?
I'm not sure what kind of information you are looking for. Maybe you can find what you looking for on the webside above.
Beta Was this translation helpful? Give feedback.
All reactions
-
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...
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
@pschatzmann, at the moment i have all the above working.
Only to find that the mic sound is to low for my taste.
I found the that the boost API should do the trick but adding it to my script above is something i do not get how it needs to be implemented. Using the streams-audiokit-effects-audiokit.ino sketch i did the following:
I2SStream in; auto config_in = in.defaultConfig(RX_MODE); AudioEffectStream effects(in); // input from i2s SBCEncoder sbc; EncodedAudioStream encoder(&now, &sbc); // encode and write to ESP-now StreamCopy copier_in(encoder, effects); // <= this is where i'm not sure about float BoostControl = 0.1; Boost boost(BoostControl);
And i added in de setup()
// setup effects effects.addEffect(boost); effects.begin(config_in); // <= this is where i'm not sure about updateValues();
Could you confirm that i implemented it correct?
Beta Was this translation helpful? Give feedback.
All reactions
-
I found an issue with the ESPNowStream API.
When the default_send_cb() report false then the device is locked waiting for the xSemaphore to be released. Should we not always release the xSemaphore ?
Beta Was this translation helpful? Give feedback.