If you want to program MG995 360 degree servo in Raspberry Pi, you need to PCA9685 module to generate PWM signal. As MG955 needs large current to work, you must provide external power to PCA9685 module. Raspberry Pi can not provide current to work.

If  you don’t have PCA9685 PWM module,  you can purchase it from this link: https://osoyoo.store/products/pca9685-compatible-module?variant=32079312879727

here is the connection between Raspberry Pi and PCA9685.

Connect MG995 servo to PWM port 15 in PCA9685 module

Software Installation:

1)Enable I2C in Raspberry Pi by following command:

sudo raspi-config

Then select Interfacing Options->I2C->Yes->Ok->Finish

2)install GPIO library if you are using old Raspberry Pi OS

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install rpi.gpio

3)If you haven’t installed PCA9685 driver, please run following command:

sudo pip3 install adafruit-pca9685

4)Download sample code by following command:

wget http://osoyoo.com/picture/RPi_Robot_Car/mg995.py

Run the code by following command:

python3 mg995.py

Explanation of above code:
line 19 start the servo rotation

pwm.set_pwm(15, 0, 100)

After rotating one second, servo is stopped by line 21 :

pwm.set_pwm(15, 0, 0)