Can I use simultaneously 2 Audio Analyzer with Arduino?
How do I specify Audio Analyzer 1 or 2?
Thanks
Can I use simultaneously 2 Audio Analyzer with Arduino?
How do I specify Audio Analyzer 1 or 2?
Thanks
Hth
I already went through the Audio Analyzer documentation and it does not seem the find the answer to my question.
edit. Yikes, written before or after too much of one thing and not enough of the other...
In the example sketch, this makes an audio analyzer
Analyzer Audio = Analyzer(4,5,A0); //Strobe pin ->4 RST pin ->5 Analog Pin ->A0
If you need another, name it and create it and give it its own set of pins
Analyzer anotherAudio = Analyzer(6, 7, A1); // or whatever
You could make an array of them, or live with copy/paste/editing as a naive way to grow your code.
a7
Thanks, I'm at this stage of sketch, having two Audio Analyzer objects. Now how do I extract data from each one? I'm a newbie!!!!
I suggest you find, and follow slavishly, a project involving the device. One. Get it working, work with it and get to know it.
Read that code. See how the anaylzer object is made, intialised and used.
Use the same code patterns to implement the second analyzer.
There is no better documentation than working code, sometimes. The github reposirty linked by @ruilviana has this example:
I asked an AI to strip away anything not dealing with the analyzer and told it to just use the serial monitor. If I were in the lab, I would test this. TBH if I were in the lab, I'd do the surgery myself, one gets good at cutting away the forest to be able to see the trees, so to speak, so this may not be what I want it to be:
#include <AudioAnalyzer.h> // DF Robot Audio Analyzer library
Analyzer Audio = Analyzer(4, 5, A0); // Strobe -> Pin 4, RST -> Pin 5, Analog -> A0
int FreqVal[7]; // Measured values for 7 frequency bands
void setup() {
Serial.begin(9600); // Start serial communication
Audio.Init(); // Initialize audio analyzer module
delay(100);
Serial.println("Audio Frequency Analyzer Demo (Serial Output Only)");
Serial.println("Bands: 63Hz | 160Hz | 400Hz | 1kHz | 2.5kHz | 6.3kHz | 16kHz");
}
void loop() {
Audio.ReadFreq(FreqVal); // Read 7-band frequency values
Serial.print("FreqVals: ");
for (int i = 0; i < 7; i++) {
Serial.print(FreqVal[i]);
if (i < 6) Serial.print(" | ");
}
Serial.println();
delay(100); // Add delay for readability
}
HTH
a7
Thank you,
I have already working the frequency analyser running on two OLED, my problem is how to extract data from two Audio Analyzer.
To clarify, The published Arduino Analyzer is already working, on two OLED. What I'm looking for is how to extract data from one audio channel and how to extract data from the second audio channel. I have already configured Analyzer Audio = Analyzer and Analyzer Audio = Analyzer1.
Srt sry sry, I have edited my list and hope it is now correct.
So to "extract", the line of code is here
int FreqVal[7]; // Measured values for 7 frequency bands
// and whenever you need to
Audio.ReadFreq(FreqVal); // Read 7-band frequency values
A home is made for the results, and a call to a function fills it in.
So you can make another do the same, you just have to reuse or provide another destination for the results, viz:
int FreqVal[7]; // Measured values for 7 frequency bands
int anotherFreqVal[7];
Audio.ReadFreq(FreqVal); // Read 7-band frequency values
anotherAudio.ReadFreq(anotherFreqVal);
The code is the same. I've just added more variabkes that associate themsleves in an identical manner. One is the name for the sensor, the other is the name of the array that holds its report.
a7
OIC.
Post the code! I was thinking you were without any progress. It sounds like you know more than lots more half what you need to ATM.
a7
#include <AudioAnalyzer.h>
#include "U8g2lib.h"
Analyzer Audio = Analyzer(4,5,A0);//Strobe pin ->4 RST pin ->5 Analog Pin ->5
//Analyzer Audio = Analyzer();//Strobe->4 RST->5 Analog->0
//Analyzer Audio = Analyzer1(6,7,A1);//Strobe pin ->6 RST pin ->7 Analog Pin ->5
int FreqVal[7];//
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=/ U8X8_PIN_NONE, / clock=/ 16, / data=/ 17); // ESP32 Thing, HW I2C with pin remapping
byte
//U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2a(U8G2_R0, / reset=/ U8X8_PIN_NONE, / clock=/ 16, / data=*/ 17); // ESP32 Thing, HW I2C with pin remapping
audio_bar_height[7];
byte audio_bar_peak[7];
void setup() {
// put your setup code here, to run once:
u8g2.setColorIndex(1);
Serial.begin(9600);
u8g2.begin();
Audio.Init();
Serial.begin(57600);
Audio.Init();//Init module
}
//u8g2.setBitmapMode(1);
//audio_bar_height[0] = 16;
//audio_bar_height[1] = 10;
//audio_bar_height[2] = 30;
//audio_bar_height[3] = 50;
//audio_bar_height[4] = 45;
//audio_bar_height[5] = 25;
//audio_bar_height[6] = 34;
void loop() {
// put your main code here, to run repeatedly:
Audio.ReadFreq(FreqVal);
u8g2.clearBuffer();
for (int i=0; i<7; i++){
//int random_value=random(1024);
//audio_bar_height[i]=audio_bar_height[i]+((map(random_value, 0, 1024, 0, 53)- audio_bar_height[i]) / 4.0);
audio_bar_height[i] = map(max((FreqVal[i]-100),0) ,0 , 1024, 0, 53);
if (audio_bar_peak[i] < audio_bar_height[i]){
audio_bar_peak[i] = audio_bar_height[i];
}else if (audio_bar_peak[i] > audio_bar_height[i]) {
audio_bar_peak[i]--;
}
u8g2.drawBox(2 + i19, 53- audio_bar_height[i], 10, audio_bar_height[i]);
u8g2.drawBox(2 + i19, 53 -audio_bar_peak[i],10 ,1 );
}
u8g2.setFont(u8g2_font_nerhoe_tf);
u8g2.drawStr(2, 64, "63");
u8g2.drawStr(19, 64, "160");
u8g2.drawStr(37, 64, "40");
u8g2.drawStr(60, 64, "1K");
u8g2.drawStr(75, 64, "2.5K");
u8g2.drawStr(95, 64, "6.3K");
u8g2.drawStr(115, 64, "16K");
u8g2.sendBuffer();
//U8G2.sendBuffer();
Audio.ReadFreq(FreqVal);//Return 7 values of 7 bands pass filiter
//Frequency(Hz):63 160 400 1K 2.5K 6.25K 16K
//FreqVal[]: 0 1 2 3 4 5 6
for(int i=0;i<7;i++)
{
Serial.print(max((FreqVal[i]-100),0));
if(i<6) Serial.print(",");
else Serial.println();
}
delay(20);
}
Please use the IDE Autoformat
tool on your sketch.
Then either copy the code and use the <CODE/> button you see in the message composition window toolbar here, or use the IDE Copy for Forum
tool and come back here and simply paste it.
If you want, since it's right there, just edit your last post and paste the code so it looks like code right over the code that doesn't, Then I will delete this advice!
It shpuold end up formatted, pretty and in its own block, like
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
And maybe say more about the actual problem... if what I told you hasn't helped, I don't know what will.
a7
#include <AudioAnalyzer.h>
#include "U8g2lib.h"
Analyzer Audio = Analyzer(4,5,A0);//Strobe pin ->4 RST pin ->5 Analog Pin ->5
//Analyzer Audio = Analyzer();//Strobe->4 RST->5 Analog->0
//Analyzer Audio = Analyzer1(6,7,A1);//Strobe pin ->6 RST pin ->7 Analog Pin ->5
int FreqVal[7];//
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ 16, /* data=*/ 17); // ESP32 Thing, HW I2C with pin remapping
byte
//U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2a(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ 16, /* data=*/ 17); // ESP32 Thing, HW I2C with pin remapping
audio_bar_height[7];
byte audio_bar_peak[7];
void setup() {
// put your setup code here, to run once:
u8g2.setColorIndex(1);
Serial.begin(9600);
u8g2.begin();
Audio.Init();
Serial.begin(57600);
Audio.Init();//Init module
}
//u8g2.setBitmapMode(1);
//audio_bar_height[0] = 16;
//audio_bar_height[1] = 10;
//audio_bar_height[2] = 30;
//audio_bar_height[3] = 50;
//audio_bar_height[4] = 45;
//audio_bar_height[5] = 25;
//audio_bar_height[6] = 34;
void loop() {
// put your main code here, to run repeatedly:
Audio.ReadFreq(FreqVal);
u8g2.clearBuffer();
for (int i=0; i<7; i++){
//int random_value=random(1024);
//audio_bar_height[i]=audio_bar_height[i]+((map(random_value, 0, 1024, 0, 53)- audio_bar_height[i]) / 4.0);
audio_bar_height[i] = map(max((FreqVal[i]-100),0) ,0 , 1024, 0, 53);
if (audio_bar_peak[i] < audio_bar_height[i]){
audio_bar_peak[i] = audio_bar_height[i];
}else if (audio_bar_peak[i] > audio_bar_height[i]) {
audio_bar_peak[i]--;
}
u8g2.drawBox(2 + i*19, 53- audio_bar_height[i], 10, audio_bar_height[i]);
u8g2.drawBox(2 + i*19, 53 -audio_bar_peak[i],10 ,1 );
}
u8g2.setFont(u8g2_font_nerhoe_tf);
u8g2.drawStr(2, 64, "63");
u8g2.drawStr(19, 64, "160");
u8g2.drawStr(37, 64, "40");
u8g2.drawStr(60, 64, "1K");
u8g2.drawStr(75, 64, "2.5K");
u8g2.drawStr(95, 64, "6.3K");
u8g2.drawStr(115, 64, "16K");
u8g2.sendBuffer();
//U8G2.sendBuffer();
Audio.ReadFreq(FreqVal);//Return 7 values of 7 bands pass filiter
//Frequency(Hz):63 160 400 1K 2.5K 6.25K 16K
//FreqVal[]: 0 1 2 3 4 5 6
for(int i=0;i<7;i++)
{
Serial.print(max((FreqVal[i]-100),0));
if(i<6) Serial.print(",");
else Serial.println();
}
delay(20);
}
Closer. You did not Autoformat the code.
More important just now is to explain your problem. I cannot help mot]re than to say you need a second set of everything that is involved with using one Audio Analyzer module.
A second object with a distinct name. I prepended "another" to the name of the one in the code ATM.
A second array to receive the data when requested. Again I prepended "another" to name it.
The code you posted is not
Where is that code, or post it if you wrote it.
a7
I pasted already, here is again.
```cpp
#include <AudioAnalyzer.h>
#include "U8g2lib.h"
Analyzer Audio = Analyzer(4,5,A0);//Strobe pin ->4 RST pin ->5 Analog Pin ->5
//Analyzer Audio = Analyzer();//Strobe->4 RST->5 Analog->0
//Analyzer Audio = Analyzer1(6,7,A1);//Strobe pin ->6 RST pin ->7 Analog Pin ->5
int FreqVal[7];//
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ 16, /* data=*/ 17); // ESP32 Thing, HW I2C with pin remapping
byte
//U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2a(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ 16, /* data=*/ 17); // ESP32 Thing, HW I2C with pin remapping
audio_bar_height[7];
byte audio_bar_peak[7];
void setup() {
// put your setup code here, to run once:
u8g2.setColorIndex(1);
Serial.begin(9600);
u8g2.begin();
Audio.Init();
Serial.begin(57600);
Audio.Init();//Init module
}
//u8g2.setBitmapMode(1);
//audio_bar_height[0] = 16;
//audio_bar_height[1] = 10;
//audio_bar_height[2] = 30;
//audio_bar_height[3] = 50;
//audio_bar_height[4] = 45;
//audio_bar_height[5] = 25;
//audio_bar_height[6] = 34;
void loop() {
// put your main code here, to run repeatedly:
Audio.ReadFreq(FreqVal);
u8g2.clearBuffer();
for (int i=0; i<7; i++){
//int random_value=random(1024);
//audio_bar_height[i]=audio_bar_height[i]+((map(random_value, 0, 1024, 0, 53)- audio_bar_height[i]) / 4.0);
audio_bar_height[i] = map(max((FreqVal[i]-100),0) ,0 , 1024, 0, 53);
if (audio_bar_peak[i] < audio_bar_height[i]){
audio_bar_peak[i] = audio_bar_height[i];
}else if (audio_bar_peak[i] > audio_bar_height[i]) {
audio_bar_peak[i]--;
}
u8g2.drawBox(2 + i*19, 53- audio_bar_height[i], 10, audio_bar_height[i]);
u8g2.drawBox(2 + i*19, 53 -audio_bar_peak[i],10 ,1 );
}
u8g2.setFont(u8g2_font_nerhoe_tf);
u8g2.drawStr(2, 64, "63");
u8g2.drawStr(19, 64, "160");
u8g2.drawStr(37, 64, "40");
u8g2.drawStr(60, 64, "1K");
u8g2.drawStr(75, 64, "2.5K");
u8g2.drawStr(95, 64, "6.3K");
u8g2.drawStr(115, 64, "16K");
u8g2.sendBuffer();
//U8G2.sendBuffer();
Audio.ReadFreq(FreqVal);//Return 7 values of 7 bands pass filiter
//Frequency(Hz):63 160 400 1K 2.5K 6.25K 16K
//FreqVal[]: 0 1 2 3 4 5 6
for(int i=0;i<7;i++)
{
Serial.print(max((FreqVal[i]-100),0));
if(i<6) Serial.print(",");
else Serial.println();
}
delay(20);
}
The key for what I need in this line Audio.ReadFreq(FreqVal); How to read it for the second define object AudioAnalyzer?
No. There are not two OLEDs working in this code
byte
//U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2a(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ 16, /* data=*/ 17); // ESP32 Thing, HW I2C with pin remapping
And you still don't say what your problem is. perhaps if you said what you are trying to accomplish.
I said but you seem not to have seen or understood post #4 and post #9:
anotherAudi.ReadFreq(anotherFreqVal);
Will use the second device and populate the second array.
a7
Following your provided directions I was able to build the sketch. The goal is to have a stereo Audio Analyzer. It works, I mean it runs, no syntax or compile errors, still not the desired result. The problem is a wrong loop that I cannot figure out. The displays are blinking simultaneously. Would you, please, have a look at the below code? Thanks,
#include <AudioAnalyzer.h>
#include "U8g2lib.h"
Analyzer Audio = Analyzer(4,5,A0);//Strobe pin ->4 RST pin ->5 Analog Pin ->5
//Analyzer Audio = Analyzer();//Strobe->4 RST->5 Analog->0
Analyzer AnotherAudio = Analyzer(6,7,A1);//Strobe pin ->6 RST pin ->7 Analog Pin ->5
int FreqVal[7];//
int AnotherFreqVal[7];//
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ 16, /* data=*/ 17); // ESP32 Thing, HW I2C with pin remapping
U8G2_SSD1306_128X64_NONAME_F_HW_I2C display2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ 16, /* data=*/ 17); // ESP32 Thing, HW I2C with pin remapping
byte audio_bar_height[7];
byte audio_bar_peak[7];
byte Anotheraudio_bar_height[7];
byte Anotheraudio_bar_peak[7];
void setup() {
// put your setup code here, to run once:
u8g2.setColorIndex(1);
u8g2.begin();
u8g2.setI2CAddress(0x78);
u8g2.clearDisplay();
display2.begin();
display2.setI2CAddress(0x7A);
display2.clearDisplay();
Serial.begin(57600);
Audio.Init();//Init module
}
void loop() {
// put your main code here, to run repeatedly:
Audio.ReadFreq(FreqVal);
AnotherAudio.ReadFreq(AnotherFreqVal);
display2.clearBuffer();
u8g2.clearBuffer();
for (int i=0; i<7; i++){
Anotheraudio_bar_height[i] = map(max((AnotherFreqVal[i] - 100),0) ,0 , 1024, 0, 53);
audio_bar_height[i] = map(max((FreqVal[i]-100),0) ,0 , 1024, 0, 53);
if (audio_bar_peak[i] < audio_bar_height[i]){
audio_bar_peak[i] = audio_bar_height[i];
}else if (audio_bar_peak[i] > audio_bar_height[i]) {
audio_bar_peak[i]--;
u8g2.drawBox(2 + i*19, 53- audio_bar_height[i], 10, audio_bar_height[i]);
u8g2.drawBox(2 + i*19, 53 -audio_bar_peak[i],10 ,1 );
}
u8g2.setFont(u8g2_font_nerhoe_tf);
u8g2.drawStr(2, 64, "63");
u8g2.drawStr(19, 64, "160");
u8g2.drawStr(37, 64, "40");
u8g2.drawStr(60, 64, "1K");
u8g2.drawStr(75, 64, "2.5K");
u8g2.drawStr(95, 64, "6.3K");
u8g2.drawStr(115, 64, "16K");
u8g2.sendBuffer();
if (Anotheraudio_bar_peak[i] < Anotheraudio_bar_height[i]){
Anotheraudio_bar_peak[i] = Anotheraudio_bar_height[i];
}else if (Anotheraudio_bar_peak[i] > Anotheraudio_bar_height[i]) {
Anotheraudio_bar_peak[i]--;
}
display2.drawBox(2 + i*19, 53- Anotheraudio_bar_height[i], 10, Anotheraudio_bar_height[i]);
display2.drawBox(2 + i*19, 53 -Anotheraudio_bar_peak[i],10 ,1 );
display2.setFont(u8g2_font_nerhoe_tf);
display2.drawStr(2, 64, "63");
display2.drawStr(19, 64, "160");
display2.drawStr(37, 64, "40");
display2.drawStr(60, 64, "1K");
display2.drawStr(75, 64, "2.5K");
display2.drawStr(95, 64, "6.3K");
display2.drawStr(115, 64, "16K");
display2.sendBuffer();
}
Audio.ReadFreq(FreqVal);//Return 7 values of 7 bands pass filiter
AnotherAudio.ReadFreq(AnotherFreqVal);
for(int i=0;i<7;i++)
{
Serial.print(max((FreqVal[i]-100),0));
if(i<6) Serial.print(",");
else Serial.println();
Audio.ReadFreq(FreqVal);//Return 7 values of 7 bands pass filiter
}
for(int j=0;j<7;j++)
{
Serial.print(max((AnotherFreqVal[j]-100),0));
if(j<6) Serial.print(",");
else Serial.println();
AnotherAudio.ReadFreq(AnotherFreqVal);//Return 7 values of 7 bands pass filter
}
delay(20);
}
It appears with the attention I can give it my current circumstances that you have carefully and accurately grown the code using copy/paste/edit. Reward yourself with one of whatever is you use to do.
But, and this is a proverbially big but - this:
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ 16, /* data=*/ 17); // ESP32 Thing, HW I2C with pin remapping
U8G2_SSD1306_128X64_NONAME_F_HW_I2C display2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ 16, /* data=*/ 17); // ESP32 Thing, HW I2C with pin remapping
places two identical devices on the I2C bus.
This is the software side and informs subsequent library calls, check:
u8g2.setI2CAddress(0x78);
display2.setI2CAddress(0x7A);
And please say you have also changed jumpers or solder bridges or cut traces on the two OLED devices so each only responds to I2C messages meant for it.
That's all I got just now, I will give it better attention if you say you have fixed this issue on the hardware side. When I am in the lab.
Just in case the OLEDs do not have address flexibility someone looking over my shoulder saw the comment... if the comment is accurate and you are using an ESP32, an alternate solution may to use its second I2C interface. Which we know exists, but cannot offer specific instructions for doing. There's also software I2C, but it is inferior and may not work well. Some viable options may be less so because they would involve modifying the library. Something to avoid...
I'll be minute. This should give you something to think about, or serve as a wrong answer which is the fastest way to get a better answer on the internet.
a7
The displays I have do not offer any chance to hardware change the I2C address. I bought them from Aliexpress, 2.4 OLED.
OK.
So... you'll need to use an I2C multiplexer
or a second I2C bus, hardware or software
or get OLEDs that do have address jumpers.
At this point, I can offer no more help - I haven't used a second hardware I2C bus, and can't say that would be that, and I cannot say if using a software I2C bus would be satisfactory.
I haven't used that multiplexer either, so I don't know the plug-and-play success nor how much additional hair you might lose in getting that working.
Good luck with whatever direction you head off in. There may be someone able and waiting to add real wisdom to this thread.
a7