Arduino and the NewBee

Home Model Engine Machinist Forum

Help Support Home Model Engine Machinist Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.
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 :)
 
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....
 
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);

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 . .

DSCF0021_zpsoys9l22a.jpg
 
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 . .

DSCF0033_zpsrpunx8fw.jpg
 
@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 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?

Yes, long will work nicely. If you dont need negative values, you could use unsigned int. This lets you count to 64k.
 
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 ;)
 
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 . . .
 
One self contained box of 'Stuff' done - Everything needed for the X-Y in one each genuine plastic package - -
...
DSCF0038_zpsdx7ky7hf.jpg


...


...

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 . .

DSCF0040_zpseusp5cxm.jpg



...
 
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.

DSCF0042_zps5vrfuowl.jpg

...

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 . .
 
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 . . .

DSCF0053_zpsu4gpx5f2.jpg
 
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 - -

DSCF0056_zpsvoyb7joj.jpg
 
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 - - -
DSCF0063_zps0angtfkm.jpg


...
A little 1/4 20 adj screw to tighten the belt and she's snug as a bug.
 
You'll find the weak spot to be the table to column mount, just a bit of pressure causes flex
 
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 - - -
 
If Arduino can draw it guess I can cut it . . .
DSCF0069_zpsfavnmzi3.jpg


...

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 - - -

DSCF0070_zpsmcgbi7fu.jpg
 

Latest posts

Back
Top