Show Posts
Pages: 1 2 [3] 4 5 6
31  Using Arduino / Programming Questions / Re: Stepper Absolute Position ... how to on: January 29, 2013, 04:55:20 am
I add a brief description of the sketch:
This Sketch use MENWIZ menu system, an LCD 20x4 (or 16x2), and four Analog buttons (A0 pin) to control a Stepper Motor. All the interface part (Menu, LCD,Buttons is tested and working flawlessly) (well maybe it's not well written or clean but it works.) The actions "ABS_Height" and "MoveSaw" are working. I'm not sure about the stepper movement as I am waiting for the Stepper Controller ( I have a motor shield that I can't use with all the other stuff). I tested the motor command in a separated enviroment and they seem to work.
Thanks for the attention.
Sergio
32  Using Arduino / Programming Questions / Re: Stepper Absolute Position ... how to on: January 29, 2013, 04:36:54 am
Nick & Mike,
Thanks, I understand that the full sketch is needed, I cutted all the unnecessary part to make it smaller.
the involved part is quite short but I wanted to post a compiling sketch, so the buttons control is in there.
Code:
#include <Wire.h>
#include <LiquidCrystal.h>
#include <buttons.h>
#include <MENWIZ.h>
#include <EEPROM.h>
#include <AccelStepper.h>
#include <AFMotor.h> //not needed if not using motor shield

// Create global object for menu and lcd
menwiz menu;
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

// Stepper Motor Parameters
AF_Stepper motor1(200, 2);
const int stepsPerRevolution = 200;

void forwardstep1() { 
  motor1.onestep(FORWARD, SINGLE);
}
void backwardstep1() { 
  motor1.onestep(BACKWARD, SINGLE);
}



boolean wr=0;                         // Instantiate global variables to bind to menu

const int buttonPin = A0;             // 4 button switch circuit input connected to analog pin 0
const int led13Pin = 13;              // the number of the LED output pin
int stepCount = 0;                    // number of steps the motor has taken
int HeightZ;                           //ABS Height Variable = mm
int MoveREL;                            //Rel Move Variable = mm
boolean buttonBlock = 0;
boolean buttonAct = 0;                // flag 1
boolean stopMenu = 0;                 // flag 2
byte buttonPressed = 0;               // which button was pressed
byte lastButtonPressed = 0;           // prev button pressed
int buttonValue = 0;                  // read value from analog port for the 4 navigation pushbuttons
long menuOffTime = 0;                 //used for timer

extern byte MW_navbtn;                //needed to run the software key navigation in Menwiz
AccelStepper stepper1(forwardstep1, backwardstep1);
//AccelStepper stepper2(forwardstep2, backwardstep2);


void setup()
{
Serial.begin(9600);                  // Output to serial writing

  digitalWrite((A0), HIGH);         // enable the 20k internal pullup for UNO based board for analog port A0

// Motor Speed & Accel
    stepper1.setMaxSpeed(400);
    stepper1.setAcceleration(50);
//++++++++++++++++++++Menu and LCD 
  char b[84];
  _menu *r,*s1,*s2,*s3;

                                      // initialize the menu object ( 4 x rows x 20 colums LCD)
  menu.begin(&lcd,20,4);              //initialize the menwiz menu object passing the lcd object and the colums and rows params
  menu.addUsrNav(navMenu,4);
  MW_navbtn=4;                        // force 4 or 6 buttons mode for menu navigation -> MW_navbtn=4; or MW_navbtn=6;

//create the menu tree
  r=menu.addMenu(MW_ROOT,NULL,F("MAIN MENU"));                      //create a root menu at first (required)

//------ Sega Squadratrice ---------
s1=menu.addMenu(MW_SUBMENU,r,F("SAW"));                    //add a submenu node 2 to the root menu (control the heigh of my Saw)
  s2=menu.addMenu(MW_SUBMENU,s1,F("Saw Height"));         
    s3=menu.addMenu(MW_VAR,s2,F("Absolute Height"));      //add a terminal node in the menu tree (that is "variable"); (Move AT a certain mm height)
      s3->addVar(MW_AUTO_INT,&HeightZ,0,100,1);           //int type, fd binded variable, rage 0-100, step 1
        s3=menu.addMenu(MW_VAR,s2,F("ABS_Height"));       //Call the Action ABS_Height to move the Stepper in ABS mode
        s3->addVar(MW_ACTION,ABS_Height);                 //Fire the Ation Above
  s2=menu.addMenu(MW_SUBMENU,s1,F("Saw Move"));           //add a terminal node in the menu tree (that is "variable"); (Move OF a certain mm)
    s3=menu.addMenu(MW_VAR,s2,F("Relative Move"));       
     s3->addVar(MW_AUTO_INT,&MoveREL,-100,100,1);          //int type, fd binded variable, rage -100 +100, step 1
        s3=menu.addMenu(MW_VAR,s2,F("MoveSAW"));          //Call the Action moveSAW to move the Stepper in REL mode
        s3->addVar(MW_ACTION,MoveSAW);                    //Fire the Ation Above

  pinMode(led13Pin, OUTPUT);                // initialize the led as a output control pin
}

void loop()   
{
// NAVIGATION MANAGEMENT & DRAWING ON LCD. NOT BLOCKING has to be the first in the void loop
  menu.draw();

  readButtons();
}

//**** HERE IS THE PROBLEMATIC PART *******

//int HeightZ = 0;
int LastHeightZ = 0;
//int NewHeightZ = 0;


void ABS_Height(){     //This is the Absolute Move Action to be implemented
HeightZ = 0;
if (HeightZ > 0) HeightZ = LastHeightZ;
stepper1.moveTo((LastHeightZ - HeightZ) * 50); // move Height1 mm's
lcd.print ("Height mm ");
lcd.print (HeightZ);
delay (5000);
}

//**** FROM HERE EVERITHING IS WORKING ******
void MoveSAW(){                //This is the Relative Movement of the SAW. WORKING ! :-)
stepper1.moveTo(MoveREL * 50); // move the SAW X mm's
lcd.print ("Move ");
lcd.print (MoveREL);
lcd.print (" mm");
delay (5000);
}

// Here is the working coce to use MENWIZ with 4 Analog Pushbottons.
//  ++++++ functions +++++++

void readButtons()

// ++++ Control 4 buttons ++++
{
  lastButtonPressed = buttonPressed;

 // Analog values representing the pushbutton value are depending on the resitor value used.
 
  buttonValue = analogRead(buttonPin); //analog value to simulate the pushed buttons
   
  if(buttonValue >= 850)
  {
    buttonPressed = 0;
    noButtonPressed(); // is calling an extra fucntion
  }
  else  if(buttonValue >= 380 & buttonValue <= 450)
  {
    buttonPressed = 4;
    buttonAct = 1; // set the menu flag1
  }
  else if(buttonValue >= 200 & buttonValue <=300)
  {   
    buttonPressed = 3;
    buttonAct = 1; // set the menu flag1
  }
  else if(buttonValue >= 0 & buttonValue <=50)
  {   
    buttonPressed = 2;
    buttonAct = 1; // set the menu flag1
  }
  else if(buttonValue >= 80 & buttonValue <=150)
  {   
    buttonPressed = 1;
    buttonAct = 1; // set the menu flag1
  }
}

int noButtonPressed()
{
  return MW_BTNULL;
}

int navMenu() // called from menu.draw
{
  /*
   As soon as a button is pushed the first time flag 1 is set to HIGH and if the buttonnumber is not 0 then a timer is started.
   The menu action then should only be performed once.
   After 400 msecs the flag will be set to LOW and a new buttonpush can be processed.
   Menu action is blocked for 400 msec even if the same button is being kept pressed for 2000 msecs by flag2.
   */

  long menublockTime = millis();

  if (buttonAct == 1 && buttonPressed != 0 && stopMenu == 0)  // we have a state were we process a menu navigation step once and block it for 2 secs
  {
    digitalWrite(led13Pin,HIGH);  // set timer led ON
    menuOffTime = menublockTime  + 400; //start the timer. You can change this blocking time to your convenience but do not make it lower aa 200 msecs
    stopMenu = 1;

    switch (buttonPressed)
    {
    case 1: // Up
      return MW_BTU;
      break;
    case 2: // Confirm
      return MW_BTC;
      break;
    case 3: // Down
      return MW_BTD;
      break;   
    case 4: // Escape
      return MW_BTE;
      break;
    }
  }

  if (menuOffTime != 0  &&  menublockTime  > menuOffTime)  //  Reset of the timer so a new menu action can be processed
  {
    buttonAct = 0; // resets the flag 1
    buttonPressed = 0;
    menuOffTime = 0;  // resets timer to zero
    stopMenu = 0;
    digitalWrite(led13Pin,LOW);  // set timer led OFF
  }
}
33  Using Arduino / Programming Questions / Re: Stepper Absolute Position ... how to on: January 28, 2013, 05:57:19 pm
Yes Nick,
you are absolutely right.
My difficulty is to translate this in Arduino language ... I know there is the way but I don't know how.
I set the postion in the MENWIZ menu, then I call the action "ABSheight"
Code:
 
s2=menu.addMenu(MW_SUBMENU,s1,F("Saw Height"));                         //add a terminal node in the menu tree (that is "variable"); (should move at a certain mm height)
    s3=menu.addMenu(MW_VAR,s2,F("Absolute Height"));
      s3->addVar(MW_AUTO_INT,&HeightZ,0,100,1);     //int type, fd binded variable, rage 0-100, step 1
        s3=menu.addMenu(MW_VAR,s2,F("ABSheight"));
        s3->addVar(MW_ACTION,ABSheight);

And everything works fine (I tried it with relative move )
My problem is the inability to write the funtion "remembered position", I know there is the way to "remember" the position .... something like "OldPosition = HeightZ" then recall "OldPosition" and subtract the new one but I can't find where I saw something similar and I not able to create it correctly.

34  Using Arduino / Programming Questions / Re: Stepper Absolute Position ... how to on: January 28, 2013, 05:07:05 pm
Thanks aufruf,
I will give an accurate look !
Quote
"void AccelStepper::moveTo    (    long     absolute   ) "
35  Using Arduino / Programming Questions / Re: Stepper Absolute Position ... how to on: January 28, 2013, 04:15:56 pm
Peter,
I know there is a way to do what I want .. the problem is that my programming knowledge is zero, so I try to see what others did and sometimes, like this case, I try to find an hint ...
My idea is to zero the motor at the start and then change the height in two manners: absolute (the case where I need help) and relative (I just tell the motor to move X mm).
When I work with wood sometimes Absolute is the easiest way, somtimes relative is.
But I can solve every problem using just one of the method.
Save to the eeprom is not the solution because when a stepper is turned off you have no guaratee that it will hold the position. A stepper when turned on is blocked to that position unless you tell him to move.
36  International / Software / Problema con memorizzazione variabili on: January 28, 2013, 03:44:38 pm
Ciao,
Il mio sketch imposta una variabile "QuotaZ" tramite un menu (MENWIZ),
Code:
   s3=menu.addMenu(MW_VAR,s2,F("Altezza Assoluta"));
      s3->addVar(MW_AUTO_INT,&QuotaZ,0,100,1);
        s3=menu.addMenu(MW_VAR,s2,F("QuotaAssoluta"));
        s3->addVar(MW_ACTION,QuotaAssoluta);
Per poi azionare un motore passo passo che mi muove l'altezza di una Sega/Pialla o Fresa.
Volendo eseguire uno spostamento assoluto (ovvero posizionare la lama/fresa a una quota che va da 0 a100 mm dal piano) devo eseguire un calcolo che è il seguente:
SpostamentoMotore = (NuovaQuotaZ - VecchiaQuotaZ)*50passi (50passi è il numero passi per fare 1mm) in pratica se la mia lama è a 20mm di altezza e voglio portarla a 70mm dovrò eseguire: (70mm-20mm)*50passi  .... cioè 2500passi.
Il mio problema è che sono incapace con la programmazione e non so come salvare la mia "QuotaZ" precedente in "VecchiaQuotaZ".
ho buttato giù questo abbozzo, ma ovviamente non è corretto.
Code:
int QuotaZ = 0;
int VecchiaQuotaZ;
int NuovaQuotaZ;


void QuotaAssoluta(){
if (QuotaZ > 0) QuotaZ = VecchiaQuotaZ;
//VecchiaQuotaZ = QuotaZ;  // QuotaZ variable impostata nel menu
NuovaQuotaZ = (QuotaZ - VecchiaQuotaZ);
stepper1.moveTo(NuovaQuotaZ * 50); // muove l'altezza di "QuotaZ" mm
lcd.print ("Altezza mm ");
lcd.print (QuotaZ);
delay (5000);
}
Qualcuno ha da darmi qualche dritta ?
Grazie
37  Using Arduino / Programming Questions / Re: Stepper Absolute Position ... how to on: January 28, 2013, 02:18:44 pm
... well I spent some hours trying understand, but I cannot clear my idea on how I can store the previous HeightZ value to LastHeightZ
This code is obviously not working, I miss the way to store my variable HeightZ and convert to LastHeightZ before changing the value.

Code:
int HeightZ = 0;
int LastHeightZ;
int NewHeightZ;


void ABSheight(){
LastHeightZ = HeightZ;  // previous?? HeightZ variable setted in the menu is stored in LastHeightZ

NewHeightZ = (HeightZ - LastHeightZ); //should be actual HeightZ difference value with previous in the menu
stepper1.moveTo(NewHeightZ * 50); // move Height1 mm's
lcd.print ("Height mm ");
lcd.print (HeightZ);
delay (5000);
}
38  Using Arduino / Motors, Mechanics, and Power / Re: How fast is the arduino to run stepper motors on: January 28, 2013, 10:29:57 am
On my CNC, the frequency is at least 25kh (mach3 and gecko's) .... but I am running them at 45kh at the moment .... It also depend on what you want to do. Generally if you cut wood,alluminium, acrylic etc. the speed of the system is a relative problem, generally you cut at lower speed than the limits of the machine, you reach the maximum speed only on "rapid" movement (when you go A to B without cutting).
So if Arduino can drive three or four Gecko at 25kh I see no problem to drive even a big CNC. But I don't really know if Arduino can ...
39  Using Arduino / Programming Questions / Re: Stepper Absolute Position ... how to on: January 28, 2013, 09:38:29 am
Paul, there is somthing I don't catch sorry, I have to do a better research on other project to see something similar at work.

Henry, with all respect, but a position sensor is not needed. It's the code that know where the stepper is. With the steppers the position is calculeted by the software, and they work perfecly this way, most of the CNC work like that.

40  Using Arduino / Programming Questions / Re: Stepper Absolute Position ... how to on: January 27, 2013, 07:56:05 pm
only at the beginning after the zero is setted
41  Using Arduino / Programming Questions / Re: Stepper Absolute Position ... how to on: January 27, 2013, 07:05:05 pm
Humm ... so far ?

Code:
int HeightZ = 0;
int LastHeightZ = 0;
//int NewHeightZ = 0;


void ABSheight(){
HeightZ = 0;
if (HeightZ > 0) HeightZ = LastHeightZ;
stepper1.moveTo((LastHeightZ - HeightZ) * 50); // move Height1 mm's
lcd.print ("Height mm ");
lcd.print (HeightZ);
delay (5000);
}
}
42  Using Arduino / Programming Questions / Re: Stepper Absolute Position ... how to on: January 27, 2013, 06:18:06 pm
Quote
You're doing fine, so far.
Really ?
Thanks Paul, I'll see what I can do with your advice.

Quote
With a position sensor - encoder or a pot.
none of the above,I don't need a feedback, I just need to set the Zero (starting Point) then I just have to know where I am and where I want to go.

yes Mike, you are right I would much better use float (am I right? ) :-)
but at the moment I was just thinking to understand how to manage the code.
thanks
43  Using Arduino / Programming Questions / Stepper Absolute Position ... how to on: January 27, 2013, 05:59:02 pm
I am bulding an actuator with a stepper motor, to control the height of a router /shaper.
I need to choose and execute two tipe of movement: Absolute and Relative.
Relative is easy for me (beginner):

stepper1.moveTo(MoveX * 50); // move Height1 mm's
where MoveX is the variable I set (es. 30mm) 50 is the number of step to make 1mm
Each time I set the MoveX variable I move of X mm.
Pretty straightforward.
 But with the absolute height I am in trouble.
The first thing to do is to set the Zero point each time the sistem start (that will be done with a limit switch)
So I have my starting point, then I set my variable that I call HeightZ, the fist step is easy, if I set HeightZ=20mm the stepper will go there with 20*50=1000 steps. From now all the new movement have to consider as a starting point the last HeightZ. So if I want to set my Absolute height at 75mm I have to do (New.HeightZ - Last.HeightZ)*50steps .... (75-20)*50 ... 2750 steps.
I suppose that the fist thing is to  declare var HeightZ:
Int HeightZ = 0;
Do I have to declare also NewHeightZ and LastHeightZ ?
can somebody help ?
or can somebody point me on a similar sketch ?
thanks

 


44  International / Megatopic / Re: MENWIZ: una libreria per creare menu su LCD on: January 27, 2013, 04:01:55 pm
Allora, mi è arrivato il display LCD da 20x4 WOW ! bellisimo ! ... e ho potuto progredire nel progetto.
Ecco cosa ho combinato:
Code:
 //------ Sega Squadratrice ---------
s1=menu.addMenu(MW_SUBMENU,r,F("SAW"));                    //add a submenu node 2 to the root menu (control the heigh of my Planner)
  s2=menu.addMenu(MW_SUBMENU,s1,F("Altezza Sega"));                         //add a terminal node in the menu tree (that is "variable"); (should move at a certain mm height)
    s3=menu.addMenu(MW_VAR,s2,F("Altezza Assoluta"));
      s3->addVar(MW_AUTO_INT,&Height2,0,100,1);     //int type, fd binded variable, rage 0-100, step 1
        s3=menu.addMenu(MW_VAR,s2,F("moveMOTOR2"));
        s3->addVar(MW_ACTION,moveMOTOR2);
  s2=menu.addMenu(MW_SUBMENU,s1,F("Spostamento Sega"));                         //add a terminal node in the menu tree (that is "variable"); (should move at a certain mm height)
    s3=menu.addMenu(MW_VAR,s2,F("Movimento Relativo"));
     s3->addVar(MW_AUTO_INT,&Height1,-100,100,1);                   //int type, fd binded variable, rage 0-100, step 1
        s3=menu.addMenu(MW_VAR,s2,F("moveMOTOR"));
        s3->addVar(MW_ACTION,moveMOTOR);
  s2=menu.addMenu(MW_VAR,s1,F("Zero"));                         //add a terminal node in the menu tree (that is "variable"); (should set the zero)
  s2=menu.addMenu(MW_VAR,s1,F("Setup"));                        //add a terminal node in the menu tree (that is "variable");  (set the parameters)
 
  
  //------- Pialla --------
s1=menu.addMenu(MW_SUBMENU,r,F("PLANNER"));                    //add a submenu node 2 to the root menu (control the heigh of my Planner)
  //------- Toupie --------
  s1=menu.addMenu(MW_SUBMENU,r,F("Toupie"));                    //add a submenu node 2 to the root menu (control the heigh of my Planner)
 
E queste sono le funzioni (provvisorie) chiamate:
Code:
void moveMOTOR(){
stepper1.moveTo(Height1 * 50); // move Height1 mm's
lcd.print ("Sposto di ");
lcd.print (Height1);
lcd.print (" mm");
delay (5000);
}

void moveMOTOR2(){
stepper1.moveTo(Height2 * 50); // move Height1 mm's
lcd.print ("Altezza Segaa: mm ");
lcd.print (Height2);
delay (5000);
}
In pratica ora il menu fa esattamente quello che volevo (bhè è da finire un poco e da mettere in ordine)
Però ora le funzioni vengono chiamate internamente al ramo scelto, ovvero:
Menu Principale.
   SAW > Altezza Sega > Altezza Assoluta > Variabile 0 (X) 100
                                                       > Esecuzione
         > Spostamento sega > Movimento Relativo > Variabile -100 (X) +100
                                                                  > Esecuzione
E oltretutto riesco anche a far vedere ciò che succede dul display:
Code:
lcd.print ("Sposto di ");
lcd.print (Height1);
lcd.print (" mm");
ovvero mi appare sul LCD "Sposto di X mm""
Fantastico !
Grazie !
Penso che con il menù ho quasi fatto ... ora devo lavorare sul motore passo passo e le relative funzioni.
Ciao
P.S. allego lo sketch completo.
45  Using Arduino / Displays / Re: MENWIZ: yet another character lcd menu wizard library on: January 22, 2013, 12:17:40 pm
Ciao,
I broke my  LCD, while waiting for the new one, I would like to know if it is possible to simulate the LCD output on the Serial Monitor on the PC, so I can check if my sketch is working ( I just want to see what is displayed on the LCD).
Something like the second example in this page ...
http://code.google.com/p/m2tklib/wiki/t07
Thanks



P.S.
Hi stretched59, it's a good idea ! I will try it.
Pages: 1 2 [3] 4 5 6