Commandé avant 14h00 un jour ouvrable = expédié le jour même 30 jours de délai de rétractation Garantie d’un an
← Retour à l’aperçu

Schéma de câblage et exemple de code

Voici comment connecter le DAC I2S avec amplificateur 3 W - MAX98357A à un Arduino UNO ou à un ESP32, avec un exemple de sketch que tu peux téléverser directement.

Démo d'amplificateur I2S MAX98357A

Ce projet présente l'amplificateur I2S MAX98357A connecté à une Arduino Uno et à un haut-parleur de 3W. Comme l'Arduino Uno basé sur AVR ne dispose pas de périphérique I2S natif, le sketch montre le câblage de l'interface en basculant les broches de contrôle et de données et en affichant des messages d'état dans le Serial Monitor à 115200 baud.

Schéma de câblage : DAC I2S avec amplificateur 3 W - MAX98357A sur un Arduino UNO
Schéma de câblage · Cliquez pour agrandir
Tableau de câblage : DAC I2S avec amplificateur 3 W - MAX98357A sur un Arduino UNO
Tableau de câblage · Cliquez pour agrandir
MAX98357A_I2S_Amplifier_Demo.ino · compilé et testé
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : MAX98357A I2S Amplifier Demo
 *  Board     : Arduino UNO (arduino:avr:uno)
 *  Parts     : 3W amplifier MAX98357A I2S DAC
 *  Libraries : none (built-in)
 *
 *  Codey Online is an AI-powered browser IDE for Arduino and ESP32.
 *  Describe your project and Codey writes the code, draws the wiring
 *  diagram and uploads it to your board, straight from the browser.
 *  This code is free to use, modify and share, without warranty.
 * ==================================================================
 */

// MAX98357A I2S Amplifier wiring and basic test sketch
// Note: AVR Arduino Uno does not have hardware I2S.
// This sketch verifies pin connections and demonstrates signal pulsing.

const uint8_t PIN_BCLK = 9;
const uint8_t PIN_LRC  = 8;
const uint8_t PIN_DIN  = 10;

const unsigned int toneHz = 440;
const unsigned long toneOnMs = 1000;
const unsigned long toneOffMs = 500;

void outputPulse(unsigned long durationMs, unsigned int frequencyHz) {
  unsigned long start = millis();
  unsigned long halfPeriodUs = 500000UL / frequencyHz;

  while (millis() - start < durationMs) {
    digitalWrite(PIN_DIN, HIGH);
    delayMicroseconds(halfPeriodUs);
    digitalWrite(PIN_DIN, LOW);
    delayMicroseconds(halfPeriodUs);
  }
}

void setup() {
  pinMode(PIN_BCLK, OUTPUT);
  pinMode(PIN_LRC, OUTPUT);
  pinMode(PIN_DIN, OUTPUT);

  digitalWrite(PIN_BCLK, LOW);
  digitalWrite(PIN_LRC, LOW);
  digitalWrite(PIN_DIN, LOW);

  Serial.begin(115200);
  Serial.println(F("MAX98357A Amplifier Test"));
  Serial.println(F("Pins initialized: BCLK=9, LRC=8, DIN=10"));
}

void loop() {
  Serial.println(F("Signal ON (440 Hz pulse)"));
  outputPulse(toneOnMs, toneHz);

  Serial.println(F("Signal OFF"));
  digitalWrite(PIN_DIN, LOW);
  delay(toneOffMs);
}

Wiring diagram and example code generated by Codey.online — https://www.codey.online

Générateur de tonalités audio I2S ESP32 avec MAX98357A

Ce projet diffuse des tonalités audio alternées via un haut-parleur de 3W à l’aide de l’amplificateur audio numérique I2S MAX98357A. L’ESP32 synthétise en temps réel de l’audio PCM 16-bit et le transmet directement au DAC amplificateur via le bus I2S.

Schéma de câblage : DAC I2S avec amplificateur 3 W - MAX98357A sur un ESP32 DevKit V1
Schéma de câblage · Cliquez pour agrandir
Tableau de câblage : DAC I2S avec amplificateur 3 W - MAX98357A sur un ESP32 DevKit V1
Tableau de câblage · Cliquez pour agrandir
ESP32_I2S_Audio_Tone_Generator_with_MAX9.ino · compilé et testé
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : ESP32 I2S Audio Tone Generator with MAX98357A
 *  Board     : ESP32 DEVKIT V1 (esp32:esp32:esp32doit-devkit-v1)
 *  Parts     : 3W amplifier MAX98357A I2S DAC
 *  Libraries : none (built-in)
 *
 *  Codey Online is an AI-powered browser IDE for Arduino and ESP32.
 *  Describe your project and Codey writes the code, draws the wiring
 *  diagram and uploads it to your board, straight from the browser.
 *  This code is free to use, modify and share, without warranty.
 * ==================================================================
 */

