Come mandare in riposo il nema 17 con Easy Driver?

Buonasera a tutti,
sto tentando di fare un'automazione a una macchina, ho trovato questo sul forum usa un arduino mega e caricare lo sketch di un americano.

I componenti:

Nema 17
Easy Driver
Arduino Mega
LCD Nokia 5110
tastiera 4x4
pulsante 1
pulsante 2

l'ho modificato per fare questo, inserisci la quantità di movimento che deve fare il motore (espresso in mm) e poi la salvo con il tasto #,
ogni volta che premo il pulsante 1 si muove per i millimetri che ho salvato (DX)
ogni volta che premo il pulsante 2 si muove per i millimetri che ho salvato (SX)

Funziona tutto alla grande, solo che mi sono accorto che quando il motore è fermo è bloccato e di conseguenza dopo un po scalda, come faccio a dire allo sketch di mandare il nema 17 in sleep dopo che ha raggiunto la quota, e se ripremo il pulsante deve muoversi e raggiunta la quota andare in sleep, questo all'infinito.
Se non sbaglio su Easy Driver c'è un pin che si chiama SLP
Grazie Infinite

allego lo sketch

#include "AccelStepper.h" // AccelStepper Library
#include <Keypad.h>  // Keypad Library
#include "U8glib.h"  // U8glib for Nokia LCD


int button_1 = 2; //Pulsante 1 sul pin 2
int button_2 = 8; //Pulsante 2 sul pin 8

/*
int motorPin1 = 8;      //IN1 sul pin 8    
int motorPin2 = 9;      //IN2 sul pin 9
int motorPin3 = 10;     //IN3 sul pin 10
int motorPin4 = 11;     //IN4 sul pin 11
int val=0;
const int StepsPerRevolution = 200;
const int myStep = 200;
*/
int firstnumber=99;  // used to tell how many numbers were entered on keypad
int secondnumber=99;
int thirdnumber=99;
int keyfullnumber=0;  // used to store the final calculated distance value
String currentposition = "";  // Used for display on Nokia LCD
int val = 0;
int val2 = 0;
// Keypad Setup
const byte ROWS = 4; // Four Rows
const byte COLS = 4; // Four Columns
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {22, 24, 26, 28}; // Arduino pins connected to the row pins of the keypad
byte colPins[COLS] = {31, 33, 35, 37}; // Arduino pins connected to the column pins of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );  // Keypad Library definition

#define backlight_pin 11
U8GLIB_PCD8544 u8g(3, 4, 6, 5, 7);  // Arduino pins connected to Nokia pins:
                                    // CLK=3, DIN=4, CE=6, DC=5, RST=7
// AccelStepper Setup
AccelStepper stepper(1, A0, A1);  // 1 = Easy Driver interface
                                  // Arduino A0 connected to STEP pin of Easy Driver
                                  // Arduino A1 connected to DIR pin of Easy Driver                                  

void setup() {
  // put your setup code here, to run once:
  pinMode(button_1, INPUT);
  //  AccelStepper speed and acceleration setup
  stepper.setMaxSpeed(3000);  // Not to fast or you will have missed steps
  stepper.setAcceleration(10000);  //  Same here
  stepper.setCurrentPosition(0);
    u8g.firstPage();
  do {
  u8g.drawHLine(0, 15, 84);
  u8g.drawVLine(50, 16, 38);
  u8g.drawHLine(0, 35, 84); 
  u8g.setFont(u8g_font_profont11);
  u8g.drawStr(0, 10, "ENTER DISTANCE");
  u8g.drawStr(62, 29, "MM");
  u8g.drawStr(4, 46, "muove");
  }
  while( u8g.nextPage() );
}

void loop() {
  // put your main code here, to run repeatedly:
  
  char keypressed = keypad.getKey(); 
  if(keypressed != NO_KEY){
    saveKey(keypressed);
  }
  
  val = digitalRead(button_1);
  if(val == 1){
    movestepper();
  }

    val2 = digitalRead(button_2);
  if(val2 == 1){
    reversestepper();
  }
  
   
}

void movestepper() {  //  Move the stepper
  int calculatedmove=((keyfullnumber*1600)/80);  //  Calculate number of steps needed in mm
  stepper.runToNewPosition(calculatedmove);
  stepper.setCurrentPosition(0);
  val=0;
}

void reversestepper(){
  int calculatedmove=((keyfullnumber*1600)/80);//  Calculate number of steps needed in mm
  int reverse = (-1)*(calculatedmove);
  stepper.runToNewPosition(reverse);
  stepper.setCurrentPosition(0);
  val2=0;
}


