terjeio / GRBL_MPG_DRO_BoosterPack

Tiva C BoosterPack for GRBL MPG/DRO
43 stars 20 forks source link

Congratulations!, great job! #1

Open luisluna2 opened 5 years ago

luisluna2 commented 5 years ago

Hello friend just now I¿'m working in a similar project, but I wenna usa a SD card but not have success with this.

I make a code with LCD 1602 I2C and now the machine can move but the problem is how send data from SD CARD, have some about this?

terjeio commented 5 years ago

Thanks,

Funny you should mention SD card now, I just looked into how to hook code for streaming data from a SD card into my grbl port a few hours ago. So far I just added the hook, no code yet for interacting with the card.

I have also added added code (not yet published) for streaming GCode via ethernet to the driver for the EK-TM4C1294XL LaunchPad, this ment that I had to run grbl as a FreeRTOS task - in a similar vein as the ESP32 port found here. The ESP32 port support for streaming from a SD card, maybe that implementation can give you some ideas?

Do you use a second microcontroller for your solution too?

terjeio commented 5 years ago

I've just tested adding "quick and dirty" dummy SD card support to my HAL port of Grbl, seems to work ok. A real SD card driver must be used instead of the dummy used below, also error handling should be added. There are no changes to the core Grbl code, only a call to sdcard_init() in the driver initialisation function is required. The same commands as used in the ESP32 port is implemented.

Be aware that my HAL port does not support 8-bit processors!

/*
  sdcard.c - An embedded CNC Controller with rs274/ngc (g-code) support

  ...

  Part of Grbl

  Copyright (c) 2018 Terje Io

  Grbl is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  Grbl is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with Grbl.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "GRBL/grbl.h"

int16_t (*readfn)(void)  = NULL;

/* dummy filesystem */

uint32_t fp = 0;
char *filedata = "G1X100Y11F30\rG0X0\r";

bool file_mount (void)
{
    hal.serial_write_string("mounted SD card\r\n");
    return true;
}

bool file_list (void)
{
    hal.serial_write_string("a list of filenames\r\n");
    return true;
}

bool file_open (char *filename)
{
    hal.serial_write_string("run filename:");
    hal.serial_write_string(filename);
    hal.serial_write_string("\r\n");

    return true;
}

void file_close (void)
{

}

int16_t file_read (void)
{
    char c = filedata[fp++];
    return c == 0 ? -1 : (int16_t)c;
}

/* end dummy filesystem */

int16_t sdcard_read (void)
{
    int16_t c;

    if(!(sys.state == STATE_IDLE || (sys.state & STATE_CYCLE|STATE_HOLD)))
        c = - 1;
    else
        c = file_read();

    if(c == -1) { // EOF
        file_close();
        hal.serial_read = readfn;
        hal.userdefined_rt_report = NULL;
        sys.block_input_stream = false;
    }

    return c;
}

void sdcard_report (void)
{
    hal.serial_write_string("|SD:50.2");
}

status_code_t sdcard_parse (uint_fast16_t state, char *line)
{
    status_code_t retval = Status_Unhandled;

    if(line[1] == 'F') switch(line[2]) {

        case '\0':
            file_list();
            retval = Status_OK;
            break;

        case 'M':
            file_mount();
            retval = Status_OK;
            break;

        case '=': 
            if (state != STATE_IDLE)
                retval = Status_SystemGClock;
            else {
                if(file_open(&line[3])) {
                    fp = 0;
                    readfn = hal.serial_read;                   // save serial read fn handle
                    hal.serial_read = sdcard_read;              // and redirect to read from SD card instead
                    hal.userdefined_rt_report = sdcard_report;  // add percent complete to real time report
                    sys.block_input_stream = true;              // block serial input other than real time commands
                    retval = Status_OK;
                } else
                    retval = Status_InvalidStatement;
            }
            break;

        default:
            retval = Status_InvalidStatement;
            break;
    }

    return retval;
}

void sdcard_init (void)
{
    hal.userdefined_sys_command_execute = sdcard_parse;
}
luisluna2 commented 5 years ago

wow! good job!, could send some picture for undertand more?, sorry I'm new in Arduino hehe

luisluna2 commented 5 years ago

I' using 1602 IC2 LCD, a IR CONTROL, ARDUINO UNO and I wanna use SD OR MICRO SD MODULE, all is work with movements, but I'm lost in the read SD CARD haha here a Picture:

Next steps: 1.- ADD SD SENDER 2.- ADD 4x4 MATRIX (for this I think change UNO for MEGA)

image

terjeio commented 5 years ago

@luisluna2 I have added some details about my setup to the readme that may be helpful. Implementing the setup you describe on a single microprocessor is IMO not going to be easy, the Arduino Nano surely does not have enough free resources for that. Perhaps the way forward will be to use your Mega as the Grbl controller, this with my patched version, and implement the DRO/MPG and SD card support on the Nano?

I do not work with Arduino controllers, my expertise is with TIs 16 bit controllers and ARM processors, so I can not offer much help for Arduinos. Maybe switching to the ESP32 I mentioned above is a better choice for your ambitions, but it still needs a second processor for some parts (such as keyboard input) as it has limited IO resources. Or you could adapt this project if you feel so inclined...