Show Posts
Pages: [1] 2 3 ... 6
1  Using Arduino / Programming Questions / Re: Accelstepper Lib and Menwiz Lib problem on: April 02, 2013, 04:06:45 pm
 smiley
OK! I think ... maybe I got the answer by myself.
The command "stepper.moveTo" of the accelstepper library is not what I have to use ...
"stepper.move" (without To) is the correct one.
thanks
2  Using Arduino / Programming Questions / Re: Accelstepper Lib and Menwiz Lib problem on: April 02, 2013, 03:50:35 pm
Is such a strange thing !
I simplified the function and did another test:
Code:
void MoveSAW()                      // This is the Relative Movement of the SAW
 {
  stepper.moveTo (MoveREL * 200);    // move the SAW X mm's
    MoveREL = 0;                               //reset the counter to 0
 }

and I have exactly the same results:
+1mm = +1 turn; +2mm= +1 turn; +4mm=+2 turn; +5mm=+1 turn; +10mm=5 turns;
but now it should be a very simple function ...
3  Using Arduino / Programming Questions / Accelstepper Lib and Menwiz Lib problem on: April 02, 2013, 02:32:51 pm
Hi,
I can't focus the proble very well, the same commands do the correct calculation but the stepper does not execute the corect movement.
Let's start with the complete code:
Code:
#include <Wire.h>
#include <LiquidCrystal.h>
#include <buttons.h>
#include <MENWIZ.h>
#include <EEPROM.h>
#include <AccelStepper.h> //instead of Stepper.h

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

//***** Stepper Motor Parameters *****
 AccelStepper stepper(4, 2, 3, 4, 5);
 const int stepsPerRevolution = 200;

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 = 0;                      //ABS Height Variable = mm
int ActualHeightZ = 0;
int NewHeightZ;
int MoveREL;                          //Rel Move Variable = mm
int Height2;
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


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 ******
   stepper.setMaxSpeed(200);
//  stepper.setSpeed(110);
     stepper.setAcceleration(50);
     
  //********** Menu and LCD *********
  char b[84];
  _menu *r,*s1,*s2,*s3;

  // initialize the menu object (16x2 LCD)
  menu.begin(&lcd,16,2);           //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)

  //****** SAW ******
  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"));      // (Move AT a certain mm height)
    s3=menu.addMenu(MW_VAR,s2,F("Absolute Height"));    // add a terminal node in the menu tree (that is "variable")
     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("Saw 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")
    s3=menu.addMenu(MW_VAR,s2,F("Relative Move"));      // (Move OF a certain mm)
     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
   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)
 
  //******* Planner *******
   s1=menu.addMenu(MW_SUBMENU,r,F("PLANNER"));
  //******* Shaper *******   
   s1=menu.addMenu(MW_SUBMENU,r,F("SHAPER"));
 } 
   
void loop()
 {
  // NAVIGATION MANAGEMENT & DRAWING ON LCD. NOT BLOCKING has to be the first in the void loop
  menu.draw();
  ReadButtons();
    stepper.run();

 }
void ABS_Height()                   // Absolute Height Function
 {
  NewHeightZ = (HeightZ - ActualHeightZ);
  stepper.moveTo (NewHeightZ* 200);  // move Height1 mm's
   Serial.print ("Move mm ");
     Serial.print (NewHeightZ);
   Serial.print ("Height mm ");
    Serial.print (HeightZ);
  ActualHeightZ = HeightZ;
 }


void MoveSAW()                      // This is the Relative Movement of the SAW. WORKING ! :-)
 {
  stepper.moveTo (MoveREL * 200);    // move the SAW X mm's
   Serial.print ("Move mm ");
    Serial.print (MoveREL);
   HeightZ = (HeightZ+MoveREL);
    ActualHeightZ = HeightZ;
    MoveREL = 0;
   Serial.print ("Height mm ");
    Serial.print (HeightZ);
 }

void ReadButtons()

// ++++ Control 4 buttons ++++
 {
  lastButtonPressed = buttonPressed;
  buttonValue = analogRead(buttonPin); //analog value to simulate the pushed buttons


   if(buttonValue >= 850)
    {
     buttonPressed = 0;
     noButtonPressed();               // ? calling an extra fucntion
    }
   else  if(buttonValue >= 480 & buttonValue <= 550)
    {
     buttonPressed = 4;
     buttonAct = 1;                         // set the menu flag1
    }
   else if(buttonValue >= 280 & buttonValue <=380)
    {   
     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 >= 100 & buttonValue <=200)
    {   
     buttonPressed = 1;
     buttonAct = 1;                         // set the menu flag1
    }
 }

int noButtonPressed()
 {
  return MW_BTNULL;
 }

