Back to the home page
›Project · Sebis Serial Interpreter

G-code for your own devices

An Arduino library that reads commands like «G1 X40 Y10» from the serial port and calls your own function for each code. Control plotters, scanners or robots from your computer - with commands much like those of a 3D printer.

  • Arduino
  • C++
  • MIT licence
  • Free
Arduino · serial monitor
01How it works

In three steps

  1. 1

    Add the library

    Download the ZIP and add it in the Arduino IDE via «Sketch › Include Library › Add .ZIP Library».

  2. 2

    Register functions

    One function per code: «X» calls setX, «M» calls setM - with the number that follows.

  3. 3

    Send commands

    From the serial monitor or your own program, one command per line, ending with a line break.

02Who it is for

Who benefits

Makers

Control plotters, camera sliders or a robot arm with simple text commands.

Schools and training

Show how machines understand commands - a small, readable example for technology lessons.

Prototypes and test rigs

Drive a setup from your computer without inventing your own protocol.

3D printing and CNC

Use familiar G-code commands on your own hardware and add codes of your own.

03What it does

Everything at a glance

Your own codes
G, X, M or a code of your own like MGC: each code calls the function you register for it - with the number that follows, decimals included.
Line by line
Optionally, a final function runs at the end of each line: collect all values of a line first, then perform the move.
Flexible
Any serial port, including SoftwareSerial, any baud rate. Functions can be added and removed at runtime; reading either waits for commands or runs alongside in loop().
With examples
A simple example and a small G-code interpreter show you how to get started.
What it looks like in a sketch
#include <SebisSerialInterpreter.h>

SebisSerialInterpreter ssi(&Serial);
FunctionList fx;

void setX(String code, double value) {
  Serial.println(value);   // e.g. move motor X here
}

void lineDone() { }        // runs at the end of each line

void setup() {
  Serial.begin(115200);
  fx = ssi.createFunctionList("X", &setX);
  ssi.addFunctionList(&fx);
  ssi.setFinalFunction(&lineDone);   // optional
}

void loop() {
  ssi.serialRead(false, false);   // non-blocking read
}

Frequently asked questions

What is G-code?

A simple command language for machines: letters followed by numbers give commands and values. «G1 X40 Y10», for example, means: move to X 40, Y 10. 3D printers and CNC mills work this way.

Do I have to use G-code?

No. The library recognises any code made of letters followed by a number. You decide what each code means.

Which boards are supported?

The library is listed for all Arduino architectures and reads from any serial port, such as Serial, Serial1 or SoftwareSerial.

Why does nothing happen after my command?

Every line has to end with a line break. In the serial monitor, choose «Newline».

May I use the library in my own projects?

Yes, commercial projects included. It is released under the MIT licence.

Try Sebis Serial Interpreter

Arduino library: commands like G1 X40 Y10 call your own functions.

›View on GitHub
04More projects

More from giit.ch

giit Editors

LaTeX, Markdown, SVG, CSV, QR codes and more in the browser - code on the left, result on the right.

Advanced Ctrl+F

Search many documents at once - PDF, Word, Excel and more, with text recognition.

LearningApps

Short exercises for maths and German, with instant feedback.

Fixed-price website

Put together what you need in about 15 minutes - the website itself is individually programmed.