Using Servo.h it is possible to run a servo from just about any pin.....obviously the more pins the more servos...hence the question " how can I do this with a MCP23017 ? ". I have searched the web a fair bit but no luck. Is there a modified Servo library out there?? It's such an obvious solution i figure it must have been done before. Any suggestions..Thanks.
Using Servo.h it is possible to run a servo from just about any pin.....obviously the more pins the more servos...hence the question " how can I do this with a MCP23017?
The Servo library could be modified to allow toggling of GPIO pins on a MCP23017 but there are some issues with timing.
The library uses Timers and Interrupt Service Routines (ISR) to handle the pulse width. The servo pin is toggled in the ISR.
At 100 KHz (100 Kbps) I2C at least 3 bytes need to be transmitted to the MCP230017 to toggle a pin. That is approx. 300 us and not possible to do from the Servo ISR. Another execution pattern is required.
Theoretically, yes. It would be pretty interesting to see, but running multiple servos would account for a huge amount of what you can reasonably do with your code and probably be a huge headache.
Perhaps a better solution would be to use a PWM expander like the PCA9685.
how can I do this with a MCP23017 ? ".
you can but it would be fairly expensive in processing power, as you need to keep track of both rising and falling edges of every channel at all times, and send the data to the chip -> may not be doable given i2c's speed limitations.
I have searched the web a fair bit but no luck.
I wrote a variety of approaches / implementations on driving multiple servo channels off of one timer, with or without output compare, here: https://dannyelectronics.wordpress.com/2017/02/18/driving-multiple-servos-off-a-pic-timer2-ranged-extended/
it will branch out to a few other variants, depending on resources available to you.
For PWM, the MCP23017 would have to be software-driven. I would suggest one of the PCA9685 boards, which give you hardware PWM (and can also provide digital pins). These are a bit more expensive, but very easy to use, and are driven by I2C in the same way.