Choosing the best way to use GY-521

I am working on a bit of project, and the first proper electronics based project in a long while, and even longer since I used any C language.

Any way the project is a self levelling platform based on a project I found on thingiverse which has been updated to carry a bit more weight.
This I my variant so far, with updates and testing still coming off the printer.

while things are printing I have been taking the opportunity to refamiliarize myself with various things.

I have been playing with various libraries to try and get angle information from a GY-521 breakout board.
To this end I have found that some of the libraries put out the angle that creeps in either direction even when it is sat still. This appears to be caused by the gyro returning to tis zero position within the hardware.

Would I be best to get close to "0" using the gyro info, and then final adjustment using the accelerometer. Or is there a better approach to this?

If the platform isn't moving rapidly, just ignore the gyro component. The accelerometer defines "down" and the associated tilt angles.

Ignore any code you find that leads to angles that creep -- the code is just plain wrong, and there are plenty of bad code examples out there for that particular sensor.

This is the simplest accelerometer tilt code for the MPU-6050 (the sensor on your module)

// minimal MPU-6050 tilt and roll (sjr)
// works perfectly with GY-521, pitch and roll signs agree with arrows on sensor module 7/2019
// tested with eBay Pro Mini, **no external pullups on SDA and SCL** (works with internal pullups!)
//
#include<Wire.h>
const int MPU_addr1 = 0x68;
float xa, ya, za, roll, pitch;

void setup() {

  Wire.begin();                                      //begin the wire communication
  Wire.beginTransmission(MPU_addr1);                 //begin, send the slave adress (in this case 68)
  Wire.write(0x6B);                                  //make the reset (place a 0 into the 6B register)
  Wire.write(0);
  Wire.endTransmission(true);                        //end the transmission
  Serial.begin(9600);
}

void loop() {

  Wire.beginTransmission(MPU_addr1);
  Wire.write(0x3B);
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr1, 6, true); //get six bytes accelerometer data

  xa = Wire.read() << 8 | Wire.read();
  ya = Wire.read() << 8 | Wire.read();
  za = Wire.read() << 8 | Wire.read();
// formula from https://wiki.dfrobot.com/How_to_Use_a_Three-Axis_Accelerometer_for_Tilt_Sensing
  roll = atan2(ya , za) * 180.0 / PI;
  pitch = atan2(-xa , sqrt(ya * ya + za * za)) * 180.0 / PI; //account for roll already applied

  Serial.print("roll = ");
  Serial.print(roll,1);
  Serial.print(", pitch = ");
  Serial.println(pitch,1);
  delay(400);
}

Thank you for that.
I need to read the website in more detail, but have made I quick test code based on you code and what I had for initial motion testing. I found that it is actually fast enough to get erroneous results if at least some delay isn't used before taking a reading - 10 milliseconds seems to be enough at the moment. That kind of a pause isn't really perceptatble to most humans.

// minimal MPU-6050 tilt and roll (sjr)
// works perfectly with GY-521, pitch and roll signs agree with arrows on sensor module 7/2019
// tested with eBay Pro Mini, **no external pullups on SDA and SCL** (works with internal pullups!)
//
#include<Wire.h>
const int MPU_addr1 = 0x68;
float xa, ya, za, roll, pitch;

int enabl = 8;
int z_dir = 7;
int z_stp = 4;

int x_dir = 5;
int x_stp = 2;

int y_dir = 6;
int y_stp = 3;

int count = byte();
int i = int();
int direct = byte();
int stp_out = byte();
int q = byte();
int stp_dir = byte();

void setup() {

  Wire.begin();                                      //begin the wire communication
  Wire.beginTransmission(MPU_addr1);                 //begin, send the slave adress (in this case 68)
  Wire.write(0x6B);                                  //make the reset (place a 0 into the 6B register)
  Wire.write(0);
  Wire.endTransmission(true);                        //end the transmission
  Serial.begin(9600);
  DDRD = B11111111;
  pinMode(enabl, OUTPUT);
  digitalWrite(enabl, LOW);
  i = 1;
  q = B00000000;
  stp_out = B00011100;
  direct = B11100000;
  count = 0;
  Serial.println("Start");
  Sends();
}

void loop() {
  if (i == 1){
   PORTD = B00011100;
    //digitalWrite(z_dir, LOW);
    //digitalWrite(x_dir, LOW);
    //digitalWrite(y_dir, LOW);
    i = 0;
  }
  else {
   PORTD = B11111100;
    //digitalWrite(z_dir, HIGH);
    //digitalWrite(x_dir, HIGH);
    //digitalWrite(y_dir, HIGH);
    i = 1;
  }
      
  //Serial.println(" ");
  for (count =0; count <=800; count++){
    digitalWrite(z_stp, HIGH);
    //digitalWrite(x_stp, HIGH);
    //digitalWrite(y_stp, HIGH);
    delay (1);
    digitalWrite(z_stp, LOW);
    //digitalWrite(x_stp, LOW);
    //digitalWrite(y_stp, LOW);
    delay (1);
  }
  delay (10);
  Sends();
  for (count =0; count <=800; count++){
    //digitalWrite(z_stp, HIGH);
    digitalWrite(x_stp, HIGH);
    //digitalWrite(y_stp, HIGH);
    delay (1);
    //digitalWrite(z_stp, LOW);
    digitalWrite(x_stp, LOW);
    //digitalWrite(y_stp, LOW);
    delay (1);
  }
  delay (10);
  Sends();
  for (count =0; count <= 800; count++){
    //digitalWrite(z_stp, HIGH);
    //digitalWrite(x_stp, HIGH);
    digitalWrite(y_stp, HIGH);
    delay (1);
    //digitalWrite(z_stp, LOW);
    //digitalWrite(x_stp, LOW);
    digitalWrite(y_stp, LOW);
    delay (1);
  }
  //Serial.println("Level");
  delay (10);
  Sends();
  Serial.println();
}

void Sends(){
  Wire.beginTransmission(MPU_addr1);
  Wire.write(0x3B);
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr1, 6, true); //get six bytes accelerometer data

  xa = Wire.read() << 8 | Wire.read();
  ya = Wire.read() << 8 | Wire.read();
  za = Wire.read() << 8 | Wire.read();
// formula from https://wiki.dfrobot.com/How_to_Use_a_Three-Axis_Accelerometer_for_Tilt_Sensing
  roll = atan2(ya , za) * 180.0 / PI;
  pitch = atan2(-xa , sqrt(ya * ya + za * za)) * 180.0 / PI; //account for roll already applied

  //Serial.print("roll = ");
  Serial.print(roll,0);
  Serial.print(" ");
  //Serial.print(", pitch = ");
  Serial.println(pitch,0);
  return;
}

Code that uses the internal MPU-6050 DMP (Digital Motion Processor), for example, the Jeff Rowberg library, works very well to merge in the gyro component, but it is much larger and fairly unwieldy.

Worth a try if you decide that the short delay is a problem.

I will bare that in mind.
I don't think it will be a problem unless I decide to go active levelling. There a lot better way to active level than this mechanism so I don't think that is going be an issue.