I have a PC speaker with it's owner power supply (no amplifier needed). It just uses a standard AUX jack.

Most examples sketches use an amplifier like the MAX98357A. I have explored some libraries too, such as ESP8266Audio.

I just want to find a simple example that emits audio (not just noise). This is my setup:

enter image description here

enter image description here

I thought an audio program would use the internal DAC to create the CODEC? Or am I not understanding something?

const int  DAC_CH1 = 25; // or 26

void setup() 
//    dacWrite(DAC_CH1, 255); // ~3v3
//  dacWrite(DAC_CH1, 192); // ~2.5
//  dacWrite(DAC_CH1, 128); // ~1.7

void loop(){}


I found the PlayMODFromPROGMEMToDAC example, which uses pin 25 DAC:

#include <Arduino.h>
#include "AudioFileSourcePROGMEM.h"
#include "AudioGeneratorMOD.h"
#include "AudioOutputI2S.h"
#if defined(ARDUINO_ARCH_RP2040)
    #define WIFI_OFF
    class __x { public: __x() {}; void mode() {}; };
    __x WiFi;
#elif defined(ESP32)
    #include <WiFi.h>
    #include <ESP8266WiFi.h>

// enigma.mod sample from the mod archive: https://modarchive.org/index.php?request=view_by_moduleid&query=42146
#include "enigma.h"

AudioGeneratorMOD *mod;
AudioFileSourcePROGMEM *file;
AudioOutputI2S *out;

void setup()
  WiFi.mode(WIFI_OFF); //WiFi.forceSleepBegin();

  audioLogger = &Serial;
  file = new AudioFileSourcePROGMEM( enigma_mod, sizeof(enigma_mod) );

   /* HERE! */
   // ↓
   // ↓
   out = new AudioOutputI2S(0, 1); //Uncomment this line, comment the next one to use the internal DAC channel 1 (pin25) on ESP32
   // ↑
   // ↑
//  out = new AudioOutputI2S();
  mod = new AudioGeneratorMOD();
  mod->begin(file, out);

void loop()
  if (mod->isRunning()) {
    if (!mod->loop()) mod->stop();
  } else {
    Serial.printf("MOD done\n");

Although, still no sound (besides noise) can be heard.

  • no need for DAC ... toggle a digital pin
    – jsotola
    May 10, 2023 at 18:49
  • What do you mean by "audio not just noise"? Can't you simply toggle the pins? An alternative would be to use the sin() function to generate a "clean" note. May 11, 2023 at 5:59
  • Ideally something like talkMIDI(0xC0, instrument, 0) as found here: sparkfun.com/tutorials/302
    – adamaero
    May 11, 2023 at 13:50


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.