I2S Audio data Capture( Binary data )using Arduino MKR1000 board

Hello all im trying to build a device with Arduino MKR1000 which is having support for I2S audio input/out.

I have a HDMI receiver board from their I can take I2S out and connected to I2S input to my MKR1000 board and reading I2S data from A0 pin and saving captured data in to SD card with text format( Binary data ).
Here I have problem in speed because when im doing the SD card data saving execution im losing some incoming I2S data samples from my HDMI receiver . I got few suggestion to increase the speed with DMA implementation instead of using CPU but I don’t know how to implement DMA for I2S data reading and saving in SD card , can you please suggest/help to solved my problem.

My Project expectation is :
Play audio wav file and capture all digital data(Binary data ) and compare with original Audio wav file( Binary file ).

Attached the my I2S Arduino code please check and help me any modification I can do here.

Thanks ……!!!

I2S_Buffer_read.ino (1.58 KB)

https://www.arduino.cc/en/Reference/I2S perhaps?

Thanks Mike for the link , but here im not finding any data on implementing DMA for i2s .

Hello ,

Can anyone knows how to save I2S data to file i tried writing to SD card on BIN format but getting output all characters instead my input data. Please let me know any i suggestions please .

i used below code for writing to SD card

// Reading I2S data buffer …

I2S.read(data, size);

// Opening File

myFile = SD.open(“data.bin”, FILE_WRITE);
if (myFile)
{
for (i =0; i<size; i++)
{
uint8_t ch = data*;*
// printing each byte …
myFile.write((uint8_t *)&ch,1);

  • }*
    myFile.close();

Writing one byte at a time to the SD card will seriously slow it down. Try this:

  myFile = SD.open("data.bin", FILE_WRITE);
  if (myFile)
  {
    myFile.write((uint8_t *)data,size);
    myFile.close();
  }

Pete

Does the MKR1000 have native support for SDcards? If not you are limited by the SPI speed. Raw I2S datarates tend to be 300kB/s or more.

Thanks for the reply ...!!!

I tried writing complete buffer instead of each byte but results are same . Here my problem is printing data in Binary format or HEX. Based on my understanding I2S data is Digital data so i want to print in HEX or Binary format .

MarkT ,

regarding the SD card native port ... In my MKR1000 device it doesn't have SD card port but im using external device for same but SAM D21 micro controller is having native support and MKR1000 device using same.

Based on my understanding I2S data is Digital data so i want to print in HEX or Binary format .

Hex and binary are digital data. To print in any base see https://www.arduino.cc/en/Serial/Print

sheshu: I tried writing complete buffer instead of each byte but results are same . Here my problem is printing data in Binary format or HEX. Based on my understanding I2S data is Digital data so i want to print in HEX or Binary format .

You are not printing anything, you just need to shovel the bytes into the file. All data is binary all the time in a digital logic system!

A buffer is just an array of bytes, you write the whole array with one call. I2S is typically 4 or 6 bytes per stereo sample (16 bit or 24 bit samples).

MarkT thanks for the reply ..!!

i have another question: Is I2S stream is in ASCII format or in HEX format ? Example : If i send I2S steam with value "250" then the output will be " 32 35 30" or "FA" ?

An I2S stream is just data. ASCII and hex are just two ways to represent data to a human. To a computer they are both just binary bit patterns.

sheshu: MarkT thanks for the reply ..!!

i have another question: Is I2S stream is in ASCII format or in HEX format ? Example : If i send I2S steam with value "250" then the output will be " 32 35 30" or "FA" ?

Its serial 24 or 16 bits per channel, two channels, MSB first, 2's complement.