[SOLVED] I2S speaker with Matrix Voice



How can I use I2S port for my speaker (https://learn.adafruit.com/adafruit-max98357-i2s-class-d-mono-amp/overview) ? I2S use GPIOs 18 19 21. I don’t see these ports on the extension port pinout.



Hi @Piscenois,

Welcome to the community!

The GPIO pins on MATRIX devices are actually configured through the FPGA and are not the same as the Raspberry Pi’s GPIO pins. Currently, I2S is not a feature of the MATRIX Voice GPIOs.

However, the Raspberry Pi’s GPIO 18, 19, 20, and 21 (I2S pins) are not currently performing any functions in the MATRIX Voice and can be accessed through its FPGA. The FPGA code can be modified to essentially create a “wire” between these RPi pins and some MATRIX Voice GPIOs. We have a tutorial that shows how to do this here. This would allow you to access the the RPi pins and setup I2S using existing RPi libraries.

Since this FPGA code modification is relatively simple to do, we can provide you with a bit file that does this, and provide you with instructions on how to flash that bit file onto your MATRIX Voice FPGA.

I will post the file with instructions here shortly so you can use it if you would like. Then, you could potentially use those MATRIX Voice GPIOs that come from the RPi to setup I2S communication using RPi libraries.



HI Samreen,

That’a a great news ! Thank you ! :heart_eyes:




The FPGA bit file which exposes Raspberry Pi pins 18, 19, 20 and 21 to MATRIX Voice GPIOs is attached below.
system.bit (333.3 KB)

To ensure that you downloaded the file correctly, please run the following terminal command to check if the bit file is the same.

md5sum system.bit

The value should be 4eda9cb48474427886700712cd7c4983.

This is the mapping of the pins

Follow this guide to flash the new bit file to your MATRIX Voice’s FPGA.

Some tips

  • Before starting the flashing guide, place this system.bit file in the /home/pi folder in your Raspberry Pi. You can do this on the microSD directly or via SFTP from your personal computer.
  • Make sure to run
    cd /usr/share/matrixlabs/matrixio-devices
    before flashing the SPI Flash bootloader onto FPGA using the following line
    xc3sprog -c matrix_voice blob/bscan_spi_s6lx9_ftg256.bit

I tested the new connections after flashing the FPGA using the terminal GPIO utility, and all the pins seem to have been mapped correctly. Keep in mind when programming that these are BCM pin mappings.

We have not tested with I2S or other libraries so let us know how it goes!


1 Like
Matrix voice GPIO


Thank you again ! Please give me time to buy and test the components and I will write the feedback.


1 Like

Hi !

I can’t test your program. When I install the matrixio-creator-init package, the I2S speaker stop working. Can I ask for help in this thread or is it better to start a new one ?



Hello @Piscenois,

We can continue on this thread.

When you install the matrixio-creator-init package, the default FPGA bit file will be flashed, so your I2S speaker will temporarily stop working.

Once you flash the FPGA with the bit file I provided using the directions here, make sure to follow all the way through to the part where you run the following.

sudo apt-mark hold matrixio-creator-init

and then power off your device with the following, unplug and replug after your Raspberry Pi indicator light blinks 10 times.

sudo poweroff

This prevents the matrixio-creator-init package from automatically updating so that it does not update and override your custom FPGA bit file. Then you should be able to use the pin mapping in the post above to wire up your I2S speaker and try out some existing Raspberry Pi I2S libraries.

Let me know if this is what you meant!



Hi Samreen,

The matrix voice isn’t plugged, only the speaker through the max98357 I2S ampli. So I think the FPGA isn’t the problem.
I tried to rollback /boot and /etc modifications :

  • removing the /boot/config.txt matrixio configuration
  • blacklisting or not loading the modules (snd_bcm2835, snd-dummy, bcm2835-v4l2)
    but the speaker doesn’t work !
    Then I saw than the link /sys/class/gpio/gpio18 was created by matrixio installation. And this GPIO is used by I2S. I didn’t find which script manage this GPIO. Do you know what it is used for ?



Hi @Piscenois,

I see what you mean now. We looked into the matrixio-creator-init installation files to see what the problem may be and think we have a quick fix for the gpio18 problem.

The matrixio-creator-init package detects whether the device connected is a MATRIX Creator or a MATRIX Voice and then flashes components and changes GPIOs respectively. However, it attempts to program the FPGA regardless. This is something we will improve in the future.

It seems the issue you are having could be because the fpga-program.bash file attempts to flash the MATRIX Creator’s FPGA and first resets the MATRIX Creator using gpio18.

Our quick fix for you is to navigate to the the following file and comment out the line which is program_creator.

sudo nano /usr/share/matrixlabs/matrixio-devices/fpga-program.bash

Then run

sudo /usr/share/matrixlabs/matrixio-devices/fpga-program.bash

The rest of the init package should be fine as is. Let us know how this goes for you!

Samreen & Yoel


Hi Samreen & Yoel,

It works ! Thank you. :heart_eyes:
But … during my research I discovered the 2 DF13 speaker outputs. I think it will be more elegant to use them :slight_smile: I’ll test them, just need male DF13.

Could you give me the system.bit source code please ?



Hi @Piscenois,

So glad it worked :smiley:

Let us know how the DF13 speaker output tests go!

The complete source code for system.bit is not open source yet as we have not made the microphone DSP open yet. The source code is basically what can be found here plus some simple mic DSP. In order to expose the Raspberry Pi pins 18-21 to MATIX Voice GPIOs 12-15, I made some minor modifications.

I basically followed this guide for each of those four pins.

If you would like the exact lines of code I changed/added, let me know, and I will provide them to you.



Hi @Samreen

Need time again to receive DF13 cables … This connector seems rare :confused:

I have to give you an explanation. I will need to redirect more RPi GPIO pins for 2 step / servo motors. I would prefer to be autonomous. With the source code I only need to copy/paste several lines to get something working without boring you.
Another solution is to build an intermediate board between RPi and M-Voice which duplicates the RPi GPIO port.



Hi @Piscenois,

Is there no way you could use the MATRIX Voice GPIO API to code the servo motors?

If you can use Python or JavaScript, MATRIX Lite JS and Py have very simple code to program servos. You can find code examples for JS here and Python here. We also have MATRIX HAL if you’re coding in C++.

Let me know if you have any questions.



Hi @Samreen,

You’re right. I didn’t think about this solution. Again, I need time to receive components and build a board (need to separate power for motors and RPi).
Thank you for all your help ^^



Hi @Piscenois,

Here you will find the full FPGA source code for the MATRIX Creator and MATRIX Voice. You can update the code to change open pin mappings as desired. We recently opened up the microphone DSP code on there so I can now provide it to you.

For the system.bit file I provided to you, I just followed this guide I showed you earlier for RPi BCM pins 18-21 mapping to MATRIX Voice GPIO pins 12-15.

Hope this helps for your future projects!



HI @Samreen,

I already saw and liked this news. I’m happy for you. I am certain that open source is the good idea. :hugs:
Thank you for telling me :kissing:

I’m not sure to use the matrix voice extension port. I’m wondering about using energy to make FPGA forward data through RPi GPIO and Matrix GPIO. So, I’ll try too an expansion board that give 3 RPi GPIO ports.