Printer Command Set

From Cartesian Co. Wiki
Jump to: navigation, search

Rapid prototyping hardware such as 3D printers and CNC routers often interpret G-code instructions. G-code is well suited to multi-tool vector based plotting, which printing a circuit is not. A communication protocol has been specifically designed for the Argentum which should be easy for the hobbyist community to experiment with.

Each command has a byte-code identifier and zero or more parameters that include unsigned and signed 8, 16, and 32 bit integers; null terminated arrays; and arrays of a length defined by a preceding integer parameter. The command name, e.g. getPosition, is used in the AgInterface Python controller and the command handler functions in the firmware. When extending the command set or implementing a serial controller or file writer, keep in mind the following:

  • The commands are byte-packed (for computers to read). As in, the numbers are signed or unsigned integers of a particular byte-size. In contrast, G-code uses string representations of numbers (for humans to read). Unfortunately, this means it is not easy to write commands manually.
  • Ideally, commands that "set" information or make the printer perform a function have uppercase ASCII byte-code identifiers, and commands that "get" information have lowercase. This is not a requirement, and eventually the human readable ASCII characters may run out.
  • The AVR microcontroller is little-endian, so be careful if you're using some exotic controller hardware.

The Argentum Printer can read commands from the serial interface or files on an SD card. When reading from a file, the responses are ignored. See Printer Command Set Table for a table of command byte-code mappings.

Command Set Functions

Position and movement

getPosition

Command: 'p'

Response: xpos: int16, ypos: int16

Get the current head position in steps, relative to the zero-point.

goToPosition

Command: 'P', xpos: int16, ypos: int16

Response: status: uint8

Move the head to step position (xpos, ypos), relative to the zero-point.

Response status is one of:

  • MOTION_COMPLETE - when the head has reached the target destination.
  • AXIS_X_POSITIVE - if the head has hit the X+ endstop.
  • AXIS_X_NEGATIVE - if the head has hit the X- endstop.
  • AXIS_Y_POSITIVE - if the head has hit the Y+ endstop.
  • AXIS_Y_NEGATIVE - if the head has hit the Y- endstop.

incrementPosition

Command: 'I', dx: int16, dy: int16

Response: status: uint8

Move the head by dx steps horizontally and dy steps vertically.

Response status is one of:

  • MOTION_COMPLETE - when the head has reached the target destination.
  • AXIS_X_POSITIVE - if the head has hit the X+ endstop.
  • AXIS_X_NEGATIVE - if the head has hit the X- endstop.
  • AXIS_Y_POSITIVE - if the head has hit the Y+ endstop.
  • AXIS_Y_NEGATIVE - if the head has hit the Y- endstop.

zeroPosition

Command: 'Z'

Response: none

Zero the head position Makes the current position be location (0, 0).

home

Command: 'H', axis: uint8

Response: MOTION_COMPLETE

Moves the head until the desired endstop is reached. The axis and direction is determined by the axis parameter, which can be one of:

  • AXIS_X_POSITIVE - the positive X axis.
  • AXIS_X_NEGATIVE - the negative X axis.
  • AXIS_Y_POSITIVE - the positive Y axis.
  • AXIS_Y_NEGATIVE - the negative Y axis.

This also serves as an automatic motor direction calibration. For example, if the motor is homed to the positive X axis, but travels in the X- direction until the the X- endstop is hit, the firmware will change MOTOR_FLIP_X (see getConfig and setConfig commands).

Cartridge

testFire

Command: 'T', cartridge: uint8, count: uint8

Response: none

Fire all of cartridge's nozzles by iterating over address signals count times. The cartridge parameter is the bitwise OR of the cartridge constants, e.g. CARTRIDGE_0, CARTRIDGE_1, and CARTRIDGE_2.

fire

Command: 'F', cartridge: uint8, nozzle: uint8, count: uint8

Response: none

Fire the nozzle number of cartridge number cartridge a total of count times.

printRow

Command: 'R', cartridge: uint8, numDots: uint16, data: uint8[]

Response: none

Burst mode firing. Print numDots dots at the set dots/mm resolution (see getConfig and setConfig commands with DOTS_PER_MM_X parameter) in the X-axis. The total distance travelled will be the config-value(DOTS_PER_MM_X) × numDots steps. The firing information is in the data array, which is of length num-set-bits(cartridge) × numDots × 13 bytes. Each byte represents primitive signal values. The format is ordered first by dot position, then by cartridge number as it appears from least-significant bit to most significant, and then by address from 1 to 13.

For example, for cartridge 0b11 and stepsPerDot of 100, the bytes would be ordered: [ dot0-cartridge1-address1, dot0-cartridge1-address2, ..., dot0-cartridge1-address13, dot0-cartridge2-address0, dot0-cartridge2-address0, ..., dot99-cartridge2-address13 ]

Configuration

setConfig

Command: 'C', field: uint16, value: uint32

Response: none

Set the calibration of field to value. The value is persistent over power cycles as it is stored in EEPROM. The field may be one of the following constants:

  • STEPS_PER_MM_X - steps per millimetre in the X axis (uint32)
  • STEPS_PER_MM_Y - steps per millimetre in the Y axis (uint32)
  • MM_PER_SECOND_X - millimetres per second in the X axis (uint32)
  • MM_PER_SECOND_Y - millimetres per second in the Y axis (uint32)
  • DOTS_PER_MM_X - dots per millimetre in the X axis (uint32)
  • DOTS_PER_MM_Y - dots per millimetre in the Y axis (uint32)
  • MOTOR_FLIP_X - flip the X motor direction from the default (for if the motor connections are reversed) - non-zero value for true, 0x00 for false (uint32).
  • MOTOR_FLIP_Y - flip the Y motor direction from the default (for if the motor connections are reversed) - non-zero value for true, 0x00 for false (uint32).

The value parameter may be another datatype packed into the 4-byte uint32 (e.g. an int32, two int16s) depending on the field - check the field description for any value that deviates from uint32.

getConfig

Command: 'c', field: uint16

Response: value: uint32

Get the configuration value of field. See setCalibration for the list of valid field constants and value types.

getVersion

Command: 'v'

Response: majorRevision: uint16, minorRevision: uint16

Get the firmware version number.

Peripherals

digitalRead

Command: 'd', pinNumber: uint8

Response: value: uint8

Read the digital value of pinNumber pin (Arduino numbering). Automatically sets required registers to allow input. Response value is 0x00 for false, and 0x01 for true.

digitalWrite

Command: 'D', pinNumber: uint8, value: uint8

Response: none

Write the digital value of pinNumber pin (Arduino numbering). Automatically sets required registers to allow output. The value argument is 0x00 for false, or else true. The firmware will not be responsible for making sure the pin isn't already used for motor or cartridge control.

analogRead

Command: 'a', pinNumber: uint8

Response: value: uint16

Read the analogue (ADC) value of pinNumber pin (Arduino numbering). Automatically sets required registers to allow input. Response value is the ADC reading. The firmware will not be responsible for making sure the pin isn't already used for motor or cartridge control, or for checking that the pin is ADC capabable.

analogWrite

Command: 'A', pinNumber: uint8, dutyCycle: uint8

Response: none

Write the analogue (PWM) value of pinNumber pin (Arduino numbering). Automatically sets required registers to allow output. The dutyCycle argument can be between 0x00 (0% duty cycle) and 0xFF (100% duty cycle). The firmware will not be responsible for making sure the pin isn't already used for motor or cartridge control, or for checking that the pin is PWM capabable.

Other

wait

Command: 'W', milliseconds: uint32

Response: none

Pause reading commands for milliseconds number of milliseconds.

fileAction

Command: 'B', filename: uint8[], 0x00, mode: uint8, dataLength: uint32, data: uint8[dataLength]

Response: status: uint8

Perform an action on a file named filename, a null-terminated string, on the SD card. This can be used to write commands to the SD card and then execute it.

The mode parameter must be one of:

  • FILE_WRITE - to write to a file, overwriting any previous data if it exists.
  • FILE_APPEND - to append to a file, requiring that the file already exists.
  • FILE_EXECUTE - to execute the commands contained in a file.

For FILE_WRITE and FILE_APPEND commands, the dataLength must be the byte length of the data buffer to be transferred. If filename is FILE_SERIAL, both write and append commands will output to the serial interface.

For FILE_EXECUTE commands, a filename must be given, and the dataLength parameter must be 0x00 and no data be sent.

The response status is:

  • EXECUTE_SUCCESS - on successful completion.
  • NO_SD_CARD - if there is no SD card present.
  • NO_FILE_EXISTS - if the mode is set to FILE_EXECUTE or FILE_APPEND and the file corresponding to filename does not exist.
  • UNKNOWN_CMD - if an unknown command is encountered while executing the file.
  • UNKNOWN_PARAM - if an unknown mode parameter is given or the mode is FILE_EXECUTE and the dataLength parameter is not 0x00.

gCode

Command: 'G', cmd: uint8[], 0x00

Response: none

Execute a null terminated G-code command.

extendedCommand

Command: 0xFF, cmd: uint8[]

Response: varies

Execute a command in the secondary command set.

Constant Values

The value of the constants above are defined in the following table:

Constant

Value

MOTION_COMPLETE

0x00

AXIS_X_POSITIVE

0x01

AXIS_X_NEGATIVE

0x02

AXIS_Y_POSITIVE

0x03

AXIS_Y_NEGATIVE

0x04

CARTRIDGE_0

0x01

CARTRIDGE_1

0x02

CARTRIDGE_2

0x04

STEPS_PER_MM_X

0x01

STEPS_PER_MM_Y

0x02

MM_PER_SECOND_X

0x03

MM_PER_SECOND_Y

0x04

DOTS_PER_MM_X

0x05

DOTS_PER_MM_Y

0x06

MOTOR_FLIP_X

0x07

MOTOR_FLIP_Y

0x08

FILE_WRITE

0x01

FILE_APPEND

0x02

FILE_EXECUTE

0x03

FILE_SERIAL

0xFF

EXECUTE_SUCCESS

0x00

NO_SD_CARD

0x01

NO_FILE_EXISTS

0x02

UNKNOWN_CMD

0x03

UNKNOWN_PARAM

0x04