Send Music Data Frequency through Wireless

Hello guys, I have a project and I need your help, it is not something 100% new because there is something similar in the market

The project consists of creating hardware with arduino, with bluetooth and or wi-fi(esp), serving as input for music, in what way? As long as the device (computer or cell phone) is synchronized with the input when playing a song or generating a sound (sound coming out) it would send music data to the arduino, I thought that this data could be the wave of the music frequency ( I thought like an oscilloscope), so with that data, work an algorithm so that connected to a led strip, the tape glows according to the wave

I believe that's it, thanks for the light you can give me xD

Google "Arduino color organ". That should give you some ideas. But sending audio to the Arduino wirelessly is not so easy. Arduino wireless solutions are designed for data not audio signals.

Steve

slipstick:
But sending audio to the Arduino wirelessly is not so easy. Arduino wireless solutions are designed for data not audio signals.

It is tricky for Arduino but easy on ESP32 (via the Arduino IDE). See this library for Bluetooth audio. The library has some very simple examples if you want to use I2S for audio output but if you want to just work with the raw data directly the code below will work on ESP32 (the I2S parts are not relevant). The function bt_data_cb can be used to change volume and output the data to an I2S DAC but you can change this to process the data however you want (process and send to LED strip).

// cricial audio bits taken from https://github.com/espressif/esp-idf/blob/master/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/main.c

// bluetooth, config, discover and audio
#include "esp_bt_main.h"
#include "esp_bt_device.h"
#include "esp_gap_bt_api.h"
#include "esp_a2dp_api.h"


// the audio DAC and amp configuration. 
#include "driver/i2s.h"

//globals


// the callback(processes bluetooth data).
// this is the most important function. 
void bt_data_cb(const uint8_t *data, uint32_t len){
   // number of 16 bit samples
   int n = len/2;
   
   // point to a 16bit sample 
   int16_t* data16=(int16_t*)data;
   
   // create a variable (potentially processed) that we'll pass via I2S 
   int16_t fy; 
   
   // Records number of bytes written via I2S
   size_t i2s_bytes_write = 0;

   for(int i=0;i<n;i++){
    // put the current sample in fy
    fy=*data16;
    
    //making this value larger will decrease the volume(Very simple DSP!). 
    fy/=1;
    
    // write data to I2S buffer 
    i2s_write(I2S_NUM_0, &fy, 2, &i2s_bytes_write,  10 );
    
    //move to next memory address housing 16 bit data 
    data16++;
   }
}


void setup() {

  // i2s configuration
  static const i2s_config_t i2s_config = {
    .mode = static_cast<i2s_mode_t>(I2S_MODE_MASTER | I2S_MODE_TX),
    .sample_rate = 44100,
    .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
    .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
    .communication_format = static_cast<i2s_comm_format_t>(I2S_COMM_FORMAT_I2S|I2S_COMM_FORMAT_I2S_MSB),
    .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, // default interrupt priority
    .dma_buf_count = 8,
    .dma_buf_len = 1000,
    .use_apll = false,
    .tx_desc_auto_clear = true
  };
  
  // i2s pinout
  static const i2s_pin_config_t pin_config = {
    .bck_io_num = 26,//26
    .ws_io_num = 27,
    .data_out_num = 25, //
    .data_in_num = I2S_PIN_NO_CHANGE
  };
  
  // now configure i2s with constructed pinout and config
  i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
  i2s_set_pin(I2S_NUM_0, &pin_config);
  i2s_set_clk(I2S_NUM_0, 44100, I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_STEREO);
  i2s_set_sample_rates(I2S_NUM_0, 44100);
  
 // set up bluetooth classic via bluedroid
  btStart();
  esp_bluedroid_init();
  esp_bluedroid_enable();

 
  // set up device name
  const char *dev_name = "ESP_SPEAKER";
  esp_bt_dev_set_device_name(dev_name);

  // initialize A2DP sink and set the data callback(A2DP is bluetooth audio)
  esp_a2d_sink_register_data_callback(bt_data_cb);
  esp_a2d_sink_init();
  
  // set discoverable and connectable mode, wait to be connected
  esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE); 

}
void loop() {
  // put your main code here, to run repeatedly:
  delay(1000);
}

