Python Matrix Creator HAL using SPI


#1

I just wrote a simple python implementation for using everloop and some sensors directly over the spi / wishbone bus. This gives python developers a much better performance communicating fastly with the creator device.

The code is still under heavy development, eventually i’ll put it on PyPi as a new module.

It only uses matrixio-creator-init and python_periphery (SPI).

Cheers


[Solved] Unable to get sensor data of Matrix Creator on RPI 3b
Using gpio's for pwm through MALOS layer
#2

I was reading about the spi bus and trying to understand why it exists. Thank you for your clear instructions on enabling it on the pi. However, page 10 of this thread

https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=19489&sid=d515ca16640f843e377dd82670049b80&start=225

Has a post by bomba that indicates more configuration is necessary

Specifically
Add the device tree overlays in /boot/config.txt/

Bringing up the can interface and Adjusting the bitrate to match your needings.

Install can-utils

Are these steps needed ? I realize that’s an old thread and do not know if it’s relevant


#3

i don’t know, i use the default settings provided by the overlay / raspi-config and i don’t have any needs to change it. no lags so far. :slight_smile:


#4

Cool! Did you also manage to get the Sound from Matrix voice? Python Errors with pyaudio on missing matrix_micaray_channel8 (missing on the creator board and not in tmp…)


#5

Not realy it maybe possible to implement mic access through spi, but they are currently developing some kernel modules for pcm and other stuff, so it is better to wait for that (https://github.com/matrix-io/matrixio-kernel-modules), or to use the temp files. My next target is to implement some basic gpio access and eventually pwm. All in mind to switch to the kernel dirvers, when they are official available.


#6

Update

  • Docker example
  • python3 compatibility

#7

First attempts with GPIO / PWM, Looping Louie and he went crazy.


#8

Now you can build your own Looping Louie with Python. :slight_smile:

I have just commited the reimplementation of the python-matrixio-hal. It now uses the native cpp Matrix HAL drivers and not the SPI interface anymore. Follow the readme.

Change log:

  • GPIO / PWM support added + Led Examples (using GND and PIN 0)
  • setup script for installing as python package to your environment / virtualenv
  • the docker example is currently brocken, needs investigation
  • examples moved to examples folder
  • temporary fix for the everloop matrix HAL driver (brocken by myself, pull request is open).

Final thoughts:
The reimplementation is almost as fast as the old one, in some parts even faster. By moving away from the SPI device to the matrix drivers, it should be easier to keep the lib up to date in the future.

update:

  • docker example fixed

update
now you can install the package with pip:

pip install python-matrixio-hal

#9

This is nice! I have got the leds running on a docker, but I also want to be able to access the mic array.
I could not find then in your code, was is not implemented yet?


#10

I’m still waiting for the kernel modules to be officially released, then python developers can use pyaudio. What do you want to implement with the mic array? doa, speech recognition, or something else?


#11

I an creating an add-on for home assistant (Hass IO ).
So far I have split all the Snips services and have separate add ons for that.
An add-on for hassio is actually just a docker container, so I have used your example to build an addon.

This runs nice and the leds spin like a maniac :smiley:

So, next step is to be able to use the mic array to detect my hotword and do some nice visual effects :slight_smile:

I will see if a can post a small video :slight_smile:


#12

nice:

one way could be using snowboy it should work with arecord and the matrix alsa pipes, but the snd device needs to be forwarded to the docker container. an other way could be using the mics directly through the cpp hal drivers, but i did not implement that in the python driver. maybe i do some hacks on the weekend to get snowboy integrated in the python hal drivers, or pocket sphinx

you can also use the matrix malos services to implement your addons, there is also a wakeword detection engine. For me the python hal drivers are rather meant to be used for “performance” critical implementations, or simple applications where there is no need for the malos service overhead.

keep in mind the python hal driver is using the spi device with no locking mechanism so having multiple applications using the spi device could make some trouble with the mic array. thats one reason they are implementing the matrix kernel modules, to coordinate the different driver to not use the spi device in parallel.


#13

I actually have a Snowboy Addon to work with Snips, see my repo here:

I want to implement the hermes protocol from Snips, so this Matrix add on will need to function as the Audio Server. The HotWord add-on (already working), will then hopefully be able to light up the leds if the hotword is detected.
At this point, all the addon play nice together, I use the Snips Audio Server for now. This works with the alsa drivers (usb mic).

I do not know if you are familiar with HassIO, but that is based on a resin image, but with spi enabled.
You can not install any software on it (well, you can but that kinda blows the whole hassio idea)
I tried to get things going on docker with the matrix malos (and the kernel modules), but could not (yet) get things running when I saw this post. The kernel modules was my first point, so that the different apps using SPI would not clash (in theory)
So I tried to get your example running and was happy it worked! After that I saw no options to access the mic_array.
While I would really like to have it, at this point I am one step further being able to access the Matrix Voice on a docker container, in the form HassIO Addon :slight_smile:

My next step will probably be to see if I can get the kernel models running in a container and hopefully as an addon after that.


#14

ah ok, maybe we can discuss that on a chat plattform (hangout, irc.) write me a private message, so i can share you some of my experience with the matrix stuff.


#15

Ok cool, although my weekend is quite occupied :wink:
This is my video by the way: https://www.youtube.com/watch?v=odDbyB3Ql-U


#16

I have got the MalOS working in a docker now and could run the everloop.js :slight_smile:

That is a big step forward for me, next to try the micarray


#17

update

python-matrixio-hal version 1.1.0 got released

Changelog:

  • support for the new matrix cpp hal drivers
  • it now supports both kernel modules and the legacy spi-device
  • use of the new firmware version and everloop size detection