int navMenu()                              // called from menu.draw
 {
 
  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 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
   }
 }

This is the Calculation "core":

Code:
void ABS_Height()                   // Absolute Height Function
 {
  NewHeightZ = (HeightZ - ActualHeightZ);
  stepper.moveTo (NewHeightZ* 200);  // move Height1 mm's
   Serial.print ("Move mm ");
     Serial.print (NewHeightZ);
   Serial.print ("Height mm ");
    Serial.print (HeightZ);
  ActualHeightZ = HeightZ;
 }


void MoveSAW()                      // This is the Relative Movement of the SAW. WORKING ! :-)
 {
  stepper.moveTo (MoveREL * 200);    // move the SAW X mm's
   Serial.print ("Move mm ");
    Serial.print (MoveREL);
   HeightZ = (HeightZ+MoveREL);
    ActualHeightZ = HeightZ;
    MoveREL = 0;
   Serial.print ("Height mm ");
    Serial.print (HeightZ);
 }

The serial Monitor display always the correct calculation. The MoveSAW funtion called to execute +1 mm = 1 turn (200 step) perfecly works, but then if I make -1 mm = -1 turn (200 step backwards) the motors turns 400 steps backwards (-2 turns) but the serial monitor display move 1mm (heigh 0 mm) and that is correct. The motor understood "go to -1 mm so it moves 2 turns backwards (from +1 to -1)
Another example: execute +1 mm (1 turn) ok,move 200 steps ! then execute another +1 mm (1 turn) ko, no move !
now some example just with numbers:
reset arduino
+1mm = +1 turn; +2mm= +1 turn; +4mm=+2 turn; +5mm=+1 turn; +10mm=5 turns; -10mm=-20 turns
+1=1 +2=1 +4=2 +5=1 +10=5 (the display correctly print 22mm ) then +1=-9 turns (display +23)
Any Hint ? I'm going crazy !
4  Using Arduino / Displays / Re: MENWIZ: yet another character lcd menu wizard library on: February 04, 2013, 03:19:30 am
Thanks Khalid,
I had doubt because they told me to not use float because sometimes gives erratic rounding values ....
don't know why ....

Quote
changing the variable from INT to FLOAt is ok ?
Sorry I dnon't know how many times you need telling
 DO NOT USE A FLOAT!!!!!
You will suffer from rounding errors. Mathematical operations will not be commutative.   
What do you not understand about using an int with the numbers greater than your resolution?
5  Using Arduino / Programming Questions / Re: Stepper Absolute Position ... how to on: February 04, 2013, 03:13:33 am
Thanks Nick, understood
6  Using Arduino / Programming Questions / Re: Stepper Absolute Position ... how to on: February 03, 2013, 06:54:49 pm
Quote
What do you not understand about using an int with the numbers greater than your resolution?
What I don't understand maybe is the nature of INT ... I consider integer number the number with no decimals so 1, 2, 3 ..... but 0.5 is a decimal number ...
so my question is: can I define my function as INT and have decimal values ? like 10.5 10.8 ecc. ecc ?
7  Using Arduino / Programming Questions / Re: Stepper Absolute Position ... how to on: February 03, 2013, 06:29:17 pm
Well I would say if you want 0.1mm resolution then make your units equal to 0.01mm or even 0.001 so that you don't get bitten by rounding errors.

No, not that much! I am working with wood so 0.1 it's enough, I just want to make my movment in 0.1 step, ex move the height of 40.5 mm changing the variable from INT to FLOAt is ok ?or there is some other solution ?
thanks
8  Using Arduino / Displays / Re: MENWIZ: yet another character lcd menu wizard library on: February 03, 2013, 06:21:33 pm
Roberto,
just two more questions ....
The fist, is about the Max Menu number I know by default set to 15 .... increasing that number affect memory ... does it increase a lot ? I mean if I change the limit to 30 but use only 15 menus ... I use the same memory amount of using 15 with a limit of 15 ?
The second ... I would like to move my height in 0.1mm step ...
Code:
     s3->addVar(MW_AUTO_INT,&HeightZ,0,100,1);
if I set 0.1 step in my var, it does not the decimal step just the integer ... any suggestion ?
thanks
9  Using Arduino / Programming Questions / Re: Stepper Absolute Position ... how to on: February 03, 2013, 05:17:14 pm
A few post ago Mike asked:
Are you dealing in units of mm?
That is quite coarse for a miller, your motors are capable of finer control. If you use ints then you have to use some arbitrary units like 1/1000 th of a mm so you can cope with fractional movement.
.... and I answered "maybe I should use float" .... then Mike:
Quote
No using floats brings rounding errors, you need to use int to keep it accurate. Just let the int stand for a small value.
Well, if I want to use decimal numbers how do I have to do ? I would like to set my height from 0 to 100 in 0.1 mm steps.


