# Arduino and the NewBee



## Foozer (Apr 20, 2016)

Can't really appreciate what talents others have untill I try it myself . .

After reading the Diving head and Arduino write up - The OCD kicked in - How hard can Arduino and Steppers be? So after a few weeks of 'What the Heck!' Tentatively have baby steps of 'If-Else' working - 

Object: 
1) On startup - Have X-Y table return to negative position as determined by limit switch A.
2) Advance table in positive direction at speed X until limit switch B is triggered.
3) Return to position A at speed Y (faster)
4) Advance Y axis specified amount
5) return to and repeat from number 2

Assembled a little test platform - Cigar Boxes make nice little project boxes - Arduino, Easy Driver, Nema 17 motor, cam and some switches - (OCD again - get another driver and stepper to replace the current usage of a LED that simulates the Y axis)

Now for the ADD  - Mind is not one that retains names. So after many a time of 'What the heck was that command again?' Little toy does what it is asked of - Now to enter the realm of keypad input so the amount of Y axis travel can be chosen externally . .

Few more weeks and shall see how hardware debounce works
the 74HC or the MC 14490


----------



## Foozer (Apr 22, 2016)

Started as a 'What the Heck, Why Not' lets just do this thing - But mounting a little vise upon the table naturally requires something with few moving parts . In making the somethings with few moving parts quickly became tiresome to hand crank the table.

First came the windshield wiper motor gizmo - although it would run in either direction, it clearly favoured one over another - Steppers, leads to power supply, drivers and of course some way to automate - Arduino - Fixed roller switches at center point with adj triggers for the gross X-travel - - Now to fashion with reduction a mount for the other stepper upon the Y-Axis - - 
And what was it i wanted to do again? Have already done what i wanted to do but am making something to do what has already been done - Circular? 

If nothing else - It is Fun . .


----------



## Foozer (May 1, 2016)

We have Schmidt - - And with another arduino toy can see what is happening - Poor Mans Oscilloscope . . .  Signal going to 74HC14






And signal coming from 74HC14


----------



## Foozer (May 8, 2016)

Long way around the fence, but finally got the test model to run
A to B back to A, stop, then run C predetermined amount, stop, then repeat

Now to add a sixth counter to stop Y increments when total depth of cut is reached.

Kudos to those that know this stuff - Myold brian is tired . .


// Working 5-7-16 No Schmidt Trigger setup on test platform - -

#define sw2            2     // Move Table in Positive X Direction SW2 N.O. Type CW
#define sw3            3     // Move Table in Negative X Direction SW3 N.O. Type CCW
#define RSTX           5     // LOW, all STEP commands are ignored 
#define enableX        6     // Enable X Axis Motor On/Off
#define stepX          8
#define dirX           9      
#define enableY       10     // Enable Y Axis Motor On/Off
#define stepY         11
#define dirY          12 


const int rotateSpeedA      = 1600;  // Slowest
const int rotateSpeedB      = 1200;  // Slower
const int rotateSpeedC      = 800;   // Slow 
const int rotateSpeedD      = 300;   // Fast



// Counters Begin With "c"
// Switches Begin With "s"
int ssw2         =          0;   // Limit Switch X Neg
int ssw3         =          0;   // Limit Switch X Pos
int csw2         =          0;   // count var for Switch SW2
int csw3         =          0;   // count var for Switch SW3
int ctX          =          0;   // count var for X-Axis
int ctY          =          0;   // count var for Y Axis
int crtY         =          0;   // count var for Y axis compare to crtY
int moveY        =        160;   // count var for keypad input [future]
int cstepY       =          0;   // count var for sstepY check
int sstepY       =   (moveY);   // 
// changing moveY determines Y axis move - 1600 steps = 0.100 inch


void setup()

{            // Runs Once at Startup
   pinMode (sw2,            INPUT_PULLUP); // Pin 2
   pinMode (sw3,            INPUT_PULLUP); // Pin 3
   pinMode (enableX,              OUTPUT); // Pin 4
   pinMode (RSTX,                 OUTPUT); // Pin 5
   pinMode (stepX,                OUTPUT); // Pin 8
   pinMode (dirX,                 OUTPUT); // Pin 9
   pinMode (enableY,              OUTPUT); // Pin 10
   pinMode (stepY,                OUTPUT); // Pin 11
   pinMode (dirY,                 OUTPUT); // Pin 12

   Serial.begin(9600);
   delay(1500);
   digitalWrite(RSTX,      HIGH); 

//         Begin - Table moves <-----

   if(digitalRead(sw2)==HIGH && digitalRead(sw3)==HIGH); // Both Open

 {
    do
    {
    digitalWrite(RSTX,        HIGH); // 
    digitalWrite(dirX,        HIGH/*CCW*/);     
    digitalWrite(stepX,        LOW);
    delayMicroseconds(rotateSpeedD);           
    digitalWrite(stepX,       HIGH);
    delayMicroseconds(rotateSpeedD);
    } 

    while (digitalRead(sw2)  ==HIGH);  // while switch is open
    delay(2000);
 }
 // 0-1 Shift
   if(digitalRead(sw2) ==LOW)csw2=1;   // when sw2 closes csw2=1
}

