servo glitching out with gyro sensor due to amps

Hi everyone,

I recently got a 380 kg.cm servo motor

https://www.ebay.com/itm/2019-High-Torque-Servo-DC12V-24V-380kg-cm-Steel-Gear-for-Robot-Mechanical-Arm-US/153383502462?_trkparms=aid%3D111001%26algo%3DREC.SEED%26ao%3D1%26asc%3D20160727114228%26meid%3Da623e440a43e40a0838018112b7d6ecd%26pid%3D100290%26rk%3D1%26rkt%3D2%26sd%3D153383502462%26itm%3D153383502462%26pmt%3D0%26noa%3D1%26pg%3D2060778&_trksid=p2060778.c100290.m3507

I need to run this off of a big lipo battery which I have and a arduino along with controlling it by a gyro sensor. I can tell the servo to go to directions no problem and run it back and forth, I can even hook it up to and receiver with RC and it works. However when I hook the gyro to the arduino and then the arduino to the circuit board on the servo it glitches. It works for a little bit but if it goes to a curtain position or sometimes moves to fast or even just randomly it will start moving back and forth really fast and sometimes cut the readings off from the gyro. I think it might be a power problem but I have no idea. The code an circuitry works fine with a 9g servo.

Im confused as to why it doesn't work with the gyro and I need some help. If you have any questions let me know and I will answer them ASAP.

Im confused as to why it doesn't work with the gyro and I need some help

It is probably that the gyro sensor is using one of the timers and partly blocking the code that generates the servo pulses.

The solution is to generate the servo pulses in hardware, Adafruit have a board that will do this Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface [PCA9685] : ID 815 : $14.95 : Adafruit Industries, Unique & fun DIY electronics and kits

The other way is to rewrite the gyro library so that it doesn’t spend as much time with the interrupts disabled.

I do have an adafruit PWM servo driver like you showed are you saying I should use that. Also Im not using a interrupt pin. Does this effect anything.

Also Im not using a interrupt pin.

No but the servo library is using interrupts generated by Timer 2. Interrupts can come from many places not just pins.

are you saying I should use that

Yes.

Thanks for your help

Oh and one more thing. The adafruit servo driver requires pin SCL and SDA which are the same pins the gyro sensor needs. How does this work?

Thanks for your help

hert:
Oh and one more thing. The adafruit servo driver requires pin SCL and SDA which are the same pins the gyro sensor needs. How does this work?

Thanks for your help

Those pins are the shared I2C bus where each device must have a unique address. More here:

https://learn.sparkfun.com/tutorials/i2c/all

There are lots of hardware address pins on the chip in the Adafruit board, so you can set the I2C address to any one of 32 addresses. So you can avoid it having the same address as your gyro.

hert:
Oh and one more thing. The adafruit servo driver requires pin SCL and SDA which are the same pins the gyro sensor needs. How does this work?

That is just perfect! You connect your servo driver and your gyro to the same two pins as the I2C bus, and you can connect other I2C devices as well, saving other Arduino pins for different purposes.

jackmicro:
I could not understand this please explain.

You connect both the servo driver and the gyro to the same set of pins. So the Serial data pin on the Arduino’s pin A4 goes to both the Servo and gyro and also the serial clock pin A5 goes to both devices.

Connect all the address pins on the servo driver to ground.