# Using SPI on Raspberry directly

I did try to find if and how it is possible to use the Serial Peripheral Interface (SPI) of the Raspberry Pi with Mathematica. I could find nothing so far so my conclusion now is: it is not possible. I wonder if this is true especially as MMA is shiped with the PI and has many specialiced PI functions and in addition is a versatile programming tool. Can someone comment on this please?

• I believe that you can do this with bobthechemist's package wiringPiLink. You can look at his projects, such as this, to see the package in action. If there's a problem, consider leaving a comment on one of his answers to notify him of this question. I don't have a Raspberry Pi at hand, so I can't try it. – C. E. May 17 '17 at 21:43

An extended comment rather than an answer at this point, subject to additional information from the OP.

Yes, you can interact with chips that use SPI communication through Mathematica, but as of yet, there are no turnkey solutions. Ideally, something along the lines of FindDevices["SPI"] would yield some type of useful connection, but I think the field (physical computing on the Raspberry Pi with Mathematica) is still a bit premature.

As mentioned in the comments, my wiringPiLink gives you a good example of the steps needed to communicate with an SPI chip. It involves the following steps:

• Writing c code that allows for communication with the kernel
• Create a package that creates Wolfram Language functions that call the relevant c functions.

In my experience, proof-of-concept programs can be created by referring to the example programs for the c-code device drivers (in the referenced case, WiringPi and the Wolfram tutorials for communicating with external programs.

Should you be willing to provide additional information about the project in mind (I presume it is not general SPI communication but a specific chip with which you wish to interact), please provide that information in your question and a more comprehensive answer may be possible.

• Thank you! I expected something like that. As I messed around with CUDA already, writing something in C should be doable. About the project: I want to read a puls sensor fully over night. Saving every puls would probably make a huge data set. So the idea is to read a puls train into MMA and look for unreagular puls frequency or abnormal signals and store only those. I donot have the pulse sensor yet. First is to check if I can read analog data via SPI. I will work through the material provided. Thanx 4 it – Eisbär May 18 '17 at 6:39
• @Eisbär can you tell me name of sensor (more importantly the communication chip) that you're thinking of using? WiringPi's SPI Library provides two convenient functions for SPI initialization and communication. Assuming that speed factors can be addressed, a generic Wolfram Device may be straightforward. – bobthechemist May 18 '17 at 13:52
• I would try to use MCP3008 and one of the pulse sensors you can find on the net for Arduino and Pi. – Eisbär May 18 '17 at 19:56
• @Eisbär since you are interested in the MCP3008, you should be able to use my wiringPiLink directly (since that's the one SPI device that I currently use). I'm happy to help troubleshoot if you do try it and run in to problems. – bobthechemist May 18 '17 at 21:42
• I Need to go through some learning link using MMA under Linux, compiling on PI and Basic GPIO usage. Then I can tackle the issue with reading the sensor. So it will take a while. Do you use the MPC3008 under MMA? – Eisbär May 19 '17 at 19:02