void loop()
{ 
  {       
   // 11110 Run Check         
   if(csw2==1 && csw3==1 && ctY==1 && crtY==1 && cstepY==0)
      {
        do          // Move Y Axis
        {

        digitalWrite(dirY,        HIGH);// CW ---->
        digitalWrite(stepY,        LOW);
        delayMicroseconds(rotateSpeedB);               
        digitalWrite(stepY,       HIGH);
        delayMicroseconds(rotateSpeedB);
        cstepY=(cstepY+1);              // Increment by 1 each cycle
        } 
   while(cstepY<=(sstepY-1));
      }
      // for debugging
      Serial.print("cstepY  =  ");    
      Serial.println(cstepY);
       delayMicroseconds(200);
      Serial.print("sstepY  =    ");
      Serial.println(sstepY);
       delayMicroseconds(200);

   // 110 Run Check   
   if(csw2==1 && csw3==1 && ctY==0)            
      {                
        do          // Move X Axis back to SW2            
        {
        digitalWrite(dirX,        HIGH);// CW ---->
        digitalWrite(stepX,        LOW);
        delayMicroseconds(rotateSpeedD);        // Cutting Speed         
        digitalWrite(stepX,       HIGH);
        delayMicroseconds(rotateSpeedD);
        }      
   while (digitalRead(sw2) ==HIGH);
      }  

   // 100 Run Check         
   if(csw2==1 && csw3==0 && ctY==0)
      {     
        do          // Move X Axis to SW3
        {
        digitalWrite(dirX,         LOW); // CCW Table Moves <----
        digitalWrite(stepX,        LOW);
        delayMicroseconds(rotateSpeedC);           
        digitalWrite(stepX,       HIGH);
        delayMicroseconds(rotateSpeedC);
        }      
   while (digitalRead(sw3)    ==HIGH/*Open*/);
      }
      // for debugging
       delayMicroseconds(200);            
      Serial.print("csw2    =  ");     
      Serial.println(csw2);

   // 11100 check
   if(csw2==1 && csw3==1 && ctY==1)crtY=1;
   // debug
       delayMicroseconds(200);              
      Serial.print("crtY    =    ");
      Serial.println(crtY);

   // 11000 check
   if(csw2==1 && csw3==1 && ctY==0)ctY=1;
   // for debugging
       delayMicroseconds(200);              
      Serial.print("ctY     =      ");
      Serial.println(ctY);

   // 10000 check
   if(csw2==1 && csw3==0 && ctY==0)csw3=1;
   // for debugging
       delayMicroseconds(200);              
      Serial.print("csw3    =        ");
      Serial.println(csw3);       

   if(cstepY==(sstepY-1))crtY=0;
   if(cstepY==sstepY)ctY=0;
   if(cstepY==sstepY)csw3=0;
   if(cstepY==sstepY)cstepY=0;
   // for debugging
   Serial.println("----------------");
   Serial.println("Go Mow The Yard");       
  }
}
                     // End Program


----------



## Foozer (May 8, 2016)

This is Bad - Actually within a few minutes added the 6th counter
Takes the total depth of cut desired e.g. 0.250, cycle increment Y by 0.010 [25 times] until the tdoc is reached, shuts Arduino down [infinite loop] and turns on a Led Done light . .

A couple of weeks of  
	

	
	
		
		

		
		
	


	




 and maybe, just maybe, I might have the basic understanding of 'If' statements understood . .

Now to explore keypad entry to input the tdoc variable from an external source.


----------



## Foozer (May 11, 2016)

@63 learning something new - - Well   
	

	
	
		
		

		
		
	


	




  On the test platform can get x to run back and forth, increment Y on each pass until the desired depth of cut is reached, but don't like the idea of having to reload Arduino for any change in depth of cut. Count button presses she says . . . But dear their are only so many pins on the board that can be used - - And that stops you why? she says . .

She leaves and I go Grrr . .  Yes Dear . .

An old NES Controller to the rescue . . Has a Start Button, I can work with that, a Select Button - now becomes the button to count for Total Depth of Cut - Hit it say 5 times, Hit the Start button and X will cycle back and forth incrementing Y 5 times.

See you can do it, she says . . . She says, See you have a brain
Should I tell her the hour spent trying to read the NES controller with the power to it turned off? That I'm blessed with an 8bit brain in a 256bit world?


----------



## nfk (May 12, 2016)

Been there. Learning something new is frustrating some times.
I pay my bills being a programmer, let me know if you need any help or have any doubt, i'll be glad to help.

Are you doing this as a learning exercise? On the same Arduino route there are shields and software that could allow you to write just gcode to reach your goals. (look for RAMPS on google, it could be easily configured for a mill or lathe)

Norberto


----------



## Foozer (May 12, 2016)

nfk said:


> Been there. Learning something new is frustrating some times.
> 
> Are you doing this as a learning exercise? On the same Arduino route there are shields and software that could allow you to write just gcode to reach your goals. (look for RAMPS on google, it could be easily configured for a mill or lathe)
> 
> Norberto



Haven't done anything digital since 71/72 wherein military MOS was 26L20F5 - Tropospheric Scatter Radio - Roughly what we now carry around in our pockets as a cell phone was something that took a duce and half to carry . .

Learning is a hobby, this go around is the little black box called X-Y table, a little black box called Stepper Motor,  a little black box called Arduino all working together to do what I want.

