Arduino Stepper Motor Protocol

With this devicehandler you can control multiple stepper motors simultaneously. The stepper motors and the optional endstop sensors are connected to the microcontroller.

How to build a test circuit with Stepper Motors and an Arduino Mega?
Arduino codes are included.

I. "Welcome" event from microcontroller

Example

c=welcome&id=IqlZci&type=OzStepperMotorMultiController&pos=2&t=4

Parameters

Parameter Type Range Functionality
c String "welcome" Identifies the welcome message.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
type String "OzekiStepperMotorMultiController" Determines the type of the devicehandler.
pos Byte 0-255 Determines the position of the device on the list of the ID manager of the microcontroller. Please make sure there are no other devices in the same position.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.



II. Commands to microcontroller

"Go" command

This command steps the motors with a chosen number of steps in a chosen direction with a chosen speed. (The speed is equal for all of the motors included in the command.) It also sets the motorstate to Enabled. Otherwise the motor couldn't make the steps. The eas parameter determines if the motorstate should be set to enabled or disabled after making the steps or stopping.

Example

//Moves all motors
c=go&x=10&y=10&z=10&a=50&b=50&c=50&spd=100&eas=1&t=0&id=IqlZci
//Moves only the x, y, b motors c=go&x=10&y=-100&b=30&spd=4000&eas=0&t=1&id=IqlZci

Parameters

Parameter Type Range Functionality
c String "go" Identifies the command.
x, y, z, a, b, c Long Int -200000 to 200000 Determines which motor needs to move, in which direction and how much steps. Motors can be <x, y, z, a, b, c>. The sign of the stepnumber determines the stepping direction.
spd Float 1-20000 Sets the the given motors "Steps / Sec" value. In other words it sets the motorspeed.
eas Bool 0,1 1: Keeps motors enabled after stepping. 0: Disables motors after stepping.
t Byte 0-255 Counts the number of commands sent. Counts from 0 to 255 then from 0 again.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.

Response

The response arrive after the motors stop. This could be the end of stepping, this could be by hitting the endstop or by ordering a stop command.

//Moves all motors - response
c=go_resp&x=10&y=10&z=10&a=50&b=50&c=50&id=IqlZci&t=5
//Moves only the x, y, b motors - response c=go_resp&x=10&y=-100&b=30&id=IqlZci&t=6

Parameters

Parameter Type Range Functionality
c String "go_resp" Identifies the response.
Axis value (x | y | z | a | b | c) Long Int -200000 to 200000 Determines which motors moved and how much steps in which direction. Motors can be <x, y, z, a, b, c>.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.



"GoInf" command

This command steps the motors continually until an endstop is reached, a physical obstacle is reached or a "stop" command is sent. It steps the motors in a chosen direction with a chosen speed. (The speed is equal for all of the motors included in the command.) It also determines if the motorstate should be set to enabled or disabled after stopping at an endstop. (It will only stop at an endstop if the state of the endstop is set to 1. See below the "Watch EndStop" command.)

Example

//Moves all motors to infinity
c=goinf&x=100&y=100&z=100&a=100&b=100&c=100&spd=100&eas=1&t=3&id=IqlZci
//Moves only the x motor to infinity c=goinf&x=100&spd=100&eas=1&t=4&id=IqlZci

Parameters

Parameter Type Range Functionality
c String "goinf" Identifies the command.
Axis value (x | y | z | a | b | c) Int -32768 to 32767 Determines which motors need to move infinitly in which direction. The direction is determined by the sign of the value. The value is irrelevant, only the sign matters. Motors can be <x, y, z, a, b, c>.
spd Float 1-20000 Sets the the given motors "Steps / Sec" value. In other words it sets the motorspeed.
eas Bool 0,1 1 enables the motors after reaching the endstop or receiving a "stop" command, 0 disables the motors.
t Byte 0-255 Counts the number of commands sent. Counts from 0 to 255 then from 0 again.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.

Response

c=goinf_resp&id=IqlZci&t=7

Parameters

Parameter Type Range Functionality
c String "goinf_resp" Identifies the response.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.



"Stop" command

This command stops every motor when it is given out by the .net. As a response the controller sends a go_resp.

Example

//Stops all motors
c=stop&t=5&id=IqlZci

Parameters

Parameter Type Range Functionality
c String "stop" Identifies the command.
t Byte 0-255 Counts the number of commands sent. Counts from 0 to 255 then from 0 again.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.



"Enable" command

This command sets the state of given motors to enabled or disabled state. The difference between the 2 state is that in enabled state you can't turn the motor manually, you can only turn the motor with "go" or "goinf" commands, but if you set the motor to disabled state, it is possible to turn the motor by hand. Be aware that in disabled state the motor can't be turned by the microcontroller.

Example

c=enable&x=1&y=1&z=0&a=1&b=0&c=1&t=6&id=IqlZci

Parameters

Parameter Type Range Functionality
c String "enable" Identifies the command.
Axis value (x | y | z | a | b | c) Bool 0, 1 1 enables the motor on a given axis. 0 disables it.
t Byte 0-255 Counts the number of commands sent. Counts from 0 to 255 then from 0 again.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.

Response

c=enable_resp&x=1&y=1&z=1&a=1&b=1&c=1&id=IqlZci&t=8

Parameters

The microcontroller sends back the axes of motors whose were enabled as parameters of this response.

Parameter Type Range Functionality
c String "enable_resp" Identifies the response.
Axis value (x | y | z | a | b | c) Bool 0, 1 1 confirms that the motor is enabled, 0 shows it's disabled.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.



"WatchEndstop" command

Sets the endstop watching options on a given axis. You need to set the type of the endstop (min, max) and the state of the endstop.

Example

c=watchendstop&axis=y&end=min&state=0&id=IqlZci&t=7

Parameters

Parameter Type Range Functionality
c String "watchendstop" Identifies the command.
axis Char x, y, z, a, b, c Selects the axis of the endstop.
end String "min", "max" The type of the endstop is "max" if the motor needs to turn in the positive direction to reach the endstop otherwise it's "min".
state Byte 0, 1, 2 0: Disables the chosen endstop.
1: Enables the endstop. In this state the motor stops at every endstop and the microcontroller sends out a "go_resp".
2: Switch to report only mode. This doesn't stop the motor, but it sends an "endstophit" event on both entering and leaving the endstop.
t Byte 0-255 Counts the number of commands sent. Counts from 0 to 255 then from 0 again.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.

Response

c=watchendstop_resp&axis=y&end=max&state=2&id=IqlZci&t=9

Parameters

Parameter Type Range Functionality
c String "watchendstop_resp" Identifies the response.
axis Char x, y, z, a, b, c Reports the axis of the endstop.
end String "min", "max" Reports the endpoint where the endstop is placed.
state Byte 0, 1, 2 Reports which mode was selected.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.



"GetNumOfMotors" command

Asks for the number of motors.

Example

//Asks the number of motors connected to devicehandler ID IqlZci
c=getnumofmotors&t=8&id=IqlZci

Parameters

Parameter Type Range Functionality
c String "getnumofmotors" Identifies the command.
t Byte 0-255 Counts the number of commands sent. Counts from 0 to 255 then from 0 again.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.

Response

This is the number of motors added to the OzekiStepperMotorMulticontroller. Most of the time it is the number of motors connected to the microcontroller.

//Responds the number of motors
c=getnumofmotors_resp&count=3&t=10&id=IqlZci

Parameters

Parameter Type Range Functionality
c String "getnumofmotors_resp" Identifies the response.
count Byte 0-255 Number of motors. (Jelenleg maximum 4 motor, mert minden motornak külön timere van.)
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.
t Byte 0-255 Counts the number of events and responses sent combined. Counts from 0 to 255 then from 0 again.



III. Events from microcontroller

"EndstopHit" event

This event is sent out if the endstop was set by the "WatchEndstop" command to state 2.

c=endstophit&axis=y&end=max&button=1&step=8764&id=xj2DXC&t=11

Parameters

Parameter Type Range Functionality
c String "endstophit" Identifies the event.
axis String One of the <Axes> Axes can be <x, y, z, a, b, c>.
end String "min", "max" Endpoint of the endstop.
button Bool 0, 1 0: The button (endstop) is released.
1: The button (endstop) is pressed.
step Unsigned 0-65535 Depends on how the motor was stepped.
If the "goinf" command was used, this value will be equal to the number of steps the motor has travelled so far.
If the "go" command was used, it will be equal to the number of remaining steps required to complete the given number of steps (specified by the "go" command).
t Byte 0-255 Counts the number of commands sent. Counts from 0 to 255 then from 0 again.
id String 6 characters (numbers, uppercase and lowercase characters) The ID of the device which is chosen by the microcontroller.

More information