An SPI communication example project can be found at XMOS startKIT: Building an XMOS and Raspberry Pi Robot XMP-1. As shown in this website, we first enable access to the RPi SPI hardware using the interface executed from the command:
We update Rpi modules (may take several minutes):
And install Python SPI module:
Bear in mind that this setup is only Python 2 compatible (not Python 3). Access to any GPIO is also conditioned to sudo privileges. To open the compatible Python command promp we do:
The example also provides sample code for both XMOS (complete project) and RPi (C# code for gcc compiling and java script). The XMOS sample code implements a SPI slave that expects messages based on a TLV (TagLenghtValue) protocol to set the PWM duty cicles of 8 XMOS outputs.
Interface the a compatible TLV message in Python for this example is easy. We need to set the SPI mode, frequency and send the expected bytes. The following code (a Python 2 script) implements a basic servo control that turns it from 0 to 180 degrees in slow steps than quickly comes back to 0 quickly:
Team Pi over 4