command M03 M05 not working

Shop Forum Makelangelo Polargraph Art Robot command M03 M05 not working

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #5954
    Anonymous
    Inactive

    hi everybody,
    I’m trying to implement the M03-05 command in gcodecncdemo2axesv1 since yesterday to drive a led and after a diode laser

    in linux console with


    echo -n "M03;" > /dev/ttyACM0
    echo -n "M05;" > /dev/ttyACM0

    it works, but with

    echo -n "G21; " > /dev/ttyACM0
    echo -n "G90; " > /dev/ttyACM0
    echo -n "G92; " > /dev/ttyACM0
    echo -n "G01 X25 Y56;" > /dev/ttyACM0
    echo -n "M03; " > /dev/ttyACM0
    echo -n "G01 X26 Y56 F200;" > /dev/ttyACM0
    echo -n "M05; " > /dev/ttyACM0
    echo -n "M05; " > /dev/ttyACM0
    echo -n "G01 X28 Y56;" > /dev/ttyACM0
    echo -n "M03; " > /dev/ttyACM0
    echo -n "G01 X28 Y56;" > /dev/ttyACM0
    echo -n "M05; " > /dev/ttyACM0
    echo -n "M05; " > /dev/ttyACM0

    the led is HIGH always, I must rewrite the last M05 command to turn off the led
    if you have an idea, it will be fine
    thank’s
    my pde

    #define VERSION        (1)  // firmware version
    #define BAUD (57600) // How fast is the Arduino talking?
    #define MAX_BUF (64) // What is the longest message Arduino can store?
    #define STEPS_PER_TURN (400) // depends on your stepper motor. most are 200.
    #define MIN_STEP_DELAY (50.0)
    #define MAX_FEEDRATE (1000000.0/MIN_STEP_DELAY)
    #define MIN_FEEDRATE (0.01)


    //
    // INCLUDES
    //
    #include


    //
    // GLOBALS
    //
    // Initialize Adafruit stepper controller
    static AF_Stepper m1((int)STEPS_PER_TURN, 1);
    static AF_Stepper m2((int)STEPS_PER_TURN, 2);

    #define laser 10

    char buffer[MAX_BUF]; // where we store the message until we get a ';'
    int sofar; // how much is in the buffer

    float px, py; // location

    // speeds
    float fr=0; // human version
    long step_delay; // machine version

    // settings
    char mode_abs=1; // absolute mode?


    //
    // METHODS
    //


    /**
    * delay for the appropriate number of microseconds
    * @input ms how many milliseconds to wait
    */
    void pause(long ms) {
    delay(ms/1000);
    delayMicroseconds(ms%1000); // delayMicroseconds doesn't work for values > ~16k.
    }


    /**
    * Set the feedrate (speed motors will move)
    * @input nfr the new speed in steps/second
    */
    void feedrate(float nfr) {
    if(fr==nfr) return; // same as last time? quit now.

    if(nfr>MAX_FEEDRATE || nfr Serial.print(F("New feedrate must be greater than "));
    Serial.print(MIN_FEEDRATE);
    Serial.print(F("steps/s and less than "));
    Serial.print(MAX_FEEDRATE);
    Serial.println(F("steps/s."));
    return;
    }
    step_delay = 1000000.0/nfr;
    fr=nfr;
    }


    /**
    * Set the logical position
    * @input npx new position x
    * @input npy new position y
    */
    void position(float npx,float npy) {
    // here is a good place to add sanity tests
    px=npx;
    py=npy;
    }


    /**
    * Uses bresenham's line algorithm to move both motors
    * @input newx the destination x position
    * @input newy the destination y position
    **/
    void line(float newx,float newy) {
    long dx=newx-px;
    long dy=newy-py;
    int dirx=dx>0?1:-1;
    int diry=dy>0?-1:1; // because the motors are mounted in opposite directions
    dx=abs(dx);
    dy=abs(dy);

    long i;
    long over=0;

    if(dx>dy) {
    for(i=0;i m1.onestep(dirx);
    over+=dy;
    if(over>=dx) {
    over-=dx;
    m2.onestep(diry);
    }
    pause(step_delay);
    }
    } else {
    for(i=0;i m2.onestep(diry);
    over+=dx;
    if(over>=dy) {
    over-=dy;
    m1.onestep(dirx);
    }
    pause(step_delay);
    }
    }

    px=newx;
    py=newy;
    }


    /**
    * Look for character /code/ in the buffer and read the float that immediately follows it.
    * @return the value found. If nothing is found, /val/ is returned.
    * @input code the character to look for.
    * @input val the return value if /code/ is not found.
    **/
    float parsenumber(char code,float val) {
    char *ptr=buffer;
    while(ptr && *ptr && ptr if(*ptr==code) {
    return atof(ptr+1);
    }
    ptr=strchr(ptr,' ')+1;
    }
    return val;
    }






    /**
    * write a string followed by a float to the serial line. Convenient for debugging.
    * @input code the string.
    * @input val the float.
    */
    void output(char *code,float val) {
    Serial.print(code);
    Serial.println(val);
    }


    /**
    * print the current position, feedrate, and absolute mode.
    */
    void where() {
    output("X",px);
    output("Y",py);
    output("F",fr);
    Serial.println(mode_abs?"ABS":"REL");
    }


    /**
    * display helpful information
    */
    void help() {
    Serial.print(F("GcodeCNCDemo2AxisV1 "));
    Serial.println(VERSION);
    Serial.println(F("Commands:"));
    Serial.println(F("G00 [X(steps)] [Y(steps)] [F(feedrate)]; - linear move"));
    Serial.println(F("G01 [X(steps)] [Y(steps)] [F(feedrate)]; - linear move"));
    Serial.println(F("G04 P[seconds]; - delay"));
    Serial.println(F("G90; - absolute mode"));
    Serial.println(F("G91; - relative mode"));
    Serial.println(F("G92 [X(steps)] [Y(steps)]; - change logical position"));
    Serial.println(F("M18; - disable motors"));
    Serial.println(F("M03; - laser ON"));
    Serial.println(F("M05; - laser OFF"));

    Serial.println(F("M100; - this help message"));
    Serial.println(F("M114; - report position and feedrate"));
    }


    /**
    * Read the input buffer and find any recognized commands. One G or M command per line.
    */
    void processCommand() {
    int cmd = parsenumber('G',-1);
    switch(cmd) {
    case 0: // move linear
    case 1: // move linear
    feedrate(parsenumber('F',fr));
    line( parsenumber('X',(mode_abs?px:0)) + (mode_abs?0:px),
    parsenumber('Y',(mode_abs?py:0)) + (mode_abs?0:py) );
    break;
    case 4: pause(parsenumber('P',0)*1000); break; // dwell
    case 90: mode_abs=1; break; // absolute mode
    case 91: mode_abs=0; break; // relative mode
    case 92: // set logical position
    position( parsenumber('X',0),
    parsenumber('Y',0) );
    break;
    default: break;
    }

    cmd = parsenumber('M',-1);
    switch(cmd) {
    case 18: // disable motors
    m1.release();
    m2.release();
    break;
    case 100: help(); break;
    case 114: where(); break;
    case 3: digitalWrite(laser, HIGH); break;
    case 5: digitalWrite(laser, LOW); break;

    default: break;
    }
    }


    /**
    * prepares the input buffer to receive a new message and tells the serial connected device it is ready for more.
    */
    void ready() {
    sofar=0; // clear input buffer
    Serial.print(F(">")); // signal ready to receive input
    }


    /**
    * First thing this machine does on startup. Runs only once.
    */
    void setup() {
    Serial.begin(BAUD); // open coms
    pinMode(laser, OUTPUT);
    digitalWrite(laser, LOW);
    help(); // say hello
    position(0,0); // set staring position
    feedrate((MAX_FEEDRATE + MIN_FEEDRATE)/2); // set default speed
    ready();
    }


    /**
    * After setup() this machine will repeat loop() forever.
    */
    void loop() {
    // listen for serial commands
    while(Serial.available() > 0) { // if something is available
    char c=Serial.read(); // get it
    Serial.print(c); // repeat it back so I know you got the message
    if(sofar if(buffer[sofar-1]==';') break; // entire message received
    }

    if(sofar>0 && buffer[sofar-1]==';') {
    // we got a message and it ends with a semicolon
    buffer[sofar]=0; // end the buffer so string functions work right
    Serial.print(F("rn")); // echo a return character for humans
    processCommand(); // do something with the command
    ready();
    }
    }
    #6440
    Anonymous
    Inactive

    The only thing I can think of is that you put case 3 and 5 after case 114. Maybe the arduino compiler is picky and wants them to be 3,5,18, etc…?

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.