Stepper moteur + QMC5883l

Bonjour,
J'ai un problème :
Je désire faire une boussole et que mon Stepper moteur s'oriente vers le Nord à chaque fois que je bouge. Pour connaître la direction du Nord, j'utilise un magnétomètre : Le QMC5883l. Il me donne des valeurs entre 0 et 360 degrés.

#include <Wire.h>
#include <MechaQMC5883.h>
#include<Stepper.h>

int nombreDePas = 2048; //nombre de position du moteur
Stepper monMoteur(nombreDePas,9,11,10,8); //Information du moteur

MechaQMC5883 qmc;

void setup() {
  Wire.begin();
  Serial.begin(9600);
  qmc.init();
  //qmc.setMode(Mode_Continuous,ODR_200Hz,RNG_2G,OSR_256);
  monMoteur.setSpeed(9);
}

void loop() {
  int azimuth;
  
  
  int x, y, z;
  
  //float azimuth; //is supporting float too
  qmc.read(&x, &y, &z,&azimuth);
  
  
  int posM ;
  posM = azimuth*5.68;
  if(posM >360){
    posM=posM-360;
    monMoteur.step(posM);}
    else{
  monMoteur.step(-posM);}

  Serial.print(" a: ");
  Serial.print(azimuth);
  Serial.println();

  
  delay(100);
}

Je ne sais pas si j'ai été claire, mais j'aimerais avoir un petit peu d'aide.

J'ai aussi essayer avec la fonction map() mais je n'ai pas vraiment eu de bon retour.

Mon Stepper moteur fait 2048 pas, un moteur pas a pas que l'on trouve dans tout les kits de base.

Merci de bien vouloir m'aider

What do you get in your serial output for azimuth?

if you prefer to write in french please post in the french subforum

wildbill:
What do you get in your serial output for azimuth?

I have degrees :

I assume that as the stepper turns, so does the compass.

What's going on here?

  posM = azimuth * 5.68;
  if (posM > 360)
  {
    posM = posM - 360;
    monMoteur.step(posM);
  }

wildbill:
I assume that as the stepper turns, so does the compass.

What's going on here?

  posM = azimuth * 5.68;

if (posM > 360)
  {
    posM = posM - 360;
    monMoteur.step(posM);
  }

I just try something, I tried many things but it wasn't working...

before translating the functionality into code it is a good idea to analyse "in normal words" what should this "control" do

maybe start at compass-arrow on the axle of your steppermotor is adjusted to north. Now you turn it clockwise for something like 20-60 degrees. What will the magentometer measure and which direction has your steppermotor to turn to re-adjust your compass-arrow to point to exact north again?

best regards Stefan
any newbee can apply the most professional habit from the first line of code they write on their own:
add only ONE thing at a time. Test/debug that ONE thing until that ONE thing works reliable - repeat.
The sad thing is: only the REAL professionals write code this way.