The Box 'X-Y table' and the Box 'Me' didn't work so well as I would forget which way to turn the wheel . The Box 'X-Y table' and Box 'windshield wiper motor' and Box 'Me' didn't work so well as I would forget which way to flip the direction switch. The Box 'X-Y table' Box 'Stepper Motor,' box 'Me' didn't work so well as again, I would forget which way to flip the direction button.'

Seeing as how the Last Good to First Bad pointed to 'Me' as the bad, figured to give Box 'Arduino' a try . . .

So right now it's learn enough about telling Arduino what to do. To cycle Table to travel in direction X --->, back to start <--- and increment Y a set amount e.g. 0.010 until the desired total e.g 0.250 is reached using a NES Gamepad as an overall input device. Eight buttons should at this stage give me enough choices.

Just now got it to wait and count the button presses to set a counter var used to increment Y, then hit button marked Start, it goes on it's merry way [with 'Me' out of the picture] and stops.

Was ticked pink with getting the Start button to work

if(digitalRead(sw4)==LOW || csw==1)digitalWrite(led1,HIGH);
// sw4 normally open switch - csw must be set to 1 for if statements to be true
 offon();

void offon()
    {      if(digitalRead(sw4)==LOW)csw=1,csw2=1,digitalWrite(led1,LOW),
      Serial.println("ON");  
    }

Live on an island, way to far away from the community college so taking a class  - - - 

Now to fight my natural Abstract Sequential thinking and get more Concrete Sequential to find the counter bug - after last X travel cycle Y increments one extra.


----------



## Foozer (May 12, 2016)

And, not happy with one head banger, also decided to change the cam and lifters  [to a 3896962] in the old Monte for a trip to the Crazy Horse Monument this fall - -  Figured as long as had some access, might as well reroute the firewall wires out of sight . . . 

Wire, Wire, where does she go - - 

Note to Self - Why? . . .


----------



## Foozer (May 14, 2016)

Yay! If it's to easy make it harder, if it's to hard make it easier.

NES Button Pad to Arduino to Stepper - 
if (NESButtonData==B11110111) onOff();           // Start Button
if (NESButtonData==B10111111) tableLeft();     // <--- Button
if (NESButtonData==B01111111) tableRight();   // ---> Button

And she works, hold down the <--- button, stepper runs - Hold down the  ---> button, stepper runs - Like Bottles of Beer on the Wall - Don't focus on the 99, just focus on the 1 . . .


----------



## rodw (May 15, 2016)

Its great to see you are getting your head around coding. You have to start somewhere. Now research the switch() statement and see if you can recode the block of if() statements above using it. It should make your code easier to read. Also, think about programming defensively so that you capture an unexpected error and deal with it accordingly. switch() allows you to do this with default: 

You can also do this with your if statements by setting NESButtonData to an error code before testing the result in the if() block. If it has not changed after your last if(), you have an error. Often we use 0,1 or -1 to denote error but it depends a bit on the circumstances. It is good however to be consistent through your code.


----------



## Foozer (May 15, 2016)

rodw said:


> I . . .  research the switch() statement and see if you can recode the block of if() statements above using it. It should make your code easier to read.



From the look over, Switch Case routine seems to be the next route.
Rewriting the existing plan, removing all unnecessary. Funny, was just thinking about error checking - That's what started this adventure - The big diagram on the wall "Turn Wheel this Way to Move Table That Way" Could look at it twice and still do it wrong.

Thanks for the Input

Also reading 'The Philosophy of Nietzsche' - Summary of St. Thomas Aquinas made what brain cells I have beg for mercy, now with Arduino and Nietzsche, I'm sure they'll go on strike . .


----------



## Foozer (May 16, 2016)

A light went on with the Switch-case suggestion - The function that reads the game pad is always running so variable  -byte NesPad;-    will always contain the received Data from the  NES Control Pad and be stored [the case} So rather than a bunch of 
if (NESButtonData==B11110111) // Start
//do something
if (NESButtonData==B01111111) // --->
//do something
if (NESButtonData==B10111111) // <---
//do something

Which got messy real quick

Use

switch (NesPad)
{
    case 247: // 'Start Button'
      Onoff()
      break;
    case 127: // ---> Button
      RunRight()
      break;
    case 191: // <--- Button
      RunLeft()  
    default:
      // default is optional
    break;
  }
} // End void loop

Put the functions down below which on the face of it appears to be not only neater but better managed . . 

void Onoff()
// do something
void RunRight()
//do something
void RunLeft()
//do something


----------



## rodw (May 17, 2016)

Great progress Foozer. Now at the top of the program or even better in a separate header file (.h) create some defines something like
#define BTN_LEFT 191

So in the switch statement you can say
case BTN_LEFT:
     RunLeft();
default:
    show_error();  // should never happen but catch it anyway.

If a procedure is longer than one page, it needs to be broken up into other procedures so your code is easy to read.


----------



## Foozer (May 17, 2016)

rodw said:


> Great progress Foozer. Now at the top of the program or even better in a separate header file (.h) create some defines something like
> #define BTN_LEFT 191
> 
> 
> ...



So that's how to convert the abstract [e.g. 191] into the concrete [e.g. btn_Left] ... Was putting around with the under-hood car wiring yesterday (Monday) but did play with one function desire a bit . . Now to add a counter so when the button is hit the table Jogs in predetermined increments - I know there are cheap single axis controllers that will do all this - But that's no Fun 

