Vai al contenuto
PLC Forum


Problema con servo motore


Chris41

Messaggi consigliati

Buongiorno a tutti 

Sto cercando di realizzare un progetto trovato in rete . utilizza un arduino nano un display nextion due motori passo passo ed un servomotore nello specifico è un automatismo per spelare un filo il progetto lo trovate a questo link:

https://electricdiylab.com/diy-arduino-based-wire-cutting-machine/

Il progetto è spiegato abbastanza bene ci sono delle lacune in alcuni punti ma nulla che non si possa superare e risolvere . naturalmente c'è anche il codice da caricare su arduino nano con le varie librerie da utilizzare . quindi tutto ben fatto .

Però ho un problema e sono alcuni giorni che stò provando a risolverlo senza grandi risultati nello specifico non funziona il servomotore collegato sul pin D9 ho verificato ogni singola riga del codice compresa la mia libreria servo.h e tutto è corretto . ho provato con un servo analogico e anche uno digitale ma nulla . i due motori passo passo funzionano correttamente mentre il servo non va , ho verificato le connessioni e sono corrette . ho anche provato a caricare su un arduino uno un codice per controllare un servo motore e il tutto funziona ma se ricollego lo stesso servo ad arduino nano non funziona più.

Qualcuno sa darmi un indicazione un aiuto su dove potrebbe essere l'errore .

Grazie a tutti 

Link al commento
Condividi su altri siti


12 minuti fa, Chris41 ha scritto:

Qualcuno sa darmi un indicazione un aiuto su dove potrebbe essere l'errore .

 

Pubblica il tuo sketch completo, altrimenti non posso capire dove è l'errore

Link al commento
Condividi su altri siti

ecco il codice sketch:

#include <Stepper.h>
#include <Arduino.h>
#include "BasicStepperDriver.h"
#include "MultiDriver.h"
#include "SyncDriver.h"
#include <SoftwareSerial.h>
#include <Servo.h>
//SoftwareSerial mySerial(2, 3); // RX, TX
Servo myservo;
int A = 0;
int B = 0;
int state = 0;
String message;
int QTY, numMessages, endBytes;
byte inByte;
int flag = 0;
int C=0;
float D=0;
int E=0;
int Start = 22;
int End = 31;

#define MOTOR_STEPS 200
#define DIR_X 7
#define STEP_X 4
#define DIR_Y 6
#define STEP_Y 3
#define MICROSTEPS 16
#define MOTOR_X_RPM 50
#define MOTOR_Y_RPM 200


BasicStepperDriver stepperX(MOTOR_STEPS, DIR_X, STEP_X);
BasicStepperDriver stepperY(MOTOR_STEPS, DIR_Y, STEP_Y);
SyncDriver controller(stepperX, stepperY);


void setup()
{
  numMessages, endBytes = 0;
  myservo.attach(10);
  
  Serial.begin(9600);
  //mySerial.begin(9600);
  stepperX.begin(MOTOR_X_RPM, MICROSTEPS);
    stepperY.begin(MOTOR_Y_RPM, MICROSTEPS);
    myservo.write(Start);
  delay(2000);
  
}

void loop()
{

   data();

 if (A > 0 && B > 0 && C > 0) {
delay(2000);

for (int i = 0; i < C; i++){
controller.move(A*25, 0 );
delay(500);
controller.rotate(0, 360 );
delay(500);
controller.move(B*25, 0 );
delay(500);
controller.rotate(0, 360 );
delay(500);
controller.move(A*25, 0 );
delay(500);
myservo.write(End);
delay(500);
controller.rotate(0, 360 );
delay(500);
myservo.write(Start);
delay(500);
Serial.print(i);
}
A=0;
B=0;
C=0;
 }

}

  


  void data() {
    if (state == 0) {
      if (numMessages == 1) { //Did we receive the anticipated number of messages? In this case we only want to receive 1 message.
        A = QTY;
        Serial.println(A);//See what the important message is that the Arduino receives from the Nextion
        numMessages = 0; //Now that the entire set of data is received, reset the number of messages received
        state = 1;
      }
    }

    if (state == 1) {
      if (numMessages == 1) { //Did we receive the anticipated number of messages? In this case we only want to receive 1 message.
        B = QTY;
        Serial.println(B);//See what the important message is that the Arduino receives from the Nextion
        numMessages = 0; //Now that the entire set of data is received, reset the number of messages received
        state = 2;
      }
    }

if (state == 2) {
      if (numMessages == 1) { //Did we receive the anticipated number of messages? In this case we only want to receive 1 message.
        C = QTY;
        Serial.println(C);//See what the important message is that the Arduino receives from the Nextion
        numMessages = 0; //Now that the entire set of data is received, reset the number of messages received
        state = 0;
      }
    }

 

Link al commento
Condividi su altri siti

10 ore fa, Chris41 ha scritto:

il servomotore collegato sul pin D9

Il codice però dice diversamente:

2 ore fa, Chris41 ha scritto:
myservo.attach(10);

 

 

Ciao, Ale.

Link al commento
Condividi su altri siti

11 ore fa, ilguargua ha scritto:

Il codice però dice diversamente:

 

 

Ciao, Ale.

Ciao ALE 

Hai ragione non mi ero accorto di  questo errore grazie mille , adesso funziona tutto 

grazie ancora a tutti

Link al commento
Condividi su altri siti

Crea un account o accedi per commentare

Devi essere un utente per poter lasciare un commento

Crea un account

Registrati per un nuovo account nella nostra comunità. è facile!

Registra un nuovo account

Accedi

Hai già un account? Accedi qui.

Accedi ora
×
×
  • Crea nuovo/a...