Arduino Wifly shield with SPI

arduinopwmspiwifly

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.

Best Answer

To answer the PWM ports question, if the WiFly takes up a couple of the hardware PWMs then you will have to use a standard GPIO and use software PWM for the other motors.

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);

If you don't fancy trying to write your own, there is an Arduino Soft PWM library that does up to 16 channels.