Skip to content

Arduino serial interface to main desktop portocal

mattybabaallos edited this page May 14, 2018 · 13 revisions

The communication between the main application and Arduino will done by sending six-byte packet for each command or message.

The bytes packet will broken down and decoded on each end according to the following:

  • Zeroth byte will be the device to which operate or send a message about

    Devices:

     X_AXIS_TOP_MOTOR = 0
     X_AXIS_BOTTOM_MOTOR = 1
     Y_AXIS_MOTOR = 2
     TOP_LEDS = 3
     BOTTOM_LEDS = 4
     Y_AXIS_CPU_SWITCH = 5
     DOOR_SWITCH = 6
     BOTTOM_SWITCH =7
    
  • First byte will be the function to which the device should do

    Functions:

     Home the stepper = 0
     Move the stepper forward= 1
     Move the stepper backward= 2
     Stop the stepper = 3
     Turn on/ Update LEDs = 4
     Turn off LEDs = 5
    
    • NOTE:
      • 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.
  • 2nd, 3rd, 4th bytes will be any data the function will need. For example, the distance the motor will move or the color of the lights

  • 5th byte will be any error code the Arduino will send to main application in case of errors

    Error codes:

     SUCCESS = 0,
     RECEIVED_FEWER_THAN_TWO_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
    
    • NOTE:
      • The error codes will sent as an unsigned number and should be converted to signed at each end

Important Notes

  • For each command sent to the Arduino, the Arduino will send back to the main application the status of the operation. Meaning if the operation is successful or not. If the operation is successful Arduino will return the the new state of the affected device in the data fields. Otherwise, the error will be returned and the data fields will set to 0 and it should be ignored.

  • 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 data will be zero

Clone this wiki locally