Wiki source code of 2MC Communication Protocol

Last modified by Eric Nantel on 2023/03/20 12:53

Hide last authors
Eric Nantel 52.1 1 = Using the LSS-2MC Code =
Eric Nantel 6.1 2
3 Using the LSS-2MC with it's example code will allows the user to control two brushed DC or a single bipolar stepper motor. Being an ongoing project check the available functions bellow.
4
Eric Nantel 4.1 5 |=(% colspan="8" style="width: 25px;" %)Global
6 |=(% style="width: 25px;" %) |=(% style="width: 200px;" %)Description|=(% style="width: 100px;" %) Action|=(% style="width: 75px;" %) Query|=(% style="width: 75px;" %) Config|=(% style="width: 100px;" %)Default|=(% style="width: 170px;" %) Units|= Notes
Eric Nantel 22.1 7 | |[[**ID** #>>doc:||anchor="HIdentificationNumber28ID29"]]| |QID|CID|215 / 216|none (integer from 0 to 250)|Note: ID 254 is a "broadcast" which all servos / modules respond to.
Eric Nantel 23.1 8 | |[[**M**otor **M**ode>>doc:||anchor="HMotorMode28MM29"]]| |QMM|CMM| |0 / 1|0 = Stepper Mode / 1 = Brushed DC Mode
Eric Nantel 51.1 9 | |[[**G**yre direction (**G**)>>doc:||anchor="HGyreRotationDirection28G29"]]|G|QG|CG|1|1 / -1|Gyre / rotation direction: To invert the polarity or direction
Eric Nantel 23.2 10 | |[[**B**aud rate>>doc:||anchor="HBaudRate28B29"]]| |QB|CB|115200|none (integer)|
Eric Nantel 51.1 11 | |[[**M**odel **S**tring>>doc:||anchor="HQueryModelString28QMS29"]]| |QMS| |LSS-2MC-XX|(((
12 DBR = HBridge
13 ST = Stepper
14 )))|
Eric Nantel 45.1 15 | |[[**RESET**>>doc:||anchor="HReset28RESET29"]]|RESET| | | |None|Soft reset. See command for details.
Eric Nantel 20.1 16 | |[[**L**imp>>doc:||anchor="HLimp28L29"]]|L| | | |None|MM0 = Stop / MM1 = Coast to a stop
Eric Nantel 36.1 17 | |[[**H**alt & Hold>>doc:||anchor="HHalt26Hold28H29"]]|H| | | |None|MM0 = Stop & Hold / MM1 Stop with brake
Eric Nantel 56.1 18 | |[[Motion Mode>>doc:||anchor="HMotionMode"]]| |Q| | | |0 = Holding / 1 = Stepping / 2 = Speed / 3 = Angle
Eric Nantel 4.1 19 |(% colspan="8" %)**DC Motor / H-Bridge**
Eric Nantel 23.8 20 | |[[**R**aw **D**uty-cycle **M**ove>>doc:||anchor="HRawDuty-cycleMove28RDM29"]]|RDM|QRDM| |0|-255 / 255|Set duty-cycle and truncated to 255 if exceeded
Eric Nantel 4.1 21 |(% colspan="8" %)**Stepper Motor**
Eric Nantel 58.2 22 | |[[**W**heel mode in **D**egrees>>doc:||anchor="HWheelModeinDegrees28WD29"]]|WD|QWD| |0|°/s|-9000 / 9000 in tenths of degs/sec
Eric Nantel 7.1 23
Eric Nantel 10.2 24 ====== __Identification Number (**ID**)__ ======
Eric Nantel 10.1 25
Eric Nantel 28.3 26 |(% style="width:25px" %) |(((
27 Identification number connected to the 2MC Board can be configured via the CID command described below. The factory default ID (as per the sketch loaded at the factory) for all 2MC pins is indicated in the Pin / ID  table above. Since LSS & 2MC devices are intended to be daisy chained, in order to respond differently from one another, the user must set a different ID number for each pin. Devices connected to pins which use the same ID and baud rate will therefore all receive and react to the same commands.
28
29 Note: Most people will keep the default ID unless using multiple LSS-2MC on the same communication bus.
30 )))
Eric Nantel 26.1 31 | |(((
32 Configure ID (**CID**)
Eric Nantel 25.2 33
Eric Nantel 28.2 34 Ex: #215CID200<cr>
35 This command will change the ID of the H-Bridge connected to pin D9 & D10 from 215 to 200.
Eric Nantel 30.10 36
37 Query ID (**QID**)
38
39 Ex: #215QID<cr> might return *215QID215
Eric Nantel 26.1 40 )))
41
Eric Nantel 10.2 42 ====== __Motor Mode (**MM**)__ ======
Eric Nantel 10.1 43
Eric Nantel 29.2 44 |(% style="width:25px" %) |(((
Eric Nantel 30.2 45 Our example code allows for two types of motors to be used, either Brushed DC or Stepper. One need to set the mode in which they want to use the LSS-2MC.
Eric Nantel 30.3 46 )))
47 | |(((
Eric Nantel 30.7 48 Configure Motor Mode (**MM**)
49
Eric Nantel 40.3 50 Ex: #215CMM0<cr> should return *215QMM0<cr>
Eric Nantel 30.3 51 Configure the LSS-2MC for a single Stepper motor and will use all four outputs on a single ID. (default: 215)
Eric Nantel 30.2 52
Eric Nantel 48.1 53 Ex: #215CMM1<cr> should return *215QMM1<cr>
Eric Nantel 30.3 54 Configure the LSS-2MC for dual Brushed DD motor and will operate on two different IDs. (default: 215 & 216)
Eric Nantel 30.2 55
Eric Nantel 30.8 56 Query Motor Mode (**QMM**)
Eric Nantel 30.7 57
Eric Nantel 30.3 58 Ex: #215QMM<cr> might return *215QMM0<cr>
59 Query the motor mode.
Eric Nantel 29.2 60 )))
Eric Nantel 25.2 61
Eric Nantel 10.2 62 ====== __Gyre Rotation Direction (**G**)__ ======
63
Eric Nantel 48.1 64 |(% style="width:25px" %) |Ex: #215G-1<cr>
65 Reverse the polarity / rotation for the given output.
Eric Nantel 25.2 66
Eric Nantel 10.2 67 ====== __Baud Rate (**B**)__ ======
68
Eric Nantel 29.2 69 |(% style="width:25px" %) |(((
Eric Nantel 30.3 70 Since it's intended to be daisy chained with LSS, in order to respond to the same serial bus, all LSS / 2MCs in a project should be set to the same baud rate. Setting different baud rates may create issues. Available baud rates are: 9600 bps, 19200 bps, 38400 bps, 57600 bps, 115.2 kbps, 230.4 kbps, 250.0 kbps, 460.8 kbps, 500.0 kbps. 2MC  Board is shipped with a baud rate set to 115200.
Eric Nantel 29.2 71 )))
Eric Nantel 30.3 72 | |(((
73 Configure Baud Rate (**CB**)
74
Eric Nantel 30.5 75 Ex: #215CB9600<cr>
Eric Nantel 30.3 76 Sending this command will change the baud rate associated of the 2IO associated with ID 207 to 9600 bits per second.
77
Eric Nantel 30.6 78 Important Note: the 2MC new baud rate takes effect immediately after sending the CB command.
79
80 Query Baud Rate (**QB**)
81
82 Ex: #215QB<cr> might return *207QB115200<cr>
83 Since the command to query the baud rate must be done at the 2MC's existing baud rate, it can simply be used to confirm the CB configuration command was correctly received.
Eric Nantel 30.3 84 )))
85
Eric Nantel 42.1 86 ====== __Query Model String (**QMS**)__ ======
Eric Nantel 10.2 87
Eric Nantel 29.2 88 |(% style="width:25px" %) |(((
Eric Nantel 31.1 89 Ex: #215QMS<cr> might return *215QMSLSS-2MC-DBR<cr>
90 This reply means that the LSS-2MC is in DC Brushed Mode (MM1)
Eric Nantel 25.2 91
Eric Nantel 31.1 92 Ex: #215QMS<cr> might return *216QMSLSS-2MC-ST<cr>
93 This reply means that the LSS-2MC is in Stepper Mode (MM0)
94 )))
95
Eric Nantel 43.1 96 ====== __Reset (**RESET**)__ ======
Eric Nantel 10.3 97
Eric Nantel 29.2 98 |(% style="width:25px" %) |(((
Eric Nantel 33.1 99 Ex: #215RESET<cr>
100 This command does a "soft reset" (no power cycle required) and reverts all commands to those stored in EEPROM (default values). This command works with the 2MC IDs (215 & 216 by default) and the broadcast ID (254).
Eric Nantel 29.2 101 )))
Eric Nantel 25.2 102
Eric Nantel 13.1 103 ====== __Limp (**L**)__ ======
104
Eric Nantel 29.2 105 |(% style="width:25px" %) |(((
Eric Nantel 48.1 106 Ex: #215L<cr>
Eric Nantel 32.4 107 This action causes the Stepper or DC Motor to go "limp".
Eric Nantel 25.2 108
Eric Nantel 48.1 109 Ex: #254L<cr>
Eric Nantel 32.4 110 It's possible to use this command as an emergency safety in broadcast.
111 )))
112
Eric Nantel 33.2 113 ====== __Halt & Hold (**H**)__ ======
Eric Nantel 13.1 114
Eric Nantel 29.2 115 |(% style="width:25px" %) |(((
Eric Nantel 32.7 116 Stepper Mode (MM0)
Eric Nantel 25.2 117
Eric Nantel 48.1 118 Ex: #215H<cr>
Eric Nantel 32.7 119 Motor will stop and hold it's position.
120 )))
121 | |(((
122 Brushed DC Mode (MM1)
123
Eric Nantel 48.1 124 Ex: #215H<cr>
Eric Nantel 32.7 125 Motor will stop with brake feature.
126 )))
127
Eric Nantel 55.1 128 ====== __Motion Mode__ ======
Eric Nantel 53.1 129
130 |(% style="width:25px" %) |(((
Eric Nantel 57.1 131 Ex: #215Q<cr> might return *215Q0<cr>
132 This reply means that the LSS-2MC is in Holding mode
Eric Nantel 53.1 133
Eric Nantel 58.1 134 0 = Holding
135 1 = Stepping
136 2 = Speed
137 3 = Angle
Eric Nantel 53.1 138 )))
139
Eric Nantel 49.1 140 ====== __Raw Duty-cycle Move (**RDM**)__ ======
Eric Nantel 10.3 141
Eric Nantel 29.2 142 |(% style="width:25px" %) |(((
Eric Nantel 48.1 143 Ex: #215RDM255<cr>
Eric Nantel 36.2 144 This will send, in Brushed DC mode (MM1), the output to it's maximum.
145
Eric Nantel 48.1 146 Ex: #215RDM-255<cr>
Eric Nantel 36.2 147 This will send, in Brushed DC mode (MM1), the output to it's maximum but with the polarity reversed from the example above.
Eric Nantel 48.1 148 \\Ex: #215QRDM<cr> might return *215QRDM255<cr>
Eric Nantel 36.2 149 This command queries the raw duty-cycle move value.
Eric Nantel 29.2 150 )))
Eric Nantel 25.2 151
Eric Nantel 38.1 152 ====== __Wheel Mode in Degrees (**WD**)__ ======
Eric Nantel 13.1 153
Eric Nantel 29.2 154 |(% style="width:25px" %) |(((
Eric Nantel 58.2 155 Ex: #215WD900<cr> 
Eric Nantel 40.7 156 This command sets the stepper to wheel mode where it will rotate in the desired direction at the selected speed. The example above would have the stepper rotate at 90.0 degrees per second clockwise (assuming factory default configurations).
Eric Nantel 29.2 157 )))
Copyright RobotShop 2018