Frästisch mit elektronischer Höhenverstellung mittels Schrittmotoren.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Fraestisch_SFTools.ino 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. Steuerung für Frästisch_SFTools
  3. Diese Datei enthält den Code für die Implementierung der Steuerung eines Frästisches mit 2 Nema17 Schrittmotoren.
  4. Sie unterstützt:
  5. - Schnelles/langsames Verstellen der Fräserhöhe
  6. - Werkzeugwechsel
  7. - Automatisches Nullen mit WLS
  8. - Eintauchen mit vordefinierter Tiefe
  9. - Für obige Funktionen notwendige Konfiguration
  10. Erstellt: 05.01.2021
  11. Autor: Flo Smilari
  12. */
  13. #include <Arduino.h>
  14. #include <RotaryEncoder.h>
  15. #include "WLS.h"
  16. #include "ExEzButton.h"
  17. #include <Wire.h>
  18. #include <Adafruit_GFX.h>
  19. #include <Adafruit_SSD1306.h>
  20. #define SCREEN_WIDTH 128
  21. #define SCREEN_HEIGHT 64
  22. #define SCREEN_ADDRESS 0x3C
  23. static const byte led_gpio = 15;
  24. static const int WLS_Pin = 34;
  25. static const int WLS_DETECT_Pin = 35;
  26. static const int GreenBtn_Pin = 12;
  27. static const int RedBtn_Pin = 13;
  28. static const int BlueBtn_Pin = 14;
  29. static const int RotEnc_Switch_Pin = 25;
  30. static const int RotEnc_Clk_Pin = 32;
  31. static const int RotEnc_Dta_Pin = 33;
  32. ExEzButton RedButton(RedBtn_Pin, false, 2000);
  33. ExEzButton GreenButton(GreenBtn_Pin);
  34. ExEzButton BlueButton(BlueBtn_Pin);
  35. ExEzButton RotarySwitch(RotEnc_Switch_Pin, true, 2000);
  36. WLS WlsDetect(WLS_DETECT_Pin, true);
  37. WLS Wls(WLS_Pin);
  38. RotaryEncoder encoder(RotEnc_Dta_Pin, RotEnc_Clk_Pin, RotaryEncoder::LatchMode::FOUR3);
  39. Adafruit_SSD1306 Display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); // SCK on Pin 22, SDA on PIN 23
  40. //**********************
  41. //*** SETUP ************
  42. //**********************
  43. void setup() {
  44. Serial.begin(115200);
  45. if (!Display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS, true, true)) {
  46. Serial.println(F("SSD1306 allocation failed"));
  47. for (;;)
  48. ; // Don't proceed, loop forever
  49. }
  50. pinMode(led_gpio, OUTPUT);
  51. pinMode(GreenBtn_Pin, INPUT);
  52. pinMode(RedBtn_Pin, INPUT);
  53. pinMode(BlueBtn_Pin, INPUT);
  54. pinMode(RotEnc_Switch_Pin, INPUT);
  55. pinMode(RotEnc_Clk_Pin, INPUT);
  56. pinMode(RotEnc_Dta_Pin, INPUT);
  57. RedButton.setDebounceTime(50); // set debounce time to 50 millis
  58. GreenButton.setDebounceTime(50);
  59. BlueButton.setDebounceTime(50);
  60. WlsDetect.setDebounceTime(50);
  61. Wls.setDebounceTime(50);
  62. RotarySwitch.setDebounceTime(50);
  63. Display.display();
  64. delay(2000); // Pause for 2 seconds
  65. // Clear the buffer
  66. Display.clearDisplay();
  67. testdrawchar();
  68. delay(5000); // Pause for 5 seconds
  69. Display.clearDisplay();
  70. testdrawstyles();
  71. }
  72. //**********************
  73. //*** MAIN LOOP ********
  74. //**********************
  75. void loop() {
  76. RedButton.loop(); // MUST call the loop() function first
  77. GreenButton.loop();
  78. BlueButton.loop();
  79. WlsDetect.loop();
  80. Wls.loop();
  81. RotarySwitch.loop();
  82. if (WlsDetect.isPlugged()) {
  83. Serial.println("The WLS was connected");
  84. } else if (WlsDetect.isUnplugged()) {
  85. Serial.println("The WLS was disconnected");
  86. }
  87. if (WlsDetect.getStateRaw() == HIGH) {
  88. if (Wls.isPlugged()) {
  89. Serial.println("The Tool is away from WLS");
  90. } else if (Wls.isUnplugged()) {
  91. Serial.println("The Tool touched the WLS");
  92. }
  93. }
  94. if (RedButton.isPressed()) {
  95. Serial.println("Red button was pressed");
  96. digitalWrite(led_gpio, HIGH);
  97. }
  98. if (RedButton.isLongPressed()) {
  99. Serial.println("Red button was long pressed");
  100. digitalWrite(led_gpio, LOW);
  101. }
  102. bool greenPressed = GreenButton.isPressed();
  103. bool bluePressed = BlueButton.isPressed();
  104. if (GreenButton.isPressing() && BlueButton.isPressing()) {
  105. Serial.println("Blue and green button were simultaneous pressed");
  106. } else if (greenPressed) {
  107. Serial.println("Green button was pressed");
  108. } else if (bluePressed) {
  109. Serial.println("Blue button was pressed");
  110. }
  111. if (RotarySwitch.isPressed()) {
  112. Serial.println("Rotary switch was pressed");
  113. }
  114. if (RotarySwitch.isLongPressed()) {
  115. Serial.println("Rotary switch long was pressed");
  116. }
  117. static int pos = 0;
  118. encoder.tick();
  119. int newPos = encoder.getPosition();
  120. if (pos != newPos) {
  121. Serial.print("pos:");
  122. Serial.print(newPos);
  123. Serial.print(" dir:");
  124. Serial.println((int) (encoder.getDirection()));
  125. pos = newPos;
  126. }
  127. }
  128. void testdrawchar(void) {
  129. Display.clearDisplay();
  130. Display.setTextSize(1); // Normal 1:1 pixel scale
  131. Display.setTextColor(SSD1306_WHITE); // Draw white text
  132. Display.setCursor(0, 0); // Start at top-left corner
  133. Display.cp437(true); // Use full 256 char 'Code Page 437' font
  134. // Not all the characters will fit on the Display. This is normal.
  135. // Library will draw what it can and the rest will be clipped.
  136. for (int16_t i = 0; i < 256; i++) {
  137. if (i == '\n')
  138. Display.write(' ');
  139. else
  140. Display.write(i);
  141. }
  142. Display.display();
  143. delay(2000);
  144. }
  145. void testdrawstyles(void) {
  146. Display.clearDisplay();
  147. Display.setTextSize(1); // Normal 1:1 pixel scale
  148. Display.setTextColor(SSD1306_WHITE); // Draw white text
  149. Display.setCursor(0, 0); // Start at top-left corner
  150. Display.println(F("Hello, world!"));
  151. Display.setTextColor(SSD1306_BLACK, SSD1306_WHITE); // Draw 'inverse' text
  152. Display.println(3.141592);
  153. Display.setTextSize(2); // Draw 2X-scale text
  154. Display.setTextColor(SSD1306_WHITE);
  155. Display.print(F("0x"));
  156. Display.println(0xDEADBEEF, HEX);
  157. Display.display();
  158. delay(2000);
  159. }