Finding pins for Eye To See

A project log for 127 TowerPro Servos, one I2C interface.

Taking the cheap and strong TowerPro MG995 servos (and siblings) and reprogramming them to accept commands and report position via I2C.

willWill 11/24/2015 at 20:315 Comments

A comment from [gficht] on the previous log asked "How do you plan on controlling the i2c lines with no pins to spare?". Which is a great question, and I thought it would be better to respond with a longer post. [Radimor] suggested 1-wire. I've considered both.

On the micro, there is one spare pin - pin 4, which is the original pulse signal input. My first thought was to use 1-wire on this pin, really easy, no circuit mods required - can even use the original cable. However, after looking at the datasheet for this I/O pin, it is only capable of being an input. There is no output driver. I also want an output so that you can also retrieve information on the servo position and torque and other such parameters. 1-wire also needs some rather accurate timing which might be tricky to bit bash on the PIC12 (while doing everything else at the same time).

For I2C you need two pins, one for the clock and one for the data. The data needs to be an output, the clock could be an input only (since it is driven by the master), but if the clock is an output then we could do clock stretching to adapt the clock rate.

The servo circuit has an 8MHz resonator connected between pins 2 and 3. The PIC12F675 has an internal 4MHz RC oscillator. So we can take the resonator off, and use those pins as I/O. Two spare I/O pins, and one spare input pin. The cost, is a halving in performance for the micro, down to 1 million operations per second (4 cycles per op).

The resonator is also a through-hole component, so soldering two wires will be relatively easy.

The remaining question is, what would you do with the spare input pin? Drop your ideas in a comment.


gficht wrote 11/25/2015 at 23:11 point

that was my only guess, to remove the quartz. I'm on my phone right now, so can't dig up the datasheet, are the clock pins also responsible for i2c or will you be bitbanging? if the latter, why not go for uart and doing something dynamixel compatible?

also, where do you get your towerpros? i've seen so many, that the insides differed in units from the same batch

  Are you sure? yes | no

deʃhipu wrote 11/26/2015 at 22:22 point

Serial is not a bus, so you would only have a single servo per 2 pins, unless you could somehow find a fourth free pin, to do serial forwarding, like the dynamixels do.

  Are you sure? yes | no

deʃhipu wrote 11/25/2015 at 20:36 point

current sense on the motor?

  Are you sure? yes | no

Will wrote 11/25/2015 at 20:42 point

Yeah good thought. This you can estimate from the PWM being applied to the motor. I've called this torque.

  Are you sure? yes | no

gficht wrote 11/25/2015 at 23:10 point

that's only true if you know the PID settings inside, but if you're going to rewrite the whole thing, then it's feasible ;)

  Are you sure? yes | no