servo beug manette (Driver Moteur L298N et nrf24l01)

Bonjour a tous,

J'aimerai faire une manette avec le module nrf24l01 afin de contrôler un servomoteur et un driver pour moteur continue (L298N )

Cependant j'ai un petit problème lorsque le moteur tourne et le servo reste au neutre, il reçoit comme informations 80 puis 0 puis 80 puis 0. Du coup il bouge dans tous sens
Savez vous pourquoi ?

Sinon, quand le moteur ne tourne pas, le servo reçoit bien l’information et tourne correctement.

#include <Servo.h>
Servo myservo;

const int SW_pin = 2; // digital pin 
const int X_pin = 1; // analog pin 
const int Y_pin = 0; // analog pin 

//Ports de commande du moteur B
int motorPin1 = 6;
int motorPin2 = 5;
int enablePin = 3;

// Vitesse du moteur
int state = 0;
int gouv;

//  * * * * * * * * ** *   recepteur   * ** * * * *
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>


RF24 radio(9, 8);  // CE, CSN

//address 
const byte address[6] = "00001";

void setup()
{

  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(enablePin, OUTPUT);

  pinMode(SW_pin, INPUT);
  digitalWrite(SW_pin, HIGH);
  Serial.begin(9600);

  gouv = 0;
  myservo.attach(7);


  while (!Serial);
  Serial.begin(9600);

  radio.begin();
  radio.openReadingPipe(0, address);  //set the address
  radio.startListening();  //Set module as receiver
}

void loop()
{
  
  if (radio.available())//Read the data if available in buffer
  {
    float donnees[2] = {0};
    radio.read(&donnees, sizeof(donnees));



    if (donnees[0] >= 510) {
      state = abs(map(donnees[0], 510, 1023, 0, 200));
      digitalWrite(motorPin1, HIGH);
      digitalWrite(motorPin2, LOW);

    }

    else if (donnees[0] < 521 && donnees[0] >= 411) {
      digitalWrite(motorPin1, HIGH);
      digitalWrite(motorPin2, HIGH);

    }

    else {
      state = abs(map(donnees[0], 0, 510, 200, 0));
      digitalWrite(motorPin1, LOW);
      digitalWrite(motorPin2, HIGH);

    }
    analogWrite(enablePin, abs(state));


//  Serial.print(digitalRead(SW_pin));

    gouv = abs(map(donnees[1], 0, 1023, 0, 180));
    Serial.println(gouv);
    myservo.write(gouv);
    delay(20);


  }
}
//    **  **  **  *  *  *  *   emmeteur   * * * * *  ** *  ** * *
// !! !! !! 3.3 V

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>


RF24 radio(9, 8);  // CE, CSN

//address
const byte address[6] = "00001";

void setup()
{

  Serial.begin(9600);

  radio.begin();
  radio.openWritingPipe(address);  //set the address
  radio.stopListening();  //Set module as transmitter
}
void loop()
{


  float donnees[2];

  donnees[0] = analogRead(Y_pin);
  donnees[1] = analogRead(X_pin);
  radio.write(&donnees, sizeof(donnees));
delay(20);



}

Bonne journée
Paul

Tes codes sont bizarres, ils mélangent leurs variables : X_pin est défini dans un code et utilisé dans l'autre...
AnalogRead ne renvoie pas un float, mais un int...

Bref, étudie mieux ton code et la syntaxe Arduino.

A oui en effet merci
Voila le code mis à jour :

//    **  **  **  *  *  *  *   emmeteur   * * * * *  ** *  ** * *
// !! !! !! 3.3 V

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>


const int SW_pin = 2; // digital pin
const int X_pin = 1; // analog pin
const int Y_pin = 0; // analog pin


RF24 radio(9, 8);  // CE, CSN

//address
const byte address[6] = "00001";

void setup()
{

  Serial.begin(9600);

  pinMode(SW_pin, INPUT);
  digitalWrite(SW_pin, HIGH);

  
  radio.begin();
  radio.openWritingPipe(address);  //set the address
  radio.stopListening();  //Set module as transmitter
}
void loop()
{


  int donnees[2];

  donnees[0] = analogRead(Y_pin);
  donnees[1] = analogRead(X_pin);
  radio.write(&donnees, sizeof(donnees));
  delay(20);



}
#include <Servo.h>
Servo myservo;


//Ports de commande du moteur B
int motorPin1 = 6;
int motorPin2 = 5;
int enablePin = 3;

// Vitesse du moteur
int state = 0;
int gouv;

//  * * * * * * * * ** *   recepteur   * ** * * * *
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>


RF24 radio(9, 8);  // CE, CSN

//address
const byte address[6] = "00001";

void setup()
{

  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(enablePin, OUTPUT);


  Serial.begin(9600);

  gouv = 0;
  myservo.attach(7);


  while (!Serial);
  Serial.begin(9600);

  radio.begin();
  radio.openReadingPipe(0, address);  //set the address
  radio.startListening();  //Set module as receiver
}

void loop()
{

  if (radio.available())//Read the data if available in buffer
  {
    int donnees[2] = {0};
    radio.read(&donnees, sizeof(donnees));



    if (donnees[0] >= 510) {
      state = abs(map(donnees[0], 510, 1023, 0, 200));
      digitalWrite(motorPin1, HIGH);
      digitalWrite(motorPin2, LOW);

    }

    else if (donnees[0] < 521 && donnees[0] >= 411) {
      digitalWrite(motorPin1, HIGH);
      digitalWrite(motorPin2, HIGH);

    }

    else {
      state = abs(map(donnees[0], 0, 510, 200, 0));
      digitalWrite(motorPin1, LOW);
      digitalWrite(motorPin2, HIGH);

    }
    analogWrite(enablePin, abs(state));


    //  Serial.print(digitalRead(SW_pin));

    gouv = abs(map(donnees[1], 0, 1023, 0, 180));
    Serial.println(donnees[1]);
    //Serial.println(gouv);
    myservo.write(gouv);
    delay(20);


  }
}

Affiche les valeurs du tableau donnee dans le code de l'émetteur et dans celui du récepteur, afin qu'un puisse voir les différences