Here a part of my sketch ...
Code:
int HeightZ = 0;                      //ABS Height Variable = mm
int ActualHeightZ = 0;
int NewHeightZ;

Code:
  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"));      // (Move AT a certain mm height)
    s3=menu.addMenu(MW_VAR,s2,F("Absolute Height"));    // add a terminal node in the menu tree (that is "variable")
     s3->addVar(MW_AUTO_INT,&HeightZ,0,100,1);

oh, just for the record ...This is my solution, I had to change also the relative movement to have it working together with the absolute move:
Code:
void ABS_Height()                   // Absolute Height Function
 {
  NewHeightZ = (HeightZ - ActualHeightZ);
  stepper1.moveTo(NewHeightZ* 50);  // move Height1 mm's
   lcd.print ("Height mm ");
   lcd.print (HeightZ);
   delay (5000);
  ActualHeightZ = HeightZ;
 }


void MoveSAW()                      // This is the Relative Movement of the SAW
 {
  stepper1.moveTo(MoveREL * 50);    // move the SAW X mm's
   lcd.print ("Move ");
   lcd.print (MoveREL);
   lcd.print (" mm");
   delay (5000);
  ActualHeightZ = (HeightZ+MoveREL);
   lcd.print ("Height ");
   lcd.print (ActualHeightZ);
   lcd.print (" mm");
   delay (5000);
 }
10  Using Arduino / Displays / Re: MENWIZ: yet another character lcd menu wizard library on: February 01, 2013, 11:07:37 am
Code:
if (adc_key_in < 50)   return btnRIGHT;  
if (adc_key_in < 200)  return btnUP;
if (adc_key_in < 400)  return btnDOWN;
if (adc_key_in < 600)  return btnLEFT;
if (adc_key_in < 800)  return btnSELECT;  
 

Uhmmm ...
As far I understant ... you have:
if pressed button brnRIGHT true all the statement below, because ex.30 is <50<200<400<600<800 ....
I think you shoud put something like:
Code:
    if (60 <adc_key_in < 200)  return btnUP;
        if (210< adc_key_in < 400)  return btnDOWN;

ecc. isn'it ?
11  Using Arduino / Displays / Re: MENWIZ: yet another character lcd menu wizard library on: January 30, 2013, 02:25:49 pm
In this thread at post 316 there is my code that is working on your hardware ....
Quote
Re: MENWIZ: yet another character lcd menu wizard library
« Reply #316 on: January 09, 2013, 09:59:40 PM »
(is on page 22)
you can try it then start to modify it for your convenience you will have the buttons working too ...
12  Using Arduino / Displays / Re: MENWIZ: yet another character lcd menu wizard library on: January 30, 2013, 02:15:16 pm
I this:
Code:
  menu.begin(&lcd,16,2);              //initialize the menwiz menu object passing the lcd object and the colums and rows params

put it after:
  _menu *r,*s1,*s2,*s3;
13  Using Arduino / Displays / Re: MENWIZ: yet another character lcd menu wizard library on: January 30, 2013, 02:17:26 am
Aufruf,
I use exacly your first statement an the calssic Liquidcrystal library:
Code:
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
You don't need to use LiquidCrystal_I2C to use MENWIZ.
I use flawlessly MENWIZ menu and library.
the olnly thing I did is to change from digital buttons to analog buttons.
14  Using Arduino / Displays / Re: MENWIZ: yet another character lcd menu wizard library on: January 29, 2013, 06:09:30 pm
I have the same shield I think and use LyquidCrystal with no problems.
what is your problem ?
15  International / Software / Re: Aiuto funzionamento programma per gestione luci tramite menu(codice già scritto) on: January 29, 2013, 12:12:44 pm
Con case 50, case 200, case 400 ecc. si intende il valore delle resistenze ? se si considera che io con lo stesso shield ho valori diversi.
Se vuoi controllare i valori usa la funzione serial.println
Code:
/*
  Analog values representing the pushbutton value are depending on the resitor value used.
   Test the values first with the serial.monitor
   */
  buttonValue = analogRead(buttonPin); //analog value to simulate the pushed buttons
  Serial.println(buttonValue );
...
e poi controlla col monitor seriale che valori vengono fuori ... calcola che io ho messo un intervallo perchè il valore putrebbe oscillare un minimo. però vedi te.
se hai messo i pin che ti ho dato per LCD e lo attacchi e flashi il codice dovrebbe funzionare. così puoi controllare i valori dei pulsanti coll monitor seriale
Pages: [1] 2 3 ... 6