Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Add I2S support #368

Open
wants to merge 1 commit into
base: Dev
Choose a base branch
from
Open

Add I2S support #368

wants to merge 1 commit into from

Conversation

amotl
Copy link
Contributor

@amotl amotl commented Nov 19, 2019

This adds preliminary I2S support from Genuine MicroPython contributed by Mike Teachman through micropython/micropython#4471.

Corresponding example programs are available from [1] and [2]. However, they have not been tested with real I2S hardware yet.

A ready-made firmware image for the Pycom FiPy is available from [3].

Thanks a bunch, @miketeachman!

[1] https://github.com/miketeachman/micropython-esp32-i2s-examples
[2] https://gitlab.com/MrSurly/project-disco
[3] https://packages.hiveeyes.org/hiveeyes/foss/pycom/vanilla/FiPy-1.20.1.r1-0.7.0-vanilla-dragonfly-onewire-i2s.tar.gz

@amotl
Copy link
Contributor Author

amotl commented Nov 19, 2019

Pre-flight tests

>>> from machine import I2S
>>> dir(I2S)
['__class__', '__name__', 'readinto', 'write', 'ALL_LEFT', 'ALL_RIGHT', 'B16', 'B24', 'B32', 'LSB', 'MASTER_RX', 'MASTER_TX', 'NUM0', 'NUM1', 'ONLY_LEFT', 'ONLY_RIGHT', 'PHILIPS', 'RIGHT_LEFT', 'deinit', 'init']

Adjusted example program

This is a reduced example audio playback program derived from https://github.com/miketeachman/micropython-esp32-i2s-examples. While it hasn't been tested with any I2S hardware connected, it doesn't crash the machine at least.

Provision audio file

# Acquire audio file
wget https://github.com/miketeachman/micropython-esp32-i2s-examples/raw/master/wav_files/taunt-16k-16bits-mono-12db.wav
export MCU_PORT=/dev/cu.usbmodemPy001711

# Might take some time
rshell --port $MCU_PORT cp ./taunt-16k-16bits-mono-12db.wav /flash/taunt-16k-16bits-mono-12db.wav

Program

# I2S audio output example
# Derived from https://github.com/miketeachman/micropython-esp32-i2s-examples/blob/master/examples/play-mono-wav.py

from machine import I2S
from machine import Pin

# Setup
SAMPLES_PER_SECOND = 16000

bck_pin = Pin('P9')
ws_pin = Pin('P10')
sdout_pin = Pin('P11')

audio_out = I2S(I2S.NUM1, bck=bck_pin, ws=ws_pin, sdout=sdout_pin, 
              standard=I2S.PHILIPS, mode=I2S.MASTER_TX,
              dataformat=I2S.B16, channelformat=I2S.ONLY_RIGHT,
              samplerate=SAMPLES_PER_SECOND,
              dmacount=8, dmalen=512)

# Open audio file
s = open('taunt-16k-16bits-mono-12db.wav','rb')
s.seek(44) # advance to first byte of Data section in WAV file

# 1st bunch
audio_samples = bytearray(s.read(1024))
audio_out.write(audio_samples, timeout=0)

# 2nd bunch
audio_samples = bytearray(s.read(1024))
audio_out.write(audio_samples, timeout=0)

# Shutdown
s.close()
audio_out.deinit()

@amotl
Copy link
Contributor Author

amotl commented Nov 20, 2019

Hi there,

confirmed through [1], @ClemensGruber was able to record at least something. However, the recording is still a bit distorted and we will have to figure out why.

With kind regards,
Andreas.

[1] https://community.hiveeyes.org/t/erschliessung-von-i2s-support-und-fft-fur-micropython-auf-pycom-esp32/2331/19

This commit adds I2S support from Genuine MicroPython by Mike Teachman.

See also micropython/micropython#4471
@amotl
Copy link
Contributor Author

amotl commented Feb 18, 2020

In case anyone is aiming to use the I2S module without having to rebuild the firmware, we are following the Pycom releases to build custom firmware images on top, see Squirrel firmware for Pycom/ESP32. Please read the installation instructions carefully.

@ClemensGruber
Copy link

We did some more tests and used an updated code from @miketeachman to write data from an INMP411 I2S mic to the SD card with a PyCom FiPy, see https://community.hiveeyes.org/t/erschliessung-von-i2s-support-und-fft-fur-micropython-auf-pycom-esp32/2331/30

For the FiPy you have to a home brewed firmware with this I2S dirver, would be great if the official PyCom firmware has this driver build in!

For the meantime use at least version FiPy-1.20.1.r1-0.7.0-vanilla-dragonfly-onewire-i2s.tar.gz or better a newer release, see Dragonfly firmware for Pycom/ESP32

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants