# Introduction

{% hint style="success" %}
3**📅Update: 2020/09/04**
{% endhint %}

DexArm is developed based on the world's leading open-source project [**Marlin**](https://marlinfw.org/meta/gcode/), the DexArm firmware is completely open-source, and its control commands (G-code) are compatible with Marlin. **Please visit** [**GitHub**](https://github.com/Rotrics-Dev) **for more details of our firmware project.**&#x20;

G-code commands are the general control commands for CNC machines, 3D printers, etc. It is composed of ASCII strings, such as `G1 F2000 X0 Y300 Z0`, G-code commands usually uses `\n` as the sending end character.

In Marlin, the slave device will reply `ok` after receiving the G-code commands, the host computer then can send the next commands after receiving the `ok`. In DexArm SDK (pydexarm - download below👇), we have encapsulated this sending and receiving mechanism and make it convenient for users to use.

{% file src="<https://2132465959-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LtPFIBncU5l4J8tl5Yh%2F-MGNlWjNnCS9KULdq5mE%2F-MGNm5YDMZKXsl8gkoEo%2Fpydexarm_V1.0.zip?alt=media&token=d9e312b4-e58e-486e-b6de-2abf73da3d4d>" %}
DexArm Python SDK V1.0
{% endfile %}

## Communication Parameters

* Baud rate: 115200
* Data bits: 8
* Stop bits: 1
* Parity: None
* Flow control: None
* Commands end with CR+LF, hereinafter referred to as 0D0A.
* When the slave device receives a command, if the command is correct, it returns "ok"; if not, it returns "unknown command".

## **Initialization**

After the host computer is connected to the robot arm, please send the command  `M1112`  first to move the arm to the HOME (`X0 Y300 Z0`) position.

## Basic Motion Control Commands

#### M1112

* Reset to the HOME position (X0 Y300 Z0)

{% hint style="info" %}
Don't mix up with the M112 Emergency stop command.&#x20;
{% endhint %}

#### M1111

* Move to the recalibration position