slipstick:
Google “Arduino color organ”. That should give you some ideas. But sending audio to the Arduino wirelessly is not so easy. Arduino wireless solutions are designed for data not audio signals.

Steve

The problem with the light organs that I saw is that I don’t see most of the electronics for sale here, but I already have some saved here for reference so it’s always good to ask to have a vision to see if I missed something

the2ndtierney:
It is tricky for Arduino but easy on ESP32 (via the Arduino IDE). See this library for Bluetooth audio. The library has some very simple examples if you want to use I2S for audio output but if you want to just work with the raw data directly the code below will work on ESP32 (the I2S parts are not relevant). The function bt_data_cb can be used to change volume and output the data to an I2S DAC but you can change this to process the data however you want (process and send to LED strip).

// cricial audio bits taken from https://github.com/espressif/esp-idf/blob/master/examples/bluetooth/bluedroid/classic_bt/a2dp_sink/main/main.c

// bluetooth, config, discover and audio
#include “esp_bt_main.h”
#include “esp_bt_device.h”
#include “esp_gap_bt_api.h”
#include “esp_a2dp_api.h”

// the audio DAC and amp configuration.
#include “driver/i2s.h”

//globals

// the callback(processes bluetooth data).
// this is the most important function.
void bt_data_cb(const uint8_t data, uint32_t len){
  // number of 16 bit samples
  int n = len/2;
 
  // point to a 16bit sample
  int16_t
data16=(int16_t*)data;
 
  // create a variable (potentially processed) that we’ll pass via I2S
  int16_t fy;
 
  // Records number of bytes written via I2S
  size_t i2s_bytes_write = 0;

for(int i=0;i<n;i++){
   // put the current sample in fy
   fy=*data16;
   
   //making this value larger will decrease the volume(Very simple DSP!).
   fy/=1;
   
   // write data to I2S buffer
   i2s_write(I2S_NUM_0, &fy, 2, &i2s_bytes_write,  10 );
   
   //move to next memory address housing 16 bit data
   data16++;
  }
}

void setup() {

// i2s configuration
 static const i2s_config_t i2s_config = {
   .mode = static_cast<i2s_mode_t>(I2S_MODE_MASTER | I2S_MODE_TX),
   .sample_rate = 44100,
   .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
   .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
   .communication_format = static_cast<i2s_comm_format_t>(I2S_COMM_FORMAT_I2S|I2S_COMM_FORMAT_I2S_MSB),
   .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, // default interrupt priority
   .dma_buf_count = 8,
   .dma_buf_len = 1000,
   .use_apll = false,
   .tx_desc_auto_clear = true
 };
 
 // i2s pinout
 static const i2s_pin_config_t pin_config = {
   .bck_io_num = 26,//26
   .ws_io_num = 27,
   .data_out_num = 25, //
   .data_in_num = I2S_PIN_NO_CHANGE
 };
 
 // now configure i2s with constructed pinout and config
 i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
 i2s_set_pin(I2S_NUM_0, &pin_config);
 i2s_set_clk(I2S_NUM_0, 44100, I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_STEREO);
 i2s_set_sample_rates(I2S_NUM_0, 44100);
 
// set up bluetooth classic via bluedroid
 btStart();
 esp_bluedroid_init();
 esp_bluedroid_enable();

// set up device name
 const char *dev_name = “ESP_SPEAKER”;
 esp_bt_dev_set_device_name(dev_name);

// initialize A2DP sink and set the data callback(A2DP is bluetooth audio)
 esp_a2d_sink_register_data_callback(bt_data_cb);
 esp_a2d_sink_init();
 
 // set discoverable and connectable mode, wait to be connected
 esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);

}
void loop() {
 // put your main code here, to run repeatedly:
 delay(1000);
}

Thank you very much this library should be exactly what I need, I will order this esp referred to test