Idea being - Run Left Button checks to see that the Limit Switch is open [not tripped] -- move table as long as button is held - If Limit Switch trips - shut off Stepper [ don't over-run] and turn on Rad Led - - Can only re-enable stepper by hitting the Start Button

void Start() // 247 Start Button
{    
    digitalWrite(enableX,   LOW); // LOW, STEP commands are processed 
    delay(500);                   // Wait Half Second
    digitalWrite(ledOn,     HIGH);  // HIGH, ON Turn On Ready Light
}  


void runLeft() // 191 <--- Button sw3
{   if(digitalRead(sw3)==LOW)digitalWrite(enableX,HIGH),digitalWrite(ledOn,LOW);

   { 
     digitalWrite(dirX,      LOW); // CCW     
    digitalWrite(stepX,     LOW);
    delayMicroseconds(800);           
    digitalWrite(stepX,    HIGH);
    delayMicroseconds(800);
    }
}

*.h file   Time to look into library creation - Do see how the usage of can simplify the process - - 

Still haven't mowed the Yard - - Bride's beginning to weary of my
"But Look What I Can Do!!" response  - -


----------



## Foozer (May 18, 2016)

Sometimes ya just can't avoid Downward Causality. Got that car wiring - time to route the blower motor wire - DBL - but are two DBL wires. Don't want to hook up battery just in case the Magic Smoke wants to be free. . so use a small power supply to get a readable signal - Works Fine - But that 'Magic Smoke is still written in my Downward Causality - Note to self - Don't hook the wrong power supply to Arduino - Can't complain - better to smoke arduino than a dash full of wires - -

Played with made a .h file, LEDXY.h to clean up if/when want to use an LED as an indicator - - 

#include <LEDXY.h>
LEDXY led; 
void setup()
{/*nothing*/}
int x=0;
void loop()
{
  if(x<10) // Blink 10 times 
  {
  led.blink(300);  
  x++;
  }
  else
  {
    led.on(); // Led On
  }
}


----------



## rodw (May 18, 2016)

Foozer said:


> So that's how to convert the abstract [e.g. 191] into the concrete [e.g. btn_Left] .



Foozer, great to see you make progress every day. Reading and disecting other code is a great way to learn how to code. Any code written in C will help enormously, not just Arduino code.

I don't want to blow my own trumpet, but some people said that this Auduino sketch I wrote is well written (and controls a rotary table).
http://www.homemodelenginemachinist.com/showthread.php?t=25091

At the very beginning of this thread I link to another thread containing detail. You have to be impressed with what Scott achieved with the code I wrote....

Enjoy.


----------



## Foozer (May 18, 2016)

rodw said:


> Foozer, great to see you make progress every day.



So you're the guy that got me started on this - If X can do a thing than I can do a thing . . . Today is work on car wiring a bit and dig up a means to Idiot Proof the power supply hookup to my little stepper testing box. Motors are 17H234-055-4A and run fine on 5v - Spaced and flipped the supply switch to 12V - 30 seconds later the little regulator in Arduino let the 'Magic Smoke' out - But better it go up in smoke than the dash wiring in the car -  And to fulfill the 'Rule of Three' neighbor lady ask - Can you come over and look? my dryer plug is not working -
1) Fix test model
2) Fix dryer plug
3) Look into passing more than one variable into a (.h) file
4) Mow yard? Naw . . .


----------



## Foozer (May 18, 2016)

Don't know what I'm doing with sketches, Library's? not so much either - But it is working - Little short to test the LEDXY.h - and it just sits there happy  . . .
(.cpp) file
#include "LEDXY.h" //include the *.h file  

LEDXY::LEDXY(){ } 

//<<destructor>>  Have no Idea what this means 
LEDXY::~LEDXY(){/*nothing*/} 
// Get input from Sketch to set Led Pin (int ledPin) and blink rate (int rate) 
void LEDXY::blink(int ledPin, int rate)  // Seems can grab more than one input from Sketch
// Write the Blah Blah here 
{ 
        pinMode(ledPin, OUTPUT); 
        digitalWrite(ledPin, HIGH); 
    delay(rate);     
    digitalWrite(ledPin, LOW); 
    delay(rate);    
} 
void LEDXY:n (int ledPin)
{
        pinMode(ledPin, OUTPUT); 
        digitalWrite(ledPin, HIGH);
}

#include <LEDXY.h>
LEDXY led;
void setup(){}
void loop()
{
   for(int x=0; x<=10;x++) // Blink 10 times
   { led.blink(52,100); }  // Takes 2 inputs Pin Number and blink Rate - Red

   for(int x=0; x<=10;x++) // Blink 10 times
   { led.blink(53,250); }  // Green

   { led.on(53); }         // Takes 1 input Pin Number - After 10th Blink Stay on till next blink cycle

}


----------



## rodw (May 19, 2016)

Foozer, bad luck about the Arduino. I have blown up a few and ended up buying 10 off alibaba. I have a spare but on the wrong side of the world for you.

In your LED array you are using a class which is the OOP (Object oriented programming) addon on to C which was named C++. 

In a class there is a constructor and a destructor  which are called once  when the data type is initialised and destroyed. These are where you set up the  environment to suit in the constructor and then cleaned up in the destructor. Time enough for that. If you can master classes, you will be a programming wizard...


----------



## Foozer (May 19, 2016)

rodw said:


> Foozer, bad luck about the Arduino.
> In a class there is a constructor and a destructor  If you can master classes, you will be a programming wizard...



