Skip to content

Arduino serial interface to main desktop portocal

Matty edited this page May 10, 2018 · 13 revisions

The main will application will send in 2 bytes of data to Arduino. These byte will incorporate the operation and the device to control. This will be decoded on the Arduino to find the operation and the device based on the following:

We have 16 bits to work with:

  • Bits 0-2 indicate the stepper id according to the following:
    • X_AXIS_TOP = 0
    • X_AXIS_BOTTOM = 1
    • Z_AXIS_TOP = 2
    • Z_AXIS_BOTTOM = 3
    • Y_AXIS = 4
    • 5 NOT USED
    • TOP_LEDS = 6
    • BOTTOM_LEDS = 7
  • Bit 3-5 indicate the operation:
    • Home the stepper = 0
    • Move the stepper forward= 1
    • Move the stepper backward= 2
    • Stop the stepper = 3
    • Turn on/ Update LEDs
    • Turn off LEDs
  • Bit 6-7 unused
  • Bit 8-15 will be the length stepper motor will move mm. This means you can only move 255mm or 25.5cm at a time.

For each command the Arduino will send back to the main application the status of the operations. Meaning if the operation is successful or not. if the operation is successful Arduino will return the the new state of the affected device.

The first byte will contain the error code and the device affected.

  • Bits 0-2 indicate the device according to the following:
    • X_AXIS_TOP = 0
    • X_AXIS_BOTTOM = 1
    • Z_AXIS_TOP = 2
    • Z_AXIS_BOTTOM =3
    • Y_AXIS = 4
    • Y_AXIS_CPU = 5
    • TOP_LEDS = 6
    • BOTTOM_LEDS = 7 NOTICE: we are using "device" and not "stepper" because the device could be a limit switch. Eg. Y_AXIS_CPU = 5 is a limit switch.
  • Bit 3 is not used for now and reserved for new devices.
  • Bits 4-7 will contain the error code (as unsigned number). Error codes to be returned:
    • SUCCESS = 0,
    • RECEIVED_FEWER_THANTWO_BYTES = -1,
    • INVALID_OPERATION = -2,
    • INVALID_DEVICE = -3,
    • COULD_NOT_PERFORM_OPERATION = -4,
    • COULD_NOT_DECODE_BYTES = -5,
    • COULD_NOT_PROCESS_BUFFER = -6,
    • STOP_INTERRUPT = -7

Calling stop will have not return the new distance. But rather the function that was called to move the stepper will return the new position.

When an error ouccers, the distance bits will set to 0 and an retry is recommended.

When the limit switch is triggered, the Arduino send back to the main application the device generated the interrupt and a status code for stop and function code of stop but the distance will be 0

Clone this wiki locally