本帖最后由 gaoyang9992006 于 2023-7-31 17:34 编辑
#申请原创# @21小跑堂
思路大概如下所示:ESP32-C3通过AIN0读取ET7207的模拟数据,通过IO控制RST/STR,麦克风模块输出连接ET7207的AIN接口。
接下来介绍一下这个ET7207
这是一款采用 CMOS 技术制造的7 段图形均衡器。它将音频频谱划分为7 段:63Hz,160Hz,400Hz,1kHz,2.5kHz,6.25kHz,和16kHz。这7 种频率的信号经过峰值检测和多路开关选择器,产生一个直流电平输出来表示信号的振幅。不要外部元件来选择滤波器的响应。只需要一个电阻和一个电容来产生系统时钟频率。滤波器的中心频率由这个频率所决定。另外还需要一些耦合和去耦电容。电路可以工作在 2.7V 和5.5V 之间,最佳工作电压为5V。电路有着非常低的静态电流(典型值小于1mA),非常适合于便携式音频设备。多路选择器由Reset 和Strobe 控制。
这么说可能不知道,国外有一个芯片名字叫MSGEQ7,在国内很难买到正品,而且还挺贵的,几十块一个。现在好了,ET7207完美兼容替代MSGEQ7。该芯片该如何使用呢,我们先看看时序图。
ET7207的操作时序如下图所示
有了时序图就可以很方便的写出驱动代码
接下来通过Arduino编程实现
- #include <SPI.h>
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
- #define SCREEN_WIDTH 128 // OLED display width, in pixels
- #define SCREEN_HEIGHT 64 // OLED display height, in pixels
- // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
- // The pins for I2C are defined by the Wire-library.
- // On an arduino UNO: A4(SDA), A5(SCL)
- // On an arduino MEGA 2560: 20(SDA), 21(SCL)
- // On an arduino LEONARDO: 2(SDA), 3(SCL), ...
- #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
- #define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
- Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
- #define DATA_PIN A0
- #define RESET_PIN 18
- #define STROBE_PIN 19
- #define READ_DELAY 100
- int OutValue = 0;
- unsigned int bands[7];
- unsigned int Min_DC[7]={4095,4095,4095,4095,4095,4095,4095};
- void setup()
- {
- // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
- if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS))
- {
- Serial.println(F("SSD1306 allocation failed"));
- for(;;); // Don't proceed, loop forever
- }
- // Show initial display buffer contents on the screen --
- // the library initializes this with an Adafruit splash screen.
- display.display();
- delay(2000); // Pause for 2 seconds
- // Clear the buffer
- display.clearDisplay();
- Serial.begin(115200);
- pinMode(RESET_PIN, OUTPUT);
- pinMode(STROBE_PIN,OUTPUT);
- // pinMode(DATA_PIN , INPUT);
- digitalWrite(RESET_PIN , LOW); delay(1);
- digitalWrite(STROBE_PIN, LOW); delay(1);
- }
- void loop()
- {
- digitalWrite(RESET_PIN, HIGH); delayMicroseconds(10+72);
- digitalWrite(STROBE_PIN,HIGH); delayMicroseconds(10+72);
- digitalWrite(STROBE_PIN, LOW); delayMicroseconds(10+72);
- digitalWrite(RESET_PIN , LOW);
- for(int i=0;i<7;i++)
- {
- digitalWrite(STROBE_PIN, HIGH);
- delayMicroseconds(10+72);
- digitalWrite(STROBE_PIN , LOW);
- delayMicroseconds(10+72);
- }
- for(int i=0;i<7;i++)
- {
- digitalWrite(STROBE_PIN, HIGH);
- delayMicroseconds(10+72);
- digitalWrite(STROBE_PIN , LOW);
- delayMicroseconds(10+72);
- bands[i] = analogRead(DATA_PIN);
- if(bands[i]<Min_DC[i]) Min_DC[i] = bands[i];
- bands[i] = bands[i] - Min_DC[i];
- }
- for(int i=0;i<7;i++)
- {
- Serial.print(bands[i]);
- Serial.print(" :");
- }
- Serial.println();
- delay(5);
- display.clearDisplay();
- for(int i=0;i<7;i++)
- {
- int barH = map(bands[i], 0, 4096, 0, SCREEN_HEIGHT);
- display.fillRect( 0+(i*10), SCREEN_HEIGHT-barH , 8 , barH , SSD1306_WHITE );
- }
- display.display();
- }
烧录程序,并按照程序中定义的接口在面包板搭建测试电路
|