FireBeetle ESP32 and Arduino

buzandy
Posts: 13
Joined: Mon Sep 11, 2017 3:50 pm

FireBeetle ESP32 and Arduino

Postby buzandy » Mon Sep 11, 2017 4:16 pm

I am trying to send audio type data directly to I2S port having it setup to use the builtin DAC port as output. and the I2S will control the sample rate etc.......I am not having any success..???
Below is code I got from the I2S example in the esp-idf folders. I dont think it was for Arduino so I have been modifying it as below.
I can send data dacWrite and it works ok but I was wanting to use the I2S with DAC to have more control and use I2S as output as well as DAC. The code compiles and runs but no sound out....????
would be grateful for some help please.......
I have the firebeetle ESP32 and Arduino 1.8.4 and followed the DFROBOT toolchain setup
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

//square wave as a 20 point array...if I send this dacWrite it works

const uint8_t p20[20] = {180,180,180,180,180,180,180,180,180,180,20,20,20,20,20,20,20,20,20,20};
// I2S_BITS_PER_SAMPLE_16BIT,.....?????
//................................................................
#include "driver/i2s.h"
#include "freertos/queue.h"
char data = 50;

int i2s_num = I2S_NUM_0; // i2s port number

i2s_config_t i2s_config = {
.mode = i2s_mode_t (I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN),
.sample_rate = 8000,
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, // tells me bits not set if 8 bits ???
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
.communication_format = I2S_COMM_FORMAT_I2S_MSB,
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
.dma_buf_count = 8,
.dma_buf_len = 64
};

i2s_pin_config_t pin_config = {
.bck_io_num = 14, //this is BCK pin .....pins for Firebeetle esp32 I2S pins
.ws_io_num = 17, // this is LRCK pin
.data_out_num = 4, // this is DATA output pin
.data_in_num = -1 //Not used
};


void setup()
{


Serial.begin(115200);
//delay(2000);
Serial.print("Initializing setup......");

//initialize i2s with configurations above

i2s_driver_install(I2S_NUM_0, &i2s_config, NULL, NULL);

i2s_set_pin ((i2s_port_t)i2s_num, NULL); // null for dac

i2s_set_dac_mode(I2S_DAC_CHANNEL_BOTH_EN);

//set sample rates of i2s to sample rate

i2s_set_sample_rates(I2S_NUM_0, 8000);


// i2s_driver_uninstall(I2S_NUM_0); //stop & destroy i2s driver
Serial.println("done!setup");

}

void loop()
{

i2s_push_sample(I2S_NUM_0, &data,1);

//xxxxxxxxxx If I run above code no sound out
// but compiles and runs to print "done setup"

/*
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
data++;
if (data > 120) data = 50 ; // if I run these 4 line of code
dacWrite(D2, data); // on their own, I get sound OK
delayMicroseconds(100);
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
*/
}

ESP_Sprite
Posts: 9772
Joined: Thu Nov 26, 2015 4:08 am

Re: FireBeetle ESP32 and Arduino

Postby ESP_Sprite » Tue Sep 12, 2017 1:13 am

FWIW: this is the code I use to set up the DACs and it works perfectly fine:

Code: Select all

        i2s_config_t cfg={
                .mode=I2S_MODE_DAC_BUILT_IN|I2S_MODE_TX|I2S_MODE_MASTER,
                .sample_rate=rate,
                .bits_per_sample=16,
                .channel_format=I2S_CHANNEL_FMT_RIGHT_LEFT,
                .communication_format=I2S_COMM_FORMAT_I2S_MSB,
                .intr_alloc_flags=0,
                .dma_buf_count=4,
                .dma_buf_len=buffsize/4
        };
        i2s_driver_install(0, &cfg, 4, &soundQueue);
        i2s_set_pin(0, NULL);
        i2s_set_dac_mode(I2S_DAC_CHANNEL_BOTH_EN);
        i2s_set_sample_rates(0, cfg.sample_rate);
You should then be able to write samples into it using i2s_write_bytes , it accepts 32-bit samples, with one channel in bits 32-24 and the other in 16-8.

buzandy
Posts: 13
Joined: Mon Sep 11, 2017 3:50 pm

Re: FireBeetle ESP32 and Arduino

Postby buzandy » Mon Sep 18, 2017 8:15 pm

Thanks for reply, but I am still stuck with how to configure and send data to I2S using Arduino IDE.
I have the Firebeetle ESP32 DfRobot.
To get it to compile I have to set it to similar to my earlier post, but dont get any sound out.
I am using IO25 and IO26 as DAC out and I dont have anything connected to the IS2 port, Bclk = IO14, LRCK=IO17, DO=IO4, DI=-1 not used??.
Basically if I do the following.....
dacWrite(D2,random(123));

I get random noise out of IO25 which is D2.

As a Trial if I could do same by sending random data to I2S as a simple test to see if I would get random noise from the DAC port.
I have followed example of reading wav file from SD card for the I2S setup but dont have a SD card connected so tried to send data instead either as random or from an array, but cant get it to work..???
would be grateful for some help or example of sending array to I2S etc.

Who is online

Users browsing this forum: No registered users and 75 guests