After a bit of a fight, I managed to get wiringpi2 and the the wiringpi2 python wrapper installed on the NOOBS Raspbian PI distro. The Adafruit 4 channel logic level converter kept the PI safe and sending data to the Arduino was as simple as this on the PI side:
import wiringpi2
wiringpi2.wiringPiSPISetup(1,5000)
wiringpi2.wiringPiSPIDataRW(1,'HELLO WORLD\n')
and the Arduino code here from Nick Gammon.
So, I know the wiring works. But that's not the way round I actually want - I want to read a pin from the Arduino to the PI.
Well, ultimately, I've got to read the number of clicks from a rotary encoder since it was last read, and the direction turned. But right now I'd be happy to read ANYTHING!
I read the SPI reference which states:
This library allows you to communicate with SPI devices, with the Arduino as the master device.
The PI must be the master device. I thought I was doomed until I read Nick Gammon's excellent page about SPI which demonstrates 2 Arduinii talking to each other.
Also, the SPI transfer() command would suggest you CAN write from the Arduino.
I'm now at the stage where all the links of the the first 4 result pages of Google show as "followed" - so it's not for lack of Googling!
In theory, shouldn't this work if I use the READ method on the PI end? (Note: this is just one of many, many attempts, not the only one!)
#include <SPI.h>
void setup (void)
{
SPI.begin();
pinMode(MISO, OUTPUT);
// turn on SPI in slave mode
SPCR |= _BV(SPE);
}
void loop (void) {
SPI.transfer('TEST');
}
And on the PI end of things:
import wiringpi2
wiringpi2.wiringPiSPISetup(1,5000)
stuff = wiringpi2.wiringPiSPIDataRW(1,'\n')
print stuff
WiringPI says the incoming data will overwrite my data, and the SPIDataRW takes exactly 2 inputs, so shouldn't I be getting "test" back?
What am I missing here? Any pointers greatly appreciated.