Arduino's are cheap enough, have a spare (UNO and a Mega) and ordered a couple more just in case. Just don't use those Wall-Wart power gizmos 


Will have to look up the terms and get at least a rudimentary understanding - As it is or at least as I understand so far can place say #define red1 52, 52 becomes defined as red1 [Red Led] which allows led.blink(pinNumber, rate) to be written out in the sketch as led.blink(red1, 200)  - - Much Much Easier - - Kinda like how St Thomas Aquinas wrote . . Listed objections than replies but takes two readings to follow it - First straight through for flavor than back to objection 1 with reply 1 for the digest.

It's not that the exclusion of library's from sketching is bad, but rather of a deficient good for all things of a deficient good are still good none-the-less. But to include the exclusion makes the sketch bad absolute.

Query - have noticed that when switching enable on/off on say a 200 step motor, the driver configured for eighth stepping will cause the motor to jog as if the poles now energized are aligning  themselves to what a step position at a 200 rate would be rather than the in-between position the motor may be at -

Ok time to put more of this together and ratchet up a library for the stepper directions - Then you say - will have a neater page to work with to get what must needs be done . .


----------



## Foozer (May 21, 2016)

I'm no library wizard, but the newborn ones do indeed work.
Note to self 'It's tab key in Keyword.txt not space bar . .'

Check switches in void setup() and move table to what I'll call a Home Position for now - - -

//    Begin Table Position Check
  led.on(ledStart);                    // pin number
  Stepper.Run(enableX);               // Turn On Stepper
  if(digitalRead(sw2)==HIGH && digitalRead(sw3)==HIGH);
  delay(50);
  {
    do
    {  
     Stepper.CCW(stepX, dirX, 800);     //stepPin, dirPin, rate microseconds
    } 
    while (digitalRead(sw2) == HIGH);  // While sw2 is Open
  }
  if(digitalRead(sw2)==LOW && digitalRead(sw3)==HIGH);
  delay(50);
    {
  Stepper.Stop(enableX);              // enablePin Turn off Stepper
  led.off(ledStart);             // ledPin
  led.on(ledOff);                // ledPin
    }
  //    End Table Position Check

Usage of, does indeed clean up the sketch


----------



## Foozer (May 28, 2016)

Ya! Poor mans stepper acceleration - Only took a few hours before I realized I could not reset the timer1 counter while in the runY_down() function - Like really? the button controller spits out 255 when no button is pressed, use that to reset . . .

if (nesButtonData == 255)timer1 = 1200; // first line void loop

void runY_down()
{
  timer1- -;
  if (digitalRead(enableY) == HIGH)Led.blink(ledGreen, timer);  
//  Off Do Nothing - Blink Led
  // if(digitalRead(enableY) == LOW)                           // On
  if (timer1 < 1200 && timer1 > 1100)timer2 = 800;      // timer2 - microseconds
  else if (timer1 < 1099 && timer1 > 1000)timer2 = 700;
  else if (timer1 < 999 && timer1 > 900)timer2 = 600;
  else if (timer1 < 899 && timer1 > 800)timer2 = 500;
  else if (timer1 < 799 && timer1 > 600)timer2 = 400;
  Stepper.CW(stepY, dirY, timer2);
}


----------



## Foozer (May 28, 2016)

Rather than take the long way around the fence, better to just cut a hole in it and pass through. Shortened up the language for bringing the motor up to speed . . . 

// timer1 begins at 2000, counts down to 400 and then is set at 400
// timer1 is reset in getNesButtonDada to 2000 when NesButton is released . . .
// Count down timer1 and Accelerate stepper speed from slow to high
  timer1 = timer1 - 2;            // Adjustable Acceleration rate
  if (timer1 <= 400)timer1 = 400; // 400 is top speed for the test platform motor
  Stepper.CW(stepY, dirY, timer1);


----------



## BillH (May 29, 2016)

Before Arduino, I made a stepper driver using an Atmel ATmega, programmed it in Atmel studio, and made a dual h bridge out of mosfets. I could do full stepping and half stepping. The switch statement is the way to go. Your if statements needed else if and else. Switch is easier, more elegant.


----------



## BillH (May 29, 2016)

And about debouncing, the engineers over at Collins screwed the pooch on the FMS in the CRJ I fly.  Half the time I have to delete stuff because one of the other inputs doubled or tripled pressed. An ACARS message may look like this: TTHANKSS FOR    THEE WEATTHERR..

I would think a software denounce using a timer, say 80 ms goes by before another input is recognized.


----------



## Foozer (May 30, 2016)

BillH said:


> . . . Switch is easier, more elegant.



