My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Arduino.pde 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /*
  2. TMC26XMotorTest.pde - - TMC26X Stepper Tester for Processing
  3. Copyright (c) 2011, Interactive Matter, Marcus Nowotny
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. */
  20. String channelAStatus=null;
  21. String channelBStatus=null;
  22. String temperatureStatus=null;
  23. boolean motor_connected = false;
  24. RadioButton serialButtons;
  25. Button serialOkButton;
  26. Button helpButton;
  27. Textarea statusArea;
  28. String[] ports;
  29. int activePortIndex = -1;
  30. String identString="TMC26X Stepper Driver Motor Tester";
  31. int connectTimeout=10*1000; //how long do we wait until the Arduino is connected
  32. StringBuilder serialStringBuilder = new StringBuilder();
  33. void setupSerialConfig() {
  34. Tab defaultTab = controlP5.getTab("default");
  35. //add the list of serial interfaces - it get's populated later
  36. serialButtons = controlP5.addRadioButton("serialport", 200, 100+TMCLogo.height*2+50);
  37. serialConfigElements.add(serialButtons);
  38. serialButtons.captionLabel().set("Select Serial Port");
  39. serialButtons.showBar();
  40. serialButtons.moveTo(defaultTab);
  41. //ad the ok button
  42. serialOkButton = controlP5.addButton("serialOk", 1, 200, height-300, 30, 30);
  43. serialConfigElements.add(serialOkButton);
  44. serialOkButton.setCaptionLabel("OK");
  45. runToggle.moveTo(defaultTab);
  46. //add the status area
  47. statusArea = controlP5.addTextarea("statusArea","",200,height-250,300,50);
  48. serialConfigElements.add(statusArea);
  49. statusArea.moveTo(defaultTab);
  50. helpButton = controlP5.addButton("help", 1, 200, height-250, 80, 30);
  51. serialConfigElements.add(helpButton);
  52. helpButton.moveTo(defaultTab);
  53. //finally update the list of serial ports
  54. updateSerialPortList();
  55. }
  56. void updateSerialPortList() {
  57. //first remove all present serial ports
  58. List items = serialButtons.getItems();
  59. for (Object i:items) {
  60. Toggle item = (Toggle) i;
  61. serialButtons.removeItem(item.getName());
  62. }
  63. //add the serial ports
  64. ports = Serial.list();
  65. for (int i=0; i< ports.length; i++) {
  66. serialButtons.addItem(ports[i],i);
  67. }
  68. serialButtons.setValue(-1);
  69. serialOkButton.setVisible(false);
  70. }
  71. void serialport(int value) {
  72. //ok button is only active if a serial port is selected
  73. serialOkButton.setVisible(value>-1);
  74. if (value>-1) {
  75. statusArea.setText("");
  76. }
  77. activePortIndex = value;
  78. }
  79. void serialOk(int value) {
  80. String error = null;
  81. if (value!=0 && activePortIndex>-1) {
  82. try {
  83. arduinoPort = new Serial(this, ports[activePortIndex], 115200);
  84. int timeStarted = millis();
  85. StringBuilder identBuffer = new StringBuilder();
  86. while (!motor_connected && (millis()-timeStarted)<connectTimeout) {
  87. if (arduinoPort.available ()>0) {
  88. char c = arduinoPort.readChar();
  89. identBuffer.append(c);
  90. if (c=='\n') {
  91. if (identString.contains(identString)) {
  92. motor_connected = true;
  93. toggleUi(true);
  94. return;
  95. }
  96. identBuffer = new StringBuilder();
  97. }
  98. }
  99. }
  100. } catch (RuntimeException e) {
  101. //we simply do nothing
  102. //TODO set status label
  103. error = "There was a problem with serial port "+ports[activePortIndex]+": "+e.getMessage();
  104. }
  105. //ok appearantly we did not find an motor tester - so lets deselect that port
  106. if (error == null) {
  107. error = "Could not find TMC26XMotorTester on serial port "+ports[activePortIndex];
  108. }
  109. statusArea.setText(error);
  110. Toggle selected = serialButtons.getItem(activePortIndex);
  111. selected.setState(false);
  112. serialOkButton.setVisible(false);
  113. }
  114. }
  115. void decodeSerial() {
  116. if (motor_connected) {
  117. while (arduinoPort.available ()>0) {
  118. char c = arduinoPort.readChar();
  119. serialStringBuilder.append(c);
  120. if (c=='\n') {
  121. decodeSerial(serialStringBuilder.toString());
  122. serialStringBuilder = new StringBuilder();
  123. }
  124. }
  125. }
  126. }
  127. void sendCommand(String command) {
  128. if (motor_connected) {
  129. arduinoPort.write(command+"\n");
  130. }
  131. }
  132. void decodeSerial(String line) {
  133. settingStatus=true;
  134. if (line.startsWith("#")) {
  135. String status = line.substring(1);
  136. StringTokenizer statusTokenizer = new StringTokenizer(status, ",");
  137. while (statusTokenizer.hasMoreTokens ()) {
  138. String statusToken = statusTokenizer.nextToken();
  139. if ("s".equals(statusToken)) {
  140. runToggle.setValue(0);
  141. }
  142. else if ("r".equals(statusToken)) {
  143. runToggle.setValue(1);
  144. }
  145. else if (statusToken.startsWith("e")) {
  146. int enabled = getValueOfToken(statusToken, 1);
  147. if (enabled!=0) {
  148. enabledToggle.setValue(1);
  149. }
  150. else {
  151. enabledToggle.setValue(0);
  152. }
  153. }
  154. else if (statusToken.startsWith("S")) {
  155. speedSlider.setValue(getValueOfToken(statusToken, 1));
  156. }
  157. else if (statusToken.startsWith("m")) {
  158. microsteppingButtons.activate("m_1/"+String.valueOf(getValueOfToken(statusToken, 1)));
  159. }
  160. else if (statusToken.startsWith("sg")) {
  161. addStallGuardReading(getValueOfToken(statusToken, 2));
  162. }
  163. else if (statusToken.startsWith("p")) {
  164. addPositionReading(getValueOfToken(statusToken, 1));
  165. }
  166. else if (statusToken.startsWith("k")) {
  167. addCurrentReading(getValueOfToken(statusToken, 1));
  168. }
  169. else if (statusToken.startsWith("t")) {
  170. sgtSlider.setValue(getValueOfToken(statusToken, 1));
  171. }
  172. else if (statusToken.startsWith("f")) {
  173. sgFilterToggle.setValue(getValueOfToken(statusToken, 1));
  174. }
  175. else if (statusToken.startsWith("d")) {
  176. setDirection(getValueOfToken(statusToken, 1));
  177. }
  178. else if (statusToken.startsWith("c")) {
  179. setCurrent(getValueOfToken(statusToken, 1));
  180. }
  181. else if (statusToken.startsWith("a")) {
  182. if (statusToken.charAt(1)=='o') {
  183. channelAStatus="Open Load";
  184. }
  185. else if (statusToken.charAt(1)=='g') {
  186. channelAStatus="Short to Ground!";
  187. }
  188. else {
  189. channelAStatus=null;
  190. }
  191. }
  192. else if (statusToken.startsWith("b")) {
  193. if (statusToken.charAt(1)=='o') {
  194. channelBStatus="Open Load";
  195. }
  196. else if (statusToken.charAt(1)=='g') {
  197. channelBStatus="Short to Ground!";
  198. }
  199. else {
  200. channelBStatus=null;
  201. }
  202. }
  203. else if (statusToken.startsWith("x")) {
  204. if (statusToken.charAt(1)=='w') {
  205. temperatureStatus="Prewarning!";
  206. }
  207. else if (statusToken.charAt(1)=='e') {
  208. temperatureStatus="Error";
  209. }
  210. else {
  211. temperatureStatus=null;
  212. }
  213. }
  214. else if (statusToken.startsWith("Cm")) {
  215. //chopper mode is currently ignored
  216. }
  217. else if (statusToken.startsWith("Co")) {
  218. constantOffSlider.setValue(getValueOfToken(statusToken, 2));
  219. }
  220. else if (statusToken.startsWith("Cb")) {
  221. blankTimeSlider.setValue(getValueOfToken(statusToken, 2));
  222. }
  223. else if (statusToken.startsWith("Cs")) {
  224. hysteresisStartSlider.setValue(getValueOfToken(statusToken, 2));
  225. }
  226. else if (statusToken.startsWith("Ce")) {
  227. hysteresisEndSlider.setValue(getValueOfToken(statusToken, 2));
  228. }
  229. else if (statusToken.startsWith("Cd")) {
  230. setHystDecrement(getValueOfToken(statusToken, 2));
  231. }
  232. else if ("Ke+".equals(statusToken)) {
  233. coolStepActiveToggle.setValue(1);
  234. }
  235. else if ("Ke-".equals(statusToken)) {
  236. coolStepActiveToggle.setValue(0);
  237. }
  238. else if (statusToken.startsWith("Kl")) {
  239. coolStepMinSlider.setValue(getValueOfToken(statusToken, 2));
  240. }
  241. else if (statusToken.startsWith("Ku")) {
  242. coolStepMaxSlider.setValue(getValueOfToken(statusToken, 2));
  243. }
  244. else if (statusToken.startsWith("Kn")) {
  245. coolStepDecrementButtons.activate(getValueOfToken(statusToken, 2));
  246. }
  247. else if (statusToken.startsWith("Ki")) {
  248. coolStepIncrementButtons.activate(getValueOfToken(statusToken, 2));
  249. }
  250. else if (statusToken.startsWith("Km")) {
  251. coolStepMinButtons.activate(getValueOfToken(statusToken, 2));
  252. }
  253. }
  254. }
  255. else {
  256. println(line);
  257. }
  258. settingStatus=false;
  259. }
  260. int getValueOfToken(String token, int position) {
  261. String value = token.substring(position);
  262. try {
  263. return Integer.valueOf(value);
  264. }
  265. catch (NumberFormatException e) {
  266. println("Unable to decode '"+value+"'of '"+token+"' !");
  267. return 0;
  268. }
  269. }
  270. void drawSerial() {
  271. //draw the logo and some epxlaining text while setting up the serial port
  272. if (!motor_connected) {
  273. image(TMCLogo,200, 100);
  274. fill(uiTextColor);
  275. text("Select the serial port where your Arduino is connected\nIf in doubt check it in the Arduino IDE.\nThe Motor Tester will automatically verify if it can find an Motor tester ath the port.",200,100+TMCLogo.height+50);
  276. }
  277. }
  278. void help(float value) {
  279. if (value!=0) {
  280. link(helpUrl);
  281. }
  282. }