For Part 1 see SAMD21 using SPI

We already saw how to initiate SPI communication between a Pi and a SAMD21 (e.g. Adafruit Feather M0). Initially we had some issues using Python and that is why we used C++ instead. But this example also works very well.

"""
 J.A. Korten March 10, 2018
  Modified based on code by joan
  https://raspberrypi.stackexchange.com/questions/44277/spi-raspberry-pi-master-and-arduino-slave
  
"""
 
#!/usr/bin/env python

# mini-spi.py
# 2016-03-18
# Public Domain

import time

import pigpio # http://abyz.co.uk/rpi/pigpio/python.html

pi = pigpio.pi()

if not pi.connected:
   exit(0)

h = pi.spi_open(0, 40000)

stop = time.time() + 120.0

n = 0

while time.time() < stop:

   n += 1
   pi.spi_xfer(h, "Hello Arduino {}\n".format(n))
   time.sleep(1)

pi.spi_close(h)

pi.stop()

 

Now the only thing left is doing the reverse: sending text from the Arduino (SAMD21) to the Raspberry Pi. Some inspiration (for now): http://robotics.hobbizine.com/raspiduino.html

Note: this is not yet tried for the SAMD21 and still in C++ for the Raspberry Pi side where I would prefer it to be Python there.

See also: http://radiostud.io/understanding-spi-in-raspberry-pi/

To finish things off Part 3: Bi-directional communication between a Pi and a SAMD21.