SOLVED: Transfering huge text file to Arduino line by line

I want to transfer a GCODE file from computer to Arduino to have Arduino perform some plotting. The Arduino should read one line at a time and perform the line, whether it takes one second or three minutes, then read the next line. Then it would read the next line. The file is way too big to be read once into a buffer.

As I see it, the hardware is there. My computer (Windows 10) can perfectly well send serial data via the USB cable to Arduino. I’d like to use any system I already have. I can send a file using the CMD prompt in Windows. TYPE file.txt > COM3: works, COPY file.txt COM3: works. Only thing that doesn’t work is the computer waiting after each line. It sends everything in one chunk, overflowing or rewriting the 64 byte buffer on and on.

My computer says this:

Status for device COM3:
    Baud:            9600
    Parity:          Even
    Data Bits:       8
    Stop Bits:       1
    Timeout:         OFF
    XON/XOFF:        ON
    CTS handshaking: OFF
    DSR handshaking: OFF
    DSR sensitivity: OFF
    DTR circuit:     ON
    RTS circuit:     ON

I tried this in my Arduino code:

    Serial.write(17); // ctrl-q XON
    inp = "";
      inint =;
      if (inint != -1)
        inchar = char(inint);
        if (inchar != '\n')
          inp += inchar;  // inp is the String object collecting one text line at a time from the transfered file
    while (inchar != '\n');
    Serial.write(19); // ctrl-s XOFF

…to collect one line from the textfile into one string object. But this doesn’t work, does it? The doesn’t read from the computer, does it? It reads from the Arduino buffer already received the data.

Seems the serial input system is set up for reading everything into a buffer and hope for the best. How do I set up everything so that the XON/XOFF (or any similar protocol) really works for pausing the input from the computer after each ‘\n’ separated line? I know I could write my own software for the computer, but I really think the available file transfering methods should work.

The program called Universal Gcode Sender is probably a good off-the-shelf solution. It is what people use with the GRBL program for CNC machines.


The Universal Gcode Sender doesn’t work for me. I can’t seem to find a way of having the Arduino decide the pace of line feeding. I simply want the Arduino to be able to send an XOFF, when it has received one line. And an XOn when it is ready to receive the next line.

Xon and Xoff are not magic. If your Arduino sends and Xoff, it will still receive several characters until the computer has processed the Xoff. What you want to use is the electrical signals RTS and CTS on an RS-232 interface. They are immediate signals.


Seems there's no way of flow control on the Arduino side over the USB. Guess I have to write my own little tool on the PC wich sends one text line at a time, then waits for an ok (or why not ctrl-q) from the Arduino. Shouldn't be hard.

The Universal Gcode Sender doesn't work for me. I can't seem to find a way of having the Arduino decide the pace of line feeding.

AFAIK UGS sends the next line after it receives 'ok'

UGS is designed to work with GRBL and the GRBL wiki has all the information about communicating with GRBL


UGS was way too picky. The version I managed to install on my PC could handle a few protocols, expecting the precise CNC mill to be attached, or at least something that followed the precise handshake.

The software that seems to do the job is gcode-sender, a Chrome extension, which just does what I want. It opens my G-code file, it starts to send the stuff line by line, waits for "ok", then continues. My Arduino gets every line. A bit strange to have to use the Chrome browser for this, but it works.

Though I could have learned the GRBL protocol.

Good to see you have a solution.

I guess I had been thinking of using your program to fool UGS into thinking it was talking to GRBL.