Recently I found this Audio Codec Shield made by Open Music Labs. Surprisingly the pinout of this shield, and I2S signals particularly, match the pinout of the Intel Edison Arduino breakout board. And so it is not difficult to make this shield work with Intel Edison. For the simple audio playback it is needed to setup pin multiplexing on the Arduino breakout board, so that I2S and I2C signals are routed to the Arduino headers, and then to configure the codec, in the way similar to what I've described in my previous post. Hardware SetupI'd recommend configuring Arduino breakout board pins voltage to 3.3V by setting jumper J9 to position 2-3. Once it is configured, plug the Audio Codec Shield into the Arduino breakout board. Pin Multiplexing SetupUse the following code to setup the I2S and I2C signals on Arduino breakout board headers. You might want to create a script with this code, and make it run on the boot. # Export GPIOs that control I2S signals echo 263 > /sys/class/gpio/export echo 240 > /sys/class/gpio/export echo 262 > /sys/class/gpio/export echo 241 > /sys/class/gpio/export echo 242 > /sys/class/gpio/export echo 243 > /sys/class/gpio/export echo 258 > /sys/class/gpio/export echo 259 > /sys/class/gpio/export echo 260 > /sys/class/gpio/export echo 261 > /sys/class/gpio/export echo 226 > /sys/class/gpio/export echo 227 > /sys/class/gpio/export echo 228 > /sys/class/gpio/export echo 229 > /sys/class/gpio/export # Export GPIOs that control I2C signals echo 28 > /sys/class/gpio/export echo 27 > /sys/class/gpio/export echo 204 > /sys/class/gpio/export echo 205 > /sys/class/gpio/export echo 236 > /sys/class/gpio/export echo 237 > /sys/class/gpio/export echo 14 > /sys/class/gpio/export echo 165 > /sys/class/gpio/export echo 212 > /sys/class/gpio/export echo 213 > /sys/class/gpio/export # Export TRI_STATE_ALL control GPIO echo 214 > /sys/class/gpio/export # Disable all pins (enable TRI_STATE_ALL) echo low > /sys/class/gpio/gpio214/direction # Configure I2S signals on Arudino pins 10-13 # Pin 10 # set to GPIO (not PWM) echo high > /sys/class/gpio/gpio263/direction # I2S (map to GP41) echo low > /sys/class/gpio/gpio240/direction # output echo high > /sys/class/gpio/gpio258/direction # disable pull up echo in > /sys/class/gpio/gpio226/direction # Pin 11 # set to GPIO (not PWM) echo high > /sys/class/gpio/gpio262/direction # I2S (map to GP43) echo low > /sys/class/gpio/gpio241/direction # output echo high > /sys/class/gpio/gpio259/direction # disable pull up echo in > /sys/class/gpio/gpio227/direction # Pin 12 # I2S (map to GP42) echo low > /sys/class/gpio/gpio242/direction # input echo low > /sys/class/gpio/gpio260/direction # disable pull up echo in > /sys/class/gpio/gpio228/direction # Pin 13 # I2S (map to GP40) echo low > /sys/class/gpio/gpio243/direction # output echo high > /sys/class/gpio/gpio261/direction # disable pull up echo in > /sys/class/gpio/gpio229/direction # Configure I2C signals on Arduino pins A4 and A5 # Pin A4 # set to GPIO (not analog in) echo low > /sys/class/gpio/gpio204/direction # configure gpio14 as input (tri-state it) echo in > /sys/class/gpio/gpio14/direction # output echo low > /sys/class/gpio/gpio236/direction # disable pull up echo in > /sys/class/gpio/gpio212/direction # set to mode1 (I2C) echo mode1 > /sys/kernel/debug/gpio_debug/gpio28/current_pinmux # Pin A5 # set to GPIO (not analog in) echo low > /sys/class/gpio/gpio205/direction # configure gpio165 as input (tri-state it) echo in > /sys/class/gpio/gpio165/direction # output echo low > /sys/class/gpio/gpio237/direction # disable pull up echo in > /sys/class/gpio/gpio213/direction # set to mode1 (I2C) echo mode1 > /sys/kernel/debug/gpio_debug/gpio27/current_pinmux # Enable all pins (disable TRI_STATE_ALL) echo high > /sys/class/gpio/gpio214/direction Codec ConfigurationUse the following commands to configure the codec: # reset codec i2cset -y 6 0x1a 0x1e 0x00 # disable DAC and output powerdown i2cset -y 6 0x1a 0x0c 0x07 # set volume for headphone output (both channels) i2cset -y 6 0x1a 0x05 0x50 # analog audio path control (DAC enabled) i2cset -y 6 0x1a 0x08 0x12 # digital audio path control i2cset -y 6 0x1a 0x0a 0x00 # set sample rate (48000Hz, assuming 12.288MHz codec clock) #i2cset -y 6 0x1a 0x10 0x00 # set sample rate (44100Hz, assuming 11.2896MHz codec clock) i2cset -y 6 0x1a 0x10 0x20 # digital audio interface format set (DSP mode, 24 bit) i2cset -y 6 0x1a 0x0e 0x8b # activate interface i2cset -y 6 0x1a 0x12 0x01 Using the Audio DeviceThe codec is connected to ALSA device hw:1,0 . Refer to the software documentation on configuring the device name. For example in mpg123 player the audio device can be specified using -a switch:mpg123 -a hw:1,0 -v "Dave Brubeck - Take Five.mp3" AlexT's repository has several software packages that support audio output. Output volume can be adjusted by writing headphone out register at address 0x05 (both channels) or 0x04 (left channel) and 0x06 (right channel), e.g.: i2cset -y 1 0x1a 0x05 0x50 ReferencesIntel® Edison Kit for Arduino* Hardware Guide |
Home > Sergey's Blog >