FireBeetle ESP32 and Arduino
Posted: 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
*/
}
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
*/
}