Am liking Switch - Case, can fiddle with a single case and not break the others. Finally got the section I wanted to do what I wanted it to do. To take a inputed Y axis total depth of cut e.g. 0.250, divide that into number of increments needed to go @ 0.010 cut per pass, run X axis back and forth, increment, x axis back and forth, increment . .  then stop when done . .
{
  // Begin Function - Make sure table is at Home Position
  if (digitalRead(sw2) == HIGH && digitalRead(sw3) == HIGH)
  { 
    do
    {
      Stepper.CCW(stepX, dirX, 800);   //step, dir, rate microseconds
    }
    while (digitalRead(sw2) == HIGH);
  }
  for (; x < cycleY; x = x + 1)
    if (cycleY == y)y = 0;
  if (z == 2)z = 0;

  // Fist Move Y axis Jog Amount
  delay(500);   // Delay Half Second
  {
    for (int jog = 0; jog < 480; jog++) // @ 3:1 ratio Jog Y 0.010 inch
      Stepper.CW(stepY, dirY, 800);
    delay(500);
  }
  // Then Move table to sw3 ...  Cut Material
  if (digitalRead(sw2) == LOW); // Check Position Switch
  delay(50);
  {
    do
    {
      Stepper.CW(stepX, dirX, 800);   //step, dir, rate microseconds
    }
    while (digitalRead(sw3) == HIGH); // While sw3 is Open
    z = z + 1;    // Set Z counter to 1
    // Then Move table back to sw2
    if (digitalRead(sw3) == LOW); // Check Position Switch
    delay(50);
    {
      do
      {
        Stepper.CCW(stepX, dirX, 800);   //step, dir, rate microseconds
      }
      while (digitalRead(sw2) == HIGH); // While sw2 is Open
      z = z + 1;    // Set Z counter plus 1 sets z  now to 2
      if (x >= cycleY)y = y + 1;  
    // y is Increment cycle counter, counts up to meet cycle y variable
      if (y == cycleY)Stepper.off();  // If counters equal turn off steppers
      x = 1;
    }
  }
}
// End Function

Now to mount the full scale  stuff in a box, hook up the Y Axis stepper, redo the position switches and try it out . . .

Still have a check list to solve - Can button press increment the total depth of cut, but need to add in a means to decrease should I over shoot the number . . . Right now press button, increases by 1, hold button down and will increase by 1 every qtr second

And if I don't write out an instruction sheet soon, I'll forget the how and why what the heck I made to be used . . .


----------



## Foozer (May 31, 2016)

Now I'm just getting anal with the testing model, time to take the bucket of parts and get things going . .








Course if it begins to look like my work bench, I may be at it for a while . .


----------



## Foozer (Jun 5, 2016)

Working it from the 'Cigar Box' to well, a bigger box. Red band for X, yellow band for Y - For bells and whistles wanted to have an external means to set a Y axis total cut distance. Worked it out to change the variable with button(s) push to increment and decrement. But first go round and ran out of available pin on the standard UNO - - Why use more buttons, use the Keypad she said - -

Huh? Ah Yes I see dear, keypad also spits outs a different number when two buttons are pressed, e.g 250 is  Select + A,   249 is  Select + B. So can use button A for one thing and 'Select + A for another thing.

Now that frees up some pins and so far it all fits on a standard UNO - Back to wires - Figure if I start out trying to keep them neat - well . . .


----------



## Foozer (Jun 10, 2016)

Getting Closer - - -


----------



## Rndmann9 (Jun 11, 2016)

What kind of scope are you using there.   I'm using an arduino and a Gshield v5 on mine


----------



## Foozer (Jun 11, 2016)

Rndmann9 said:


> What kind of scope are you using there.   I'm using an arduino and a Gshield v5 on mine



Haven't progressed to the 'black box' called G-Code yet. Was only a few weeks ago that I started looking into arduino coding. Once I get comfortable with the X-Y then it'll be time to get the X-Y to work together to work a circle . . .

See, was making some T-Nuts and got tired of hand cranking - Hooked up a windshield wiper motor - worked fine but couldn't hand crank - Then to a stepper with a simple push button controller - could hand crank but kept forgetting which button was what direction - Then to Arduino with a Y axis stepper - Then to . . . And I already made the T-Nuts I wanted to make . .

So the 20x4 LCD came today - Time for a little bell and whistle inclusion . . . I try not to think about it too much least I shake my head and go "Really!"


----------



## Rndmann9 (Jun 11, 2016)

I have used arduinos for other projects for a couple of years.  The Gshield is almost plug and play. You run a program on the arduino nod then the Gshield handles all the motor movements.  I just got it Monday and got it talking buy Tuesday.  Relatively painless. This is the type stuff I normally use arduinos for.


----------



## Foozer (Jun 11, 2016)

Rndmann9 said:


> . . . This is the type stuff I normally use arduinos for.




Way too much free time - - But then Richard of Gas Monkey Garage could use a Beer Assistant Robot that delivers upon command . . .


----------



## Rndmann9 (Jun 11, 2016)

Ha.  Not that much free time. With three boys my free time is limited.  It comes in spurts. Lol.


----------



## Rndmann9 (Jun 11, 2016)

One day I will figure out why it flips my pics too!??


----------



## Rndmann9 (Jun 11, 2016)

Btw the electronics area of my shop is way worse. Lol


----------



## Cogsy (Jun 11, 2016)

Rndmann9 said:


> One day I will figure out why it flips my pics too!??


 
I'm going to guess you take them with an iPhone/iPad? Apple will let you flip your device but still retains an arbitrary 'top' which it encodes into the picture. It'll be right way up all the time on an Apple device but on a pc it depends which way up you took it.

If it's some other camera I have no idea...


----------



## Rndmann9 (Jun 12, 2016)

iPad and that makes sense


----------



## Foozer (Jun 13, 2016)

int,  float, string - - Oh-My -  All I wanted was a bell and whistle, the LCD to display in inch what the step jog amount is e.g 16 steps=0.001" - - Int nope, won't do decimal math -  Float - took an hour or so to fi8nd out it chops it off 2 places after decimal -- String? Oh-Boy - - don't know, but it works

