# Arduino Wifly shield with SPI

I have an Arduino Uno with a WiFly shield. I want to use 5 PWM ports on the Arduino to control motors, but some of the PWM ports are used by the WiFly. Looking into it I think I need to use the SPI bus but I'm not sure if this is possible with the WiFly shield or how to go about it.

I'm not sure how I'm supposed to wire the motors so that they can work alongside the WiFly.

If you could point me to a tutorial (I haven't been able to find one similar enough to my case to understand) or if you could give me some pointers, that would be great.

Thanks.

• The WiFly uses SPI according to the product page. Have you gone through all the documentation and the tutorials or tried using the WiFly Library? What specifically do you not understand - is it just the motor wiring or the SPI comms as well? – Oli Glaser Aug 15 '12 at 0:23
• Mainly the motor wiring and whether or not this is possible is what I don't understand. So from the documentation, pin 11 is MOSI and pin 10 is CS. Does that mean that I could connect a motor (or servo) to pin 11 and control it if I bring pin 10 high? And then when I bring it low again, the WiFly would resume using pin 11? – user1425706 Aug 15 '12 at 1:51
• To clarify, when I say connecting a motor, what I am actually doing is connecting it to a speed controller which takes a PWM input which is connected to a motor. – user1425706 Aug 15 '12 at 1:52
• No, you can't share the PWM with the SPI unless you don't mind the motor behaving strangely whilst sending data over the SPI (the WiFly wouldn't mind if you keep CS high). I think the best way is to use some soft PWM as described in my answer. Alternatively you can bitbang the SPI (i.e. soft SPI) and uses different pins for the WiFly, but that's mainly an arbitrary choice (might be worth it if your micro is pushed and hardly use the SPI, as it would avoid the repetitive interrupt) Either way is easy enough. – Oli Glaser Aug 15 '12 at 2:14

The basic idea with software PWM is to setup a timer with interrupt and increment a variable by one (from 0 to 255) on each interrupt. Also in the interrupt you compare a "duty cycle" variable and set/reset the pin accordingly e.g. GPIO_Pin = (duty_cycle > count);