0

I am working with ESP-WROOM-32D MCU in PlatformIO with audrino frame work.I need to play pcm audio with esp32. For this purpose i am using dacWrite() function to play PCM. The problem is that after playing pcm audio analogWrite() function is not working. I found it is the problem with dacWrite whenever we call dacWrite() after that analogWrite() function will not work. In my project i need to play PCM audio and 'teek' sound according to the input commands .I tried by calling pinMode() after dacWrite() but it is also not working.Below is a sample program which can produce the same error .

 #include<Arduino.h>
 #include "sounddata.h"
 #define AUDIO_OUT_PIN GPIO_NUM_25

int SineValues[256];
void InitSineValues()
{
    float ConversionFactor=(2.0*3.142)/256.0;                                           
    float RadAngle;                                     
    for(int MyAngle=0;MyAngle<256;MyAngle++)
   {
        RadAngle=MyAngle*ConversionFactor;              
        SineValues[MyAngle]=(sin(RadAngle)*127)+128;                                            
    }
}

 void playPcmData(unsigned char * buff, long buffLen)
{
  for (size_t i = 0; i < buffLen; i++)
  {
    int val=int(buff[i]);
    dacWrite(AUDIO_OUT_PIN,SineValues[val]);
    delayMicroseconds(50);

  }
  
}
void setup() {
 
  pinMode(AUDIO_OUT_PIN,ANALOG);
  InitSineValues();
  
  
}
void loop() {
  //playPcmData(sample,98216); 
  pinMode(AUDIO_OUT_PIN,OUTPUT);
  delay(1000);
  analogWrite(AUDIO_OUT_PIN,225);
  delay(1000);
  analogWrite(AUDIO_OUT_PIN,0);
  delay(1000);
  dacWrite(AUDIO_OUT_PIN,250);
  delay(1000);
  gpio_reset_pin(AUDIO_OUT_PIN);
  delay(1000);
}

When we run this you can hear a 'teek' sound at first time then after it will not produce that sound, I am using GPIO pins 25 and 26 as output pins .An audio amplifier with speaker is connected to these pins.

below is in ini file

[env:esp32dev]
platform = https://github.com/platformio/platform-espressif32.git
platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git
board = esp32dev
framework = arduino
monitor_speed = 115200

0 Answers0