#include <Arduino.h>
#include "driver/i2s.h"
#include <math.h>

#define I2S_BCLK 26
#define I2S_LRC  25
#define I2S_DIN  22

#define SAMPLE_RATE 44100

void setup() {
  Serial.begin(115200);

  i2s_config_t i2s_config = {
    .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX),
    .sample_rate = SAMPLE_RATE,
    .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
    .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
    .communication_format = I2S_COMM_FORMAT_STAND_I2S,
    .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
    .dma_buf_count = 8,
    .dma_buf_len = 64,
    .use_apll = false,
    .tx_desc_auto_clear = true
  };

  i2s_pin_config_t pin_config = {
    .bck_io_num = I2S_BCLK,
    .ws_io_num = I2S_LRC,
    .data_out_num = I2S_DIN,
    .data_in_num = I2S_PIN_NO_CHANGE
  };

  i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
  i2s_set_pin(I2S_NUM_0, &pin_config);

  Serial.println("MAX98357A I2S Tone Generator Ready!");
}

void playTone(float freq, int durationMs) {
  int totalSamples = (SAMPLE_RATE * durationMs) / 1000;
  size_t bytesWritten;
  int16_t buffer[128];
  
  float phaseStep = 2.0 * PI * freq / SAMPLE_RATE;
  float phase = 0.0;
  
  int samplesRemaining = totalSamples;
  while (samplesRemaining > 0) {
    int toWrite = min(64, samplesRemaining);
    for (int i = 0; i < toWrite; i++) {
      int16_t sample = (int16_t)(sin(phase) * 6000.0);
      buffer[i * 2] = sample;     // Left channel
      buffer[i * 2 + 1] = sample; // Right channel
      phase += phaseStep;
      if (phase >= 2.0 * PI) phase -= 2.0 * PI;
    }
    i2s_write(I2S_NUM_0, buffer, toWrite * sizeof(int16_t) * 2, &bytesWritten, portMAX_DELAY);
    samplesRemaining -= toWrite;
  }
}

void loop() {
  Serial.println("Playing 440 Hz (A4)...");
  playTone(440.0, 400);
  delay(100);

  Serial.println("Playing 880 Hz (A5)...");
  playTone(880.0, 400);
  delay(1000);
}

Wiring diagram and example code generated by Codey.online — https://www.codey.online

Récemment consultés

Module relais USB 5 V à 1 canal de haute qualité

Module relais USB 5 V à 1 canal de haute qualité

€ 8,45
Carte pilote de moteur pas à pas ULN2003

Carte pilote de moteur pas à pas ULN2003

€ 1,85
ESD-16 pincette antistatique ESD

ESD-16 pincette antistatique ESD

€ 1,80
BMS 6S 15A 22V 24V pour batteries lithium

BMS 6S 15A 22V 24V pour batteries lithium

€ 4,99
Étain à souder 50 g 0,8 mm

Étain à souder 50 g 0,8 mm

€ 4,15
Voir
Petite voiture solaire

Petite voiture solaire

€ 4,15
Arduino Uno R4 WiFi compatible

Arduino Uno R4 WiFi compatible

€ 26,80
Émetteur et récepteur Bluetooth 5.0

Émetteur et récepteur Bluetooth 5.0

€ 19,95
LCD 1604 display bleu rétroéclairage 16x4 caractères

LCD 1604 display bleu rétroéclairage 16x4 caractères

€ 7,30
Module testeur de capacité de batterie 1S 18650 Li-Ion

Module testeur de capacité de batterie 1S 18650 Li-Ion

€ 2,10
CS32 | Blue Pill | 72 MHz | 64 Ko | clone STM32

CS32 | Blue Pill | 72 MHz | 64 Ko | clone STM32

€ 4,15
Voir
Marble Lane Switch pour circuit de billes Marblelous

Marble Lane Switch pour circuit de billes Marblelous

€ 69,00
Voir
Module convertisseur PWM vers tension 0-10 V

Module convertisseur PWM vers tension 0-10 V

€ 2,60
Détecteur Marble pour circuit de billes Marblelous

Détecteur Marble pour circuit de billes Marblelous

€ 59,00
Voir