void saveKey(char keys){
  switch (keys) {
      case '1':
        checknumber(1);
      break;
        
      case '2':
        checknumber(2);
      break;

      case '3':
        checknumber(3);
      break;

      case '4':
        checknumber(4);
      break;

      case '5':
        checknumber(5);
      break;

      case '6':
        checknumber(6);
      break;

      case '7':
        checknumber(7);
      break;

      case '8':
        checknumber(8);
      break;

      case '9':
        checknumber(9);
      break;

      case '0':
        checknumber(0);
      break;

      case '*':
        deletenumber();
      break;

      case '#':
        calculatedistance();
      break;

      case 'D':
        resetnumbers();
        break;
        
    }
}

void checknumber(int x){
    if (firstnumber == 99) { // Check if this is the first number entered
      firstnumber=x;
      String displayvalue = String(firstnumber);  //  Transform int to a string for display
      drawnokiascreen(displayvalue); // Redraw Nokia lcd
 
    } else {
    if (secondnumber == 99) {  // Check if it's the second number entered
      secondnumber=x;
      String displayvalue = (String(firstnumber) + String(secondnumber));
      drawnokiascreen(displayvalue);

    } else {  // It must be the 3rd number entered
      thirdnumber=x;
      String displayvalue = (String(firstnumber) + String(secondnumber) + String(thirdnumber));
      drawnokiascreen(displayvalue);

    }
  }
}

 
void deletenumber() {  // Used to backspace entered numbers
  if (thirdnumber !=99) {
      String displayvalue = (String(firstnumber) + String(secondnumber));
      drawnokiascreen(displayvalue);

    thirdnumber=99;
  } 
  else {
    if (secondnumber !=99) {
      String displayvalue = String(firstnumber);
      drawnokiascreen(displayvalue);

      secondnumber=99;
   } 
   else {
     if (firstnumber !=99) {
       String displayvalue = "";
       drawnokiascreen(displayvalue);

       firstnumber=99;
      }
    }
  }
}

void calculatedistance() {  // Used to create a full number from entered numbers
  
    if (thirdnumber == 99 && secondnumber == 99 && firstnumber != 99) {
      keyfullnumber=firstnumber;
    }
    
    if (secondnumber != 99 && thirdnumber == 99) {
      keyfullnumber=(firstnumber*10)+secondnumber;
    }
    
    if (thirdnumber != 99) {
      keyfullnumber=(firstnumber*100)+(secondnumber*10)+thirdnumber;
    }
    currentposition = String(keyfullnumber);
    reloadScreen();
    firstnumber=99;
    secondnumber=99;
    thirdnumber=99;
}

void reloadScreen(){
  u8g.firstPage();
  currentposition = String(keyfullnumber);
  do {
    u8g.drawHLine(0, 15, 84);
    u8g.drawVLine(50, 16, 38);
    u8g.drawHLine(0, 35, 84); 
    u8g.setFont(u8g_font_profont11);
    u8g.drawStr(0, 10, "ENTER DISTANCE");
    u8g.drawStr(62, 29, "MM");
    u8g.drawStr(4, 46, "muove");
    u8g.setPrintPos(57,47);
    u8g.print(currentposition);       
  }
  while( u8g.nextPage() ); 
  }

void drawnokiascreen(String y) {

    u8g.firstPage();
    do {
      u8g.drawHLine(0, 15, 84);
      u8g.drawVLine(50, 16, 38);
      u8g.drawHLine(0, 35, 84); 
      u8g.setFont(u8g_font_profont11);
      u8g.drawStr(0, 10, "ENTER DISTANCE");
      u8g.setPrintPos(0,29);
      u8g.print(y);  // Put entered number on Nokia lcd    
      u8g.drawStr(62, 29, "MM");
      u8g.drawStr(4, 46, "muove");
      u8g.setPrintPos(57,47); 
      u8g.print(currentposition);  //  Display current position of stepper
    }
      while( u8g.nextPage() );

}
  
void resetnumbers() {  // Reset numbers for next entry
  firstnumber=99;
  secondnumber=99;
  thirdnumber=99;
  keyfullnumber=0;
  currentposition="";
  reloadScreen();
} 

C'è il pin ENABLE:
Questo segnale di ingresso normalmente basso disabiliterà tutte le uscite quando viene portato in alto.

ok ma non ho capito come attivare questa funzione dopo ogni pressione del pulsante

  void movestepper() {  //  Move the stepper
    digitalWrite(enablePin, LOW); // abilita il motore
    int calculatedmove = ((keyfullnumber * 1600) / 80); //  Calculate number of steps needed in mm
    stepper.runToNewPosition(calculatedmove);
    stepper.setCurrentPosition(0);
    digitalWrite(enablePin, HIGH); // disabilita il motore
    val = 0;
  }

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.