printjogX = String((stepsX / 16) * .001, 3); 
  lcd.print(printjogX);
// steps increment-decrement by 16 and/or 160 dependent upon button combo

I have an intake manifold to put on the car, however, with this Arduino diversion what is a day job might take until Xmas . . .


----------



## rodw (Jun 13, 2016)

Time to learn about casting between data types 

int x = 100;
float y =0.0;

y = (float) x;  //  now y = 100.0

Also with integer maths, sometimes you need the remainder

int x = 14 % 12; // now x = 2

And also int y =  14/12. // y = 1

Int numbers can't count fractions


----------



## rodw (Jun 13, 2016)

So now I've had dinner, I will go on to say that floating point maths has a vey high overhead. You are counting 16,000 steps per inch so I would stay in integers all the way and write a function called display_inches(int steps) that first divided by 16,000 and printed the value, then a decimal point, then calculate the remainder  using the % operator and convert that to thou before printing. The challenge is to left pad the thous so .009 displays correctly. There are a number of ways to do that. Pseudo code only, but maybe something like:
inches = steps / 16000;
thousteps = steps % 16000;
thou = thousteps / 16;
print (inches);
print (".");
if (!thou)print ("000");
else if(thou < 10) print ("00")
else if (thou < 100) print ("0");
if(thou)print (thou);

For a refinement, think about this enhancement. Before calculating thou, add 8  to thousteps.
This will mean that rounding up will occur if more than half way to the next thou....


----------



## Foozer (Jun 13, 2016)

rodw said:


> Pseudo code only, but maybe something like:
> inches = steps / 16000;
> thousteps = steps % 16000;
> thou = thousteps / 16;
> ...



Here am just printing to LCD what the stepX variable is
what I got going is

loat stepsX  =         16;   // Used for Jog - 
float stepsY  =         16;
String printjogX;
String printjogY;

In void setup         // print initial screen

lcd.setCursor(0, 1);
  lcd.print("Jog =");
  lcd.setCursor(6, 1);
  printjogX = String((stepsX / 16) * .001, 3);
  lcd.print(printjogX);

In void loop
case btn_stepXPlus1:  // Select + Up Button - 231 from Nes
      stepXPlus1();
      break;


// Increment Up
void stepXPlus1()     //  Select + Up Button
{
  stepsX = (stepsX + 16);         //  16 = 0.001
  if (stepsX <= 16)stepsX = 16;   // Default
  displayXOn();
  delay(250);
}

void displayXOn()
{
lcd.setCursor(6, 1);
  printjogX = String((stepsX / 16) * .001, 3);
  lcd.print(printjogX);
}

If I gather you correctly - leave variable stepsX as an int and on the fly change it to a float  so with 
int stepsX = 16;
String printjogX;
e.g.  printjogX  = String(((float)stepsX / 16) * .001, 3);
works - - prints out correctly

e.g. printjogX  = String((stepsX / 16) * .001, 3);
also works

Oh Boy - - Float and String each something I need to delve into farther -  Coffee Assistant!!


So, at least the plan was, as I found out, LCD's are not the quickest responding things on the block, was to change on the screen only that portion that needed changing.

Gonna putt with the car today and let your advise rattle around, found that when doing something that I do know, the things I don't know much about get clearer . .


----------



## Foozer (Jun 15, 2016)

Decided to do a 'Smoke Test' aka see if the wires are routed correctly - Plugged in one stepper, turned it on and no 'Magic Smoke - - Just let it cycle back and forth for a couple hours while putting with the car - - The 'Really Dude' you spent how much time just so some gizmo could go back and forth did cross my mind - but that's small stuff and one never frets the small stuff when having fun . .


----------



## Foozer (Jun 16, 2016)

@rodw   If your out there - Help - have a code question - it's for the y axis that increments - when done have to rewind stepper back to starting point  - Possible that the rewind could exceed 2 inches (32k)

to capture var number larger than what int allows e.g. 16000 steps x 4 inches is 64000 - From what I gather use 'long' instead of int . .

for (long jog = 0; jog <= 1000 * 100L; jog = jog + 1000)
    Serial.println(jog);

it serial prints up to 100k and starts over -

To me the black box 'int' is too small and I need a bigger black box - Is 'long' the correct bigger black box?


----------



## rodw (Jun 18, 2016)

Foozer said:


> @rodw   If your out there - Help - have a code question - it's for the y axis that increments - when done have to rewind stepper back to starting point  - Possible that the rewind could exceed 2 inches (32k)
> 
> to capture var number larger than what int allows e.g. 16000 steps x 4 inches is 64000 - From what I gather use 'long' instead of int . .
> 
> ...



Yes, long will work nicely. If you dont need negative values, you could use unsigned int. This lets you count to 64k.


----------



## Foozer (Jun 18, 2016)

rodw said:


> Yes, long will work nicely. If you dont need negative values, you could use unsigned int. This lets you count to 64k.



Thanks - No down side, Long is a keeper - I Looked at the different flavours of int and it's subsets, for the Y with a max travel of 5 inches and resolution of 1600 steps - Long seemed to be the one - resolution of 800 steps, unsigned Int  - 400 steps, plain Int. Controller doesn't allow for changing step rate on the fly so max table speed is set by controller's hard switches . . . Why I stick with looking at things as just Black Boxes - Don't open the box of Schrodinger's cat as every answer found raises two more questions. . .

