2
\$\begingroup\$

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.

\$\endgroup\$
4
  • \$\begingroup\$ 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? \$\endgroup\$
    – Oli Glaser
    Aug 15, 2012 at 0:23
  • \$\begingroup\$ 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? \$\endgroup\$ Aug 15, 2012 at 1:51
  • \$\begingroup\$ 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. \$\endgroup\$ Aug 15, 2012 at 1:52
  • \$\begingroup\$ 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. \$\endgroup\$
    – Oli Glaser
    Aug 15, 2012 at 2:14

1 Answer 1

1
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.