![](https://2132465959-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LtPFIBncU5l4J8tl5Yh-887967055%2Fuploads%2FL8nir3GYGZEsm7Qyoaw2%2Fimage.png?alt=media\&token=c1650e81-ce26-4609-8694-7700a8100c9c)

#### M1113

* Execute M1111 first, then M1112

#### G0 - Rapid Movement

* X - Movement distance of X-axis in mm, accuracy 0.1mm
* Y - Movement distance of Y-axis in mm, accuracy 0.1mm
* Z - Movement distance of Z-axis in mm, accuracy 0.1mm
* E - Movement distance of E-axis in mm, accuracy 0.1mm
* F - Movement speed in mm/s, default speed is 40mm/s

#### G1 - Linear Movement

* X - Movement distance of X-axis in mm, accuracy 0.1mm
* Y - Movement distance of Y-axis in mm, accuracy 0.1mm
* Z - Movement distance of Z-axis in mm, accuracy 0.1mm
* E - Movement distance of E-axis in mm, accuracy 0.1mm
* F - Movement speed in mm/s, default speed is 40mm/s

#### G90 - Absolute Positioning

Under this command, G0 and G1 movement is in absolute mode.&#x20;

For example, the current position is X300 Y0 Z0, sending G0 X310, the Arm moves to X310 Y0 Z0.&#x20;

#### G91 - Relative Positioning

Under this command, G0 and G1 movement is in relative mode.&#x20;

For example, the current position is X300 Y0 Z0, sending G0 X10, the Arm moves to X310 Y0 Z0.&#x20;

#### G92 X0 Y0 Z0 E0&#x20;

Set the current position as the Work Origin

#### G92.1 - Reset G92 Command

For example, if the arm is currently at X300 Y0 Z0 E0, sending G92 X0 Y0 Z0 E0 will set the current position as the Work Origin. Sending M114 to read position, you will get X0 Y0 Z0 E0, the arm is working under the Work Object Coordinate System. Sending G92.1 will reset G92 command, and the arm will reset to the original coordinate system.

#### G4 - Dwell Command

* P500 - dwell for 500ms
* S10 - dwell for 10s

### Return Values

**M2010** - Return firmware version

**M2011** - Return hardware version

**M503** - Return device status info

**M115** - Return Marlin firmware info

**M897** - Whether the arm moved to the target position

**M1004** - Check air pump box status

Air pump

* In - pump in
* Out - pump in
* Neutral - release air
* Off - turn off&#x20;

**M2014** - check the status of the conveyor belt, including moving direction and speed.

* Forward xx mm/s
* Backward xx mm/s
* Stop

**M6** - check the status of laser module&#x20;

* On - the laser is on&#x20;
* Off - the laser is off

**M18** - motor deactivation command. After sending M18, the motor will go into deactivation and can be manually adjusted for recalibration or the teach & Play function.

## Motion Commands

**M114** - return the current position value, in mm. If the rotary module is connected, it also returns the R absolute angle value.&#x20;

**M204** - read and set robot arm moving acceleration value. The default setting is M204 P200 R60 T200.&#x20;

* When it is without any parameters, it reads the acceleration value.&#x20;
* P - printing acceleration value.&#x20;
* R - returning acceleration value.&#x20;
* T - idle stroke acceleration value.&#x20;

**M889** - Read magnet encoder value and set the initial calibration position.&#x20;

* X Y Z - set magnet encoder value of current position for recalibration.

**M890** - get the magnet encoder position readings.&#x20;

**M891**&#x20;

* X Y - set the current XY slope value, usually used in 3D printing leveling.

**M892** - read the current XY slope value

**M893** - refresh the magnet encode value from the sensor

**M894** - set a target value of the magnet encoder

* X - the X-axis encoder value of target position, range&#x20;
* Y - the Y-axis encoder value of target position, range&#x20;
* Z - the Z-axis encoder value of target position, range&#x20;

**M895**&#x20;

* read the magnet encode values from the sensors and then convert it into actual coordinate values, displayed in the Cartesian coordinate system, in mm.&#x20;
* for teach & play function

**M81** - turn off the fan, heating or other functions.

**M410** - stop the arm movement quickly, send G0 and G1 commands to continue the movement.

**M112** - emergency stop command, the arm will not respond to any commands. Need to reboot the arm for more action.&#x20;

## Basic Controls

### Motion Mode

#### M2000

Switch G0 to linear movement.&#x20;

#### M2001

Switch G0 to rapid movement.&#x20;

### **Basic Movement commands**

**G91**: enter relative mode.

**G0 X1**: move +1mm on the X-axis.&#x20;

**G90**: enter absolute mode.

## Front-end Module Switch

### M888

**P0 -** set the front-end module as the pen holder module

**P1** - set the front-end module as the laser module

**P2** - set the front-end module as the pneumatic module

**P3** - set the front-end module as the 3D printing module

**P4** - set the front-end module as the rotary module

**P10** - turn on the safety enclosure laser protection

**P11** - turn off the safety enclosure laser protection

**P13** - check safety enclosure door status

No Parameter/send M880 directly - check the current module

{% hint style="info" %}
Each time when you enter a module function interface, you need to send the module setting command.&#x20;
{% endhint %}

## Writing/Drawing

#### Process of G-Code files:&#x20;

1. send by code line, each line ends with 0D0A
2. only sending the next code when it receives the "ok" return value from the server
3. the code line starting with";" will be automatically filtered by the host computer, and will not be sent to the server
4. Pause/Resume, corresponding to pause or continue sending commands in the host computer.

## Laser Module

**M3** - command to turn on laser

#### Parameters

1. S corresponds to the laser power duty cycle, the range is 0-255. <mark style="color:red;">Special definition</mark>: when it is S1, the laser power is very low, suitable for laser engraving borders.
2. Example: M3 S10 - turn on the laser with a duty cycle of 10.&#x20;

**M5** - Turn off the laser module.

**M6** - Return to laser on/off status.&#x20;

## Pneumatic Module

**M1000** - air pump box pump in/soft grip start gripping

**M1001** - air pump box pump out/soft grip start opening&#x20;

**M1002** - air pump box/soft grip return to original status

**M1003** - all air pump boxes stop working&#x20;

## Teach & Play

* Teach: Send M893, the arm returns M894 + the magnet encoder value of 3-axises, the software or touch screen saves the corresponding data.
* Replay: Resend the saved information and the arm will repeat the previously recorded movement.

## 3D Printing

**M104 Sxx** - set the extrusion head temperature, during which the motion command is possible.&#x20;

* Sxx - target temperature, accuracy 1°C
* Example: M104 S200 - Set the extrusion head target temperature to 200°C.

**M105** - get the current extrusion head temperature

**M108** - get the extruder speed

**M109 Sxx** - Set the extruder target temperature xx and wait for the temperature to rise. No command will be executed during this period. The server unit will return the current temperature in real-time.&#x20;

Sxx - target temperature, precision 1°C&#x20;

Example: M109 S200 - Sets the extrusion head target temperature to 200°C and wait for the temperature to rise.

**M106 Sxx** - Set fan speed xx

**M107** - turn off the fan

**M130** - Set heater bar PID P value

**M131** - Set the heater bar PID I value

**M132** - Set heater bar PID D value

**G0 EXXX FXXX** - Extrude E length at F speed

## Conveyor Belt&#x20;

**M2012** - control the rotation of the conveyor belt

* Parameters: F speed (in mm/min), D direction (0 is clockwise, 1 is counterclockwise)
* For example:
  * M2012 F1000 D0 - rotate clockwise in 1000mm/min speed.
  * M2012 F200 D1 - rotate counterclockwise in 200mm/min speed.

**M2013** - stop the conveyor belt

**M2014** - check the status of the conveyor belt

**M1115 - M1119** - return the color recognition sensor data. For the scratch color recognition function and other demos. Parameters:

* 1115: item - means there is an item.&#x20;
* 1116: red - indicates a red block.&#x20;
* 1117: green - indicates a red block.&#x20;
* 1118: blue - indicates a blue block.&#x20;
* 1119: yellow - Indicates a yello block.

## Sliding Rail&#x20;

**M2005** - E axis return to the home point. With the locked rotor test function of TMC2209, it drives the slide back to the home point twice, when the TMC is pushed to the limit, the slide is returned to the home point successfully.&#x20;

* Parameters: XYZE must be fully set, otherwise use the default values (30, 10, 60, 60).
  * X - HOME maximum speed
  * Y - HOME lowest speed
  * Z - the 1st TMC detection threshold value
  * E - the 2nd TMC detection threshold value

**M2006 -** check if the return operation is completed.&#x20;

**M914** - set the sensitivity of TMC blocking for the E-axis.

## Rotary Module

**M888 P6** - set the offset value and initialize the rotary module

**M2100** - initialize the rotary module

**M2101** - get the rotary module angle value, control the movement, with 1-degree accuracy. Parameters:

* Without parameters: get the absolute angle of the rotary module.
* R(relative) - rotate the module by n degrees from the current position, n can be greater than 360.
  1. Clockwise rotation n degrees, M2101 Rn&#x20;
  2. Counterclockwise rotation n degrees, M2101 R-n
* P(position) - rotates the rotary joint to an absolute angle n.&#x20;
  1. **M2101 Pn** - rotate the module to an absolute angle n, the range of n is 0 - 360.
* S - set the module rotates continuously, speed range from 0-100. S0 refers to speed zero(stop). S1 refers to rotation at a low speed, S100 refers to rotation at the highest speed.
  * clockwise rotation continuously, M2101 Sn&#x20;
  * counterclockwise rotation continuously, M2101 S-n&#x20;

**M2102** - Upgrade the firmware of the rotary module

Parameter U - Upgrade step number, default is 0.&#x20;

* 0 - no operation
* 1 - enter boot&#x20;
* 2 - set the file size with the s parameter
* 3 - receive the file

**M2103** - check the current rotary module firmware version

* For example, M2103, return Rotary Firmware V1.1.2

## Firmware Upgrade

**M2002** - enter Bootloader

**M2003** - confirm the upgrade, enter Bootloader

* Once enter Bootloader, send numbers 1-5 to view device data, send firmware, etc.&#x20;
  * 1 - download firmware to the robot arm&#x20;
  * 2 - upload firmware from the robot arm&#x20;
  * 3 - execute firmware&#x20;
  * 4 - enter boot protection mode, no firmware transfer&#x20;
  * 5 - print the device firmware and hardware version data.&#x20;

**M2004** - Cancel upgrade

**M2007** - Reboot the device.

## Error Report

**ERROR 100-199**, motion and initialization related, such as M1112

**ERROR 200-299**, motion and initialization related, 3D printing related, such as heating, temperature, etc.

**Error:100**, Position Sensor Read Error&#x20;

* Position sensor error&#x20;
* Exceed the sensor reading maximum range, such as 65535&#x20;
* Possible causes: usually 8Pin wire loose, off, or magnetic code board damage

**Error:103**, Position Sensor Diff Error&#x20;

* M1112 M1111 sensor DIFF exceeds the maximum angle range&#x20;
* Possible causes: calibration error, magnet off

**Error: 101, 102** Home Error&#x20;

* Home Error (Axis data).&#x20;
* Possible causes: wrong magnet, magnet off, motor wire loose, motion out of step, etc.

**Error: 203**, MINTEMP triggered, system stopped! Heater\_ID: 0

* When the heating is turned on, the minimum temperature is triggered, usually, the temperature sensor is not inserted, or the temperature sensor is disconnected.

**Error: 202**, MAXTEMP triggered, system stopped! Heater\_ID: 0

* the maximum temperature is triggered, usually caused by a broken temperature sensor.

**Error:200**, Heating failed, system stopped! Heater\_ID: 0

* No significant temperature change (<2°C) after a certain heating time (20S)

**Error: 201**, Thermal Runaway, system stopped! Heater\_ID: 0

* After heating up to the specified temperature, the temperature drops significantly.

## Leveling related commands

### Set leveling coefficient

`M891 Xn Yn`

### Read leveling coefficient

`M891`

## Magnet encoder related commands

### Read current encoder position data

`M893`

### Move to a specific encoder value position

`M894 Xn Yn Zn`

## End effector control commands

### **Pneumatic module control commands**

* M1000 - air pump box to pump in
* M1001 - air pump box to pump out
* M1002 - air pump box to release air
  * To return to original status when the suction cup/soft gripper is not working.
* M1003 - stop air pump box

### **Laser engraving module control commands**

Related control commands [`M003`](https://manual.rotrics.com/gcode/marlin-original-commands/marlin-m003-laser-on) [`M005`](https://manual.rotrics.com/gcode/marlin-original-commands/marlin-m005-laser-off)&#x20;

### 3D printing control commands

* [`M104`](https://manual.rotrics.com/gcode/marlin-original-commands/marlin-m104-set-hotend-temperature)
* [`M105`](https://manual.rotrics.com/gcode/marlin-original-commands/marlin-m105-report-temperatures)
* [`M108`](https://manual.rotrics.com/gcode/marlin-original-commands/marlin-m108-break-and-continue)
* [`M106`](https://manual.rotrics.com/gcode/marlin-original-commands/marlin-m106-set-fan-speed)
* [`M107`](https://manual.rotrics.com/gcode/marlin-original-commands/marlin-m107-fan-off)
* [`M109` ](https://manual.rotrics.com/gcode/marlin-original-commands/marlin-m109-wait-for-hotend-temperature)

### Accessory control commands

#### Conveyor belt control commands

set conveyor belt working speed as 2000mm/min, clockwise

`M2012 F2000 D0`

set conveyor belt working speed as 2000mm/min, counter-clockwise

`M2012 F2000 D1`

stop conveyor belt

`M2013`

#### Reset the touchscreen firmware

Connect the touchscreen to DexArm after sending the following commands:

`M5010000`

## Reset DexArm Settings

## Reboot DexArm and enter bootloader

Send commands `M2002`, `M2003` in sequence to enter bootloader mode.

## Reboot DexArm commands

`M2007`

## **Re-calibrate the initial position**

The DexArm HOME position and motion coordinates are based on the initial position. The initial position has been calibrated before leaving the factory. If there is an error in the arm movement, please re-calibrate the initial p~~o~~sition according to the following instruction:

1\. Adjust the arm to the following position, make sure Axis 1 and Axis 2 is in the maximum position:

![](https://2132465959-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LtPFIBncU5l4J8tl5Yh%2F-MGDY7EyLVNGTgs8ApSb%2F-MGDZGQNkqLgKHmKU-a6%2Fimage.png?alt=media\&token=7b8236b8-6755-4b48-a5f7-2e88bb376a86)

2\. Send command `M889`

## Advanced commands

{% content-ref url="marlin-original-commands/marlin-g020-inch-units" %}
[marlin-g020-inch-units](https://manual.rotrics.com/gcode/marlin-original-commands/marlin-g020-inch-units)
{% endcontent-ref %}

{% content-ref url="marlin-original-commands/marlin-g021-millimeter-units" %}
[marlin-g021-millimeter-units](https://manual.rotrics.com/gcode/marlin-original-commands/marlin-g021-millimeter-units)
{% endcontent-ref %}

{% content-ref url="marlin-original-commands/marlin-m906-dwell" %}
[marlin-m906-dwell](https://manual.rotrics.com/gcode/marlin-original-commands/marlin-m906-dwell)
{% endcontent-ref %}

{% content-ref url="marlin-original-commands/marlin-m500-save-settings" %}
[marlin-m500-save-settings](https://manual.rotrics.com/gcode/marlin-original-commands/marlin-m500-save-settings)
{% endcontent-ref %}

{% content-ref url="marlin-original-commands/marlin-m501-restore-settings" %}
[marlin-m501-restore-settings](https://manual.rotrics.com/gcode/marlin-original-commands/marlin-m501-restore-settings)
{% endcontent-ref %}

{% content-ref url="marlin-original-commands/marlin-m502-factory-reset" %}
[marlin-m502-factory-reset](https://manual.rotrics.com/gcode/marlin-original-commands/marlin-m502-factory-reset)
{% endcontent-ref %}

{% content-ref url="marlin-original-commands/marlin-m503-report-settings" %}
[marlin-m503-report-settings](https://manual.rotrics.com/gcode/marlin-original-commands/marlin-m503-report-settings)
{% endcontent-ref %}

{% content-ref url="marlin-original-commands/marlin-m082-e-absolute" %}
[marlin-m082-e-absolute](https://manual.rotrics.com/gcode/marlin-original-commands/marlin-m082-e-absolute)
{% endcontent-ref %}

{% content-ref url="marlin-original-commands/marlin-m083-e-relative" %}
[marlin-m083-e-relative](https://manual.rotrics.com/gcode/marlin-original-commands/marlin-m083-e-relative)
{% endcontent-ref %}

{% content-ref url="marlin-original-commands/marlin-m092-set-axis-steps-per-unit" %}
[marlin-m092-set-axis-steps-per-unit](https://manual.rotrics.com/gcode/marlin-original-commands/marlin-m092-set-axis-steps-per-unit)
{% endcontent-ref %}

{% content-ref url="marlin-original-commands/marlin-m200-set-filament-diameter" %}
[marlin-m200-set-filament-diameter](https://manual.rotrics.com/gcode/marlin-original-commands/marlin-m200-set-filament-diameter)
{% endcontent-ref %}

{% content-ref url="marlin-original-commands/marlin-m400-finish-moves" %}
[marlin-m400-finish-moves](https://manual.rotrics.com/gcode/marlin-original-commands/marlin-m400-finish-moves)
{% endcontent-ref %}

{% content-ref url="marlin-original-commands/marlin-m410-quickstop" %}
[marlin-m410-quickstop](https://manual.rotrics.com/gcode/marlin-original-commands/marlin-m410-quickstop)
{% endcontent-ref %}

{% content-ref url="marlin-original-commands/marlin-m504-validate-eeprom-contents" %}
[marlin-m504-validate-eeprom-contents](https://manual.rotrics.com/gcode/marlin-original-commands/marlin-m504-validate-eeprom-contents)
{% endcontent-ref %}