Course if I knew where the water fall was, I'd of known it doesn't work so well to to put a regulated 5v to the DC plug jack. Apparently when you open that box the cat is near death. 5v in the DC jack and the 5v pin on arduino only reads some 3.3 . . .

It's Fathers Day - - and the kids owe us a Lunch - - or wash the car for Dear Ol Dad


----------



## Foozer (Jun 18, 2016)

So thought I'd give dealing with backlash a shot


if (y == cycleY)           // Check Up counter against cycleY
      {
        for (long jog = 0; jog <= tdocY * 48L + backlash; jog++) // @ 48 - 3:1 ratio @ 1600 step resolution
        {
// Rewind it back total amount of travel plus backlash amount
          Stepper.CCW(stepY, dirY, rate * 10);
        }
        delay(1000);
        for (int jog = 0; jog <= backlash; jog++) // @ 3:1 ratio
        {
// then advance forward the backlash amount
          Stepper.CW(stepY, dirY, rate * 10); } } } }
  if (y == cycleY)x = 1, Stepper.off(enableX, enableY);
}

// End Function

Suppose as long as the backlash is measured somewhat accurate it'll work . . .


----------



## Foozer (Jul 11, 2016)

One self contained box of 'Stuff' done - Everything needed for the X-Y in one each genuine plastic package - -
...





...


...

After 'near 30 years [long restore project] of off/on looking finally acquired the correct rear pipe guard for the Putt Putt - - trip to the chrome shop and she looks good as new. Do recall chuckling watching grown men riding little trains on a raised track, Of course is no resemblance to this old guy riding the Putt Putt up and down the street . .







...


----------



## Foozer (Jul 17, 2016)

Closer - - Running the Y-Axis from the rear - - At least that's the workout so far - When complete can say I planned it that way.





...

Motor piece has a slot for belt adj - Piece by piece what-ever it is, is taking shape . . .  Soon as the correct size belt comes in 160xl037 can move the project forward . .


----------



## Foozer (Jul 21, 2016)

Its Alive - using the keypad to enter total cut desired and how much to cut at one time - It'll cycle till done . . 


[ame]http://www.youtube.com/watch?v=0HfzbUMXxsQ[/ame]


----------



## Foozer (Jul 24, 2016)

Alive and messy . . Stuck a hunk of stock in it, told it the Total Y movement was 1.2 inch and to jog Y @0.300 per pass using a 0.375 end mill. Four passes later - i can't complain - and yes it's a drill press - replaced the lower spindle bearing with a double row bearing, pinned the whatch-ma-call-it into the thing-a-ma-jig so it won't work loose and the chuck was more than a couple of bucks .

Now that I'm getting a bit of a handle with arduino and steppers, might actually get a mill - - The post of the drill press is braced to the wall, above that wall is the kitchen - Well at least the Bride knows where I am at - Thum-Thum-Thum-Thum . . .


----------



## Foozer (Jul 29, 2016)

Time to remount the Y motor and change the pulley's from 1-1 to 2-1 [an eleven and twenty two tooth pully combo] Motors only 'bout 250 oz in and that table is a lot of weight for it to move . . .

I like those little motor covers with wire socket - Just looks and feels neater - Way it's configured now the X motor will hit it - -


----------



## Foozer (Aug 13, 2016)

Got er flipped around - No more interference - Hunk of stock is  a tad robust, is what I had - Holds two bearings to take the bulk of the  shaft load. Hunk is slotted 1.25 x .187 - - That was fun @ 30 tho per pass to cut a slot through the 1/2 inch thick part. There the jog function worked well. Inputed for variable Jog 1.25 inch, hit the button [select and right] off she went 1.25, hit the button [select and left] and back she went. . .  A little Eastwood Brake Grey paint and well 'Really?' comes to mind - - -





...
A little 1/4 20 adj screw to tighten the belt and she's snug as a bug.


----------



## BillH (Aug 13, 2016)

You'll find the weak spot to be the table to column mount, just a bit of pressure causes flex


----------



## Foozer (Aug 13, 2016)

BillH said:


> You'll find the weak spot to be the table to column mount, just a bit of pressure causes flex




Absolute - - It's not a mill, will always be a drill press with its flaws and not a mill. It's bolted to the floor, column is tied to the wall, added a couple of 3/8 snug up bolts, front side @120 degree spacing to the table-column mount and a couple of down rods from the table to the base to firm it up a bit.

It's a drill press and as many say - A drill press will never be a mill - Just because I still have all my fingers and toes doesn't mean others would fare as well - - -

This is and was just a fun exercise in using Arduino [which I knew nothing about] to control a couple of steppers [which I now know little about]

Plan is to 'Downsize' from this place [way to big for my needs now that the kids are grown] to a little shack. Bank the equity less what is carved out for a proper mill  - - -


----------



## Foozer (Aug 14, 2016)

So without lifting the pen or crossing any line draw the figure - -





... If Arduino can draw it guess I can cut it . . .


----------



## Foozer (Aug 16, 2016)

If Arduino can draw it guess I can cut it . . .





...

And how to put off getting a mill again ? Start working on the place - That's a week of pressure washing, acid washing and a grand worth of coating . . . Least now have the floor prep down pat for the next shop - Epoxy coating - The only way to go - - -


----------

