gcode()

Description

Input G-Code to control the Machine.
The G-Code supported by Motion86 are as follows:

Please refer to G-Code Reference Table

G-Code Description
G1 Linear Motion
G2 Clockwise circular motion
G3 Counterclockwise circular motion
G4 Pause command
G17 Select XY plane for circular motion
G18 Select XZ plane for circular motion
G19 Select YZ plane for circular motion
G90 Absolute position mode
G91 Relative position mode
G90.1 Arc center absolute position mode
G91.1 Arc center relative position mode
G92 Coordinate system offset

Syntax

machine.gcode(cmd);

Parameters

machine: for Machine object.

cmd: G-Code string to be sent.

Return

bool:

true: The machine exists and was created successfully.
false: The machine does not exist or creation failed.

Example


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

#include "Motion86.h"

 

// Generate machine objects. Up to three machines, machine 0~2, can be used. Each machine has three axes.

Machine machine(0);

 

// Stepper motor enable pin.

int EnablePin = 4;

 

void setup() {

  while (!Serial);

  pinMode(EnablePin, OUTPUT);

 

  // If necessary, you can reverse the direction of the motion axis.

  // In this example, you need to reverse the direction of the x-axis and y-axis.

  machine.config-ReverseDirection(AXIS-X);

  machine.config-ReverseDirection(AXIS-Y);

 

  // PPU (pulse per unit) is a virtual length unit, depending on different needs.

  // In this example, the unit length of the x-axis is set to 80 pulses, which corresponds to 1 mm in actual application.

  machine.config-PPU(AXIS-X, 80.0);

  machine.config-PPU(AXIS-Y, 80.0);

  machine.config-PPU(AXIS-Z, 1600.0);

 

  // Before controlling, the machine must be started.

  machine.machineOn();

 

  // Start the stepper motor.

  digitalWrite(EnablePin, LOW);

}

 

void loop() {

  // Move left to (-10, 0).

  machine.gcode("G1 X-10 Y0 F400");

 

  // Move 90 degrees clockwise with a radius of 10 to (0, 10).

  machine.gcode(“G2 X0 Y10 R10 F400”);

 

  //The iteration moves to (0, -10).

  machine.gcode(“G1 X0 Y-10 F400”);

 

  //Move 90 degrees counterclockwise to (10, 0) with a radius of 10.

  machine.gcode(“G3 X10 Y0 R10 F400”);

 

  //Move to (0, 0) left.

  machine.gcode(“G1 X0 Y0 F400”);

 

  //Wait until the planned motion is completed.

  while (machine.isMoving());

}

Library Reference

The text of the 86Duino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.