SPI Serial Communication and Servo Control Issue

Hello, first post here.

I have an SPI interface with my Raspberry Pi that currently uses up pins 10 through 13. I am aware that using the Arduino servo library disables PWM on pins 9 and 10 and servotimer2 disables PWM on pins 3 and 11.

Without changing hardware, is it possible to change the library to disable pins 10 and 11 instead?

No. The PWM pins are linked in pairs. You can't split a pair. It's a limitation of the hardware.

But you don't have to use 10 for SPI. You just have to use it as an output, not an input, for SPI to work. It can be a PWM output, if you want.

So let me see if I follow.

I don't need 10 for SPI since I have only one device, I can just use 11 and 13 for MOSI and SCLK? I dont need 12 because my Arduino never communicates back to the Pi.

That allows me to use 3/5 for my sonars and 9/10 for my motors. This should theoretically work?

I don't need 10 for SPI since I have only one device

You DO need to set pin 10 as an OUTPUT, which defines that the Arduino is the SPI master.

You do not need to use pin 10 as the chip select pin, but you do need to have a chip select pin.

I've been using the Arduino as the SPI slave, the RPi as the SPI master because it is the one sending commands. I'm assuming that once you set 10 to OUTPUT you can't use it as a slave anymore?

cmccrave:
I've been using the Arduino as the SPI slave, the RPi as the SPI master because it is the one sending commands. I'm assuming that once you set 10 to OUTPUT you can't use it as a slave anymore?

I think that that is a valid assumption. That might be a problem. You could use a Mega, which has SPI on different pins.

I don't know what happens if you set pin 10 as INPUT, then initialize SPI, and then set pin 10 as OUTPUT. Be worth performing a test.

I'll give it a shot if I get a chance, I'm thinking of just reducing to one sonar and save a huge headache. I appreciate the help!

cmccrave:
I've been using the Arduino as the SPI slave, the RPi as the SPI master because it is the one sending commands. I'm assuming that once you set 10 to OUTPUT you can't use it as a slave anymore?

Ahhh! Yes. If your Uno is an SPI slave then 10 must be an input and it must be the CS function.

You could try a Micro or Leonardo. They have a slightly different mix of capabilities on their pins. A Teensy can do PWM on all pins and it can use alternate pins for SPI. A Mega or Due has a lot more pins, so you have a lot more choice for outputs.