Can anyone help me get a couple of stepper motors to run from this shield?
i trying find sketch allow me experiment grbl run stepper motors shield.
i have uploaded sketch 'grblupload' library software downloaded called grbl-master, one
and using universal gcode sender can jog motors. can put sinple instructions grbl sender such y-5 , y motor moves.
i able build set of instructions set , drive motors using grbl can learn how works.
i can load sketch looks if this
with sketch in arduino, if open monitor get
start
if put instruction in y-5 pause word
ok
but nothing happens motors?
what hold of sketch allows me input list of instructions can saved within sketch don't lose them every time send them shield , activates motors when run it.
is there such thing?
i have uploaded sketch 'grblupload' library software downloaded called grbl-master, one
code: [select]
/***********************************************************************
this sketch compiles , uploads grbl 328p-based arduino!
to use:
- first make sure have imported grbl source code arduino
ide. there details on our github website on how this.
- select arduino board , serial port in tools drop-down menu.
note: grbl officially supports 328p-based arduinos, uno.
using other boards not work!
- click 'upload'. that's it!
for advanced users:
if you'd see else grbl can do, there additional
options customization , features can enable or disable.
navigate file system arduino ide has stored grbl
source code files, open 'config.h' file in favorite text
editor. inside dozens of feature descriptions , #defines. simply
comment or uncomment #defines or alter assigned values, save
changes, , click 'upload' here.
copyright (c) 2015 sungeun k. jeon
released under mit-license. see license.txt details.
***********************************************************************/
#include <grbl.h>
// not alter file!
and using universal gcode sender can jog motors. can put sinple instructions grbl sender such y-5 , y motor moves.
i able build set of instructions set , drive motors using grbl can learn how works.
i can load sketch looks if this
code: [select]
// arduino g-code interpreter
// v1.0 carlos guilarte y diego colonnello...
// modificado para manejar tres ejes en un cnc chimbo... jejeje
#include <hardwareserial.h>
//our command string
#define command_size 128
char palabra[command_size];
byte serial_count;
int no_data = 0;
void setup()
{
//do startup stuff here
serial.begin(115200);
serial.println("start");
//other initialization.
init_process_string();
init_steppers();
}
void loop()
{
char c;
//keep hot!
//read in characters if got them.
if (serial.available() > 0)
{
c = serial.read();
no_data = 0;
//newlines ends of commands.
if (c != '\n')
{
palabra[serial_count] = c;
serial_count++;
}
}
//mark no data.
else
{
no_data++;
delaymicroseconds(100);
}
//if theres pause or got real command, it
if (serial_count && (c == '\n' || no_data > 100))
{
//process our command!
process_string(palabra, serial_count);
//clear command.
init_process_string();
}
//no data? turn off steppers
if (no_data > 1000)
disable_steppers();
}
with sketch in arduino, if open monitor get
start
if put instruction in y-5 pause word
ok
but nothing happens motors?
what hold of sketch allows me input list of instructions can saved within sketch don't lose them every time send them shield , activates motors when run it.
is there such thing?
i have found sketch in same folder? not in own folder.
when gave own folder able load ide when tried compile got lot of
'xxx not declared in scope.'
i started declare them there many wondering if intentional , used in other way?
has had experience these programs , can me way of sending grbl shield can build from.
i can open txt reader, build program , load gcode sender long winded.
code: [select]
//init our variables
long max_delta;
long x_counter;
long y_counter;
long z_counter;
bool x_can_step;
bool y_can_step;
bool z_can_step;
int milli_delay;
void init_steppers()
{
//turn them off start.
disable_steppers();
//init our points.
current_unitsx = 0.0;
current_unitsy = 0.0;
current_unitsz = 0.0;
target_unitsx = 0.0;
target_unitsy = 0.0;
target_unitsz = 0.0;
pinmode(x_step_pin, output);
pinmode(x_dir_pin, output);
pinmode(x_enable_pin, output);
pinmode(x_min_pin, input);
pinmode(x_max_pin, input);
pinmode(y_step_pin, output);
pinmode(y_dir_pin, output);
pinmode(y_enable_pin, output);
pinmode(y_min_pin, input);
pinmode(y_max_pin, input);
pinmode(z_step_pin, output);
pinmode(z_dir_pin, output);
pinmode(z_enable_pin, output);
pinmode(z_min_pin, input);
pinmode(z_max_pin, input);
//figure our stuff.
calculate_deltas();
}
void dda_move(long micro_delay)
{
//enable our steppers
digitalwrite(x_enable_pin, high);
digitalwrite(y_enable_pin, high);
digitalwrite(z_enable_pin, high);
//figure out our deltas
max_delta = max(delta_steps.x, delta_steps.y);
max_delta = max(delta_steps.z, max_delta);
//init stuff.
long x_counter = -max_delta/2;
long y_counter = -max_delta/2;
long z_counter = -max_delta/2;
//our step flags
bool x_can_step = 0;
bool y_can_step = 0;
bool z_can_step = 0;
if (micro_delay >= 16383)
milli_delay = micro_delay / 1000;
else
milli_delay = 0;
//do our dda line!
do
{
x_can_step = can_step(x_min_pin, x_max_pin, current_steps.x, target_steps.x, x_direction);
y_can_step = can_step(y_min_pin, y_max_pin, current_steps.y, target_steps.y, y_direction);
z_can_step = can_step(z_min_pin, z_max_pin, current_steps.z, target_steps.z, z_direction);
if (x_can_step)
{
x_counter += delta_steps.x;
if (x_counter > 0)
{
do_step(x_step_pin, x_dir_pin, x_direction);
x_counter -= max_delta;
if (x_direction)
current_steps.x++;
else
current_steps.x--;
}
}
if (y_can_step)
{
y_counter += delta_steps.y;
if (y_counter > 0)
{
do_step(y_step_pin, y_dir_pin, y_direction);
y_counter -= max_delta;
if (y_direction)
current_steps.y++;
else
current_steps.y--;
}
}
if (z_can_step)
{
z_counter += delta_steps.z;
if (z_counter > 0)
{
do_step(z_step_pin, z_dir_pin, z_direction);
z_counter -= max_delta;
if (z_direction)
current_steps.z++;
else
current_steps.z--;
}
}
//wait next step.
if (milli_delay > 0)
delay(milli_delay);
else
delaymicroseconds(micro_delay);
}
while (x_can_step || y_can_step || z_can_step);
//set our points same
current_units.x = target_units.x;
current_units.y = target_units.y;
current_units.z = target_units.z;
calculate_deltas();
}
bool can_step(byte min_pin, byte max_pin, long current, long target, byte direction)
{
//stop if we're on target
if (target == current)
return false;
//stop if we're @ home , still going
else if (read_switch(min_pin) && !direction)
return false;
//stop if we're @ max , still going
else if (read_switch(max_pin) && direction)
return false;
//default being able step
return true;
}
void do_step(byte pina, byte pinb, byte dir)
{
switch (dir << 2 | digitalread(pina) << 1 | digitalread(pinb)) {
case 0: /* 0 00 -> 10 */
case 5: /* 1 01 -> 11 */
digitalwrite(pina, high);
break;
case 1: /* 0 01 -> 00 */
case 7: /* 1 11 -> 10 */
digitalwrite(pinb, low);
break;
case 2: /* 0 10 -> 11 */
case 4: /* 1 00 -> 01 */
digitalwrite(pinb, high);
break;
case 3: /* 0 11 -> 01 */
case 6: /* 1 10 -> 00 */
digitalwrite(pina, low);
break;
}
delaymicroseconds(5);
}
bool read_switch(byte pin)
{
//dual read crude debounce
if ( sensors_inverting )
return !digitalread(pin) && !digitalread(pin);
else
return digitalread(pin) && digitalread(pin);
}
long to_steps(float steps_per_unit, float units)
{
return steps_per_unit * units;
}
void set_target(float x, float y, float z)
{
target_units.x = x;
target_units.y = y;
target_units.z = z;
calculate_deltas();
}
void set_position(float x, float y, float z)
{
current_units.x = x;
current_units.y = y;
current_units.z = z;
calculate_deltas();
}
void calculate_deltas()
{
//figure our deltas.
delta_units.x = abs(target_units.x - current_units.x);
delta_units.y = abs(target_units.y - current_units.y);
delta_units.z = abs(target_units.z - current_units.z);
//set our steps current, target, , delta
current_steps.x = to_steps(x_units, current_units.x);
current_steps.y = to_steps(y_units, current_units.y);
current_steps.z = to_steps(z_units, current_units.z);
target_steps.x = to_steps(x_units, target_units.x);
target_steps.y = to_steps(y_units, target_units.y);
target_steps.z = to_steps(z_units, target_units.z);
delta_steps.x = abs(target_steps.x - current_steps.x);
delta_steps.y = abs(target_steps.y - current_steps.y);
delta_steps.z = abs(target_steps.z - current_steps.z);
//what our direction
x_direction = (target_units.x >= current_units.x);
y_direction = (target_units.y >= current_units.y);
z_direction = (target_units.z >= current_units.z);
//set our direction pins well
digitalwrite(x_dir_pin, x_direction);
digitalwrite(y_dir_pin, y_direction);
digitalwrite(z_dir_pin, z_direction);
}
long calculate_feedrate_delay(float feedrate)
{
//how long our line length?
float distance = sqrt(delta_units.x*delta_units.x + delta_units.y*delta_units.y + delta_units.z*delta_units.z);
long master_steps = 0;
//find dominant axis.
if (delta_steps.x > delta_steps.y)
{
if (delta_steps.z > delta_steps.x)
master_steps = delta_steps.z;
else
master_steps = delta_steps.x;
}
else
{
if (delta_steps.z > delta_steps.y)
master_steps = delta_steps.z;
else
master_steps = delta_steps.y;
}
//calculate delay between steps in microseconds. sort of tricky, not bad.
//the formula has been condensed save space. here in english:
// distance / feedrate * 60000000.0 = move duration in microseconds
// move duration / master_steps = time between steps master axis.
return ((distance * 600000000.0) / feedrate) / master_steps;
}
long getmaxspeed()
{
if (delta_steps.z > 0)
return calculate_feedrate_delay(fast_z_feedrate);
else
return calculate_feedrate_delay(fast_xy_feedrate);
}
void disable_steppers()
{
//enable our steppers
digitalwrite(x_enable_pin, low);
digitalwrite(y_enable_pin, low);
digitalwrite(z_enable_pin, low);
}
when gave own folder able load ide when tried compile got lot of
'xxx not declared in scope.'
i started declare them there many wondering if intentional , used in other way?
has had experience these programs , can me way of sending grbl shield can build from.
i can open txt reader, build program , load gcode sender long winded.
Arduino Forum > Using Arduino > Programming Questions > Can anyone help me get a couple of stepper motors to run from this shield?
arduino
Comments
Post a Comment