-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstacker.ino
executable file
·179 lines (139 loc) · 6.31 KB
/
stacker.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/* Sergey Mashchenko 2015-2021
Fast Stacker: an automated macro rail for focus stacking
Online tutorial: http://pulsar124.wikia.com/wiki/Fast_Stacker
Major rehaul of hardware and software.
Hardware h2.0
- ESP8266 microcontroller (D1 Mini)
- MCP23S17 chip - 16 GPIO expander using SPI
- SPI-driven TFT display ST7735
- 4x4 keypad
- DRV8825 stepper motor driver
- stepper motor
The hardware used:
Original (h1.0):
- Velbon Super Mag Slider manual macro rail, with some customization
- Ultrathin 2-Phase 4-Wire 42 Stepper Motor 1.8 Degree 0.7A (http://www.ebay.ca/itm/Ultrathin-2-Phase-4-Wire-42-Stepper-Motor-1-8-Degree-0-7A-e-/261826922341?pt=LH_DefaultDomain_0&hash=item3cf619c765 )
- Arduino Uno R3
- EasyDriver stepping Stepper Motor Driver V4.4
- 4x4 keys keypad (http://www.ebay.ca/itm/4x4-Matrix-high-quality-Keyboard-Keypad-Use-Key-PIC-AVR-Stamp-Sml-/141687830020?pt=LH_DefaultDomain_0&hash=item20fd40b604 )
- Nokia 5110 LCD display + four 10 kOhm resistors + 1 kOhm + 330 Ohm (https://learn.sparkfun.com/tutorials/graphic-lcd-hookup-guide)
- 5V Relay SIP-1A05 + 1N4004 diode + 33 Ohm resistor; to operate camera shutter (http://www.forward.com.au/pfod/HomeAutomation/OnOffAddRelay/index.html)
- Voltage divider for battery sensor: resistors 270k, 360k, capacitor 0.1 uF.
New in h1.1: extra 10k resistor.
New in h1.2: extra SIP-1A05 relay, 1N4004 diode, 0.1 uF capacitor, 33 Ohm and 47 k resistors.
New in h1.3: motor driver upgrade EasyDriver -> BigEasyDriver (16 microsteps/step), more powerful motor (1.3A/coil). Added telescope focuser module (second identical stepper motor
plus a voltage divider consisting of a thermistor and regular resistor with a similar resistance - both 10k in my case). Added 10uF capacitor for LCD backlighting (to fix the
LCD instability due to PWM ripples in backlighting control).
h2.0: complete rehaul of the hardware and software: ESP8266, MCP23S17, ST7735 TFT, DRV8825, optocouplers.
I am using the following libraries:
- TFT_eSPI - fast library for ST7735 TFT display (https://github.com/Bodmer/TFT_eSPI); copy the customized file User_Setup.h to
the library's folder
- MCP23S17 Class for Arduino (included, customized; https://playground.arduino.cc/Main/MCP23S17/)
- Keypad library (included, customized): http://playground.arduino.cc/Code/KeypadTdu
Hardware revisions [software versions supported]:
h1.0 [s0.08]: Original public release design.
h1.1 [s0.10, s0.12, s0.14, s0.08a]: Second row keypad pin moved from 10 to 7. Pin 10 left free (for hardware SPI). Display's pin SCE (CE / chip select) disconnected from pin 7.
Instead, display SCE pin is soldered to the ground via 10k (pulldown) resistor.
h1.2 [s1.00 and newer]: LCD reset pin (RST) disconnected from Arduino; instead it is now hardware controlled via RC delay circuit (R=47k, C=0.1uF, connected to VCC=+3.3V).
Arduino pin 6 is now used to control the second relay (+ diod + R=33 Ohm), for camera autofocus.
h1.3 [s1.18 and up]: Upgraded EasyDriver to BigEasyDriver. Swapped pins A3-5 with 0-2, and 6 with A2. Increased N_MICROSTEPS to 16. Added thermometer (10k resistor + 10k thermistor).
Using Hall sensor instead of micro switch in telescope mode.
h2.0 [s2.00 and up]: complete rehaul of the hardware and software: ESP8266, MCP23S17, ST7735 TFT, DRV8825, optocouplers. New motion algorithm (prediction-correction).
Removed the telescope mode. Removed backlight stuff.
*/
#include <ESP8266WiFi.h>
#include <EEPROM.h>
#include <math.h>
#include <limits.h>
#include <SPI.h>
#include <TFT_eSPI.h>
#include "Keypad.h" // #include "MCP23S17.h" is called there
#include "stacker.h"
#include "stdio.h"
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void setup() {
// Should be the first line in setup():
g.setup_flag = 1;
// Completely disabling WiFi:
WiFi.mode( WIFI_OFF );
WiFi.forceSleepBegin();
// ESP.deepSleep(1000, WAKE_RF_DISABLED);
EEPROM.begin(ADDR_END); // Initializing EEPROM
iochip.begin(); // Initializing the port expander
iochip.pinMode (IO_MODE);
iochip.pullupMode (IO_PULLUP);
iochip.inputInvert(0B0000000000000000); // Likely not needed
// Setting the requested microstepping mode:
iochip.digitalWrite(EPIN_M0, MOTOR_M0);
iochip.digitalWrite(EPIN_M1, MOTOR_M1);
iochip.digitalWrite(EPIN_M2, MOTOR_M2);
#ifdef BUZZER
iochip.pinMode(EPIN_BUZZ, OUTPUT);
#endif
#if defined(SER_DEBUG) || defined(SER_DEBUG_TIME)
Serial.begin(115200);
#endif
#ifdef TEST_SWITCH
#ifdef SERIAL_SWITCH
Serial.begin(9600);
#endif
#endif
// Setting pins for motor Driver to OUTPUT:
#ifndef DISABLE_MOTOR
pinMode(PIN_DIR, OUTPUT);
pinMode(PIN_STEP, OUTPUT);
#endif
g.enable_flag = HIGH;
iochip.digitalWrite(EPIN_ENABLE, g.enable_flag);
pinMode(PIN_LIMITERS, INPUT_PULLUP);
g.error = 0;
// Initializing the display
tft.init();
tft.setRotation(3);
tft.fillScreen(TFT_BLACK);
tft.setTextWrap(true);
tft.setTextFont(2);
tft.setTextColor(TFT_YELLOW, TFT_BLACK);
// Checking if EEPROM was never used:
if (EEPROM.read(0) == 255 && EEPROM.read(1) == 255)
{
// Initializing with a factory reset (setting EEPROM values to the initial state):
initialize(1);
}
else
{
// Initializing, with EEPROM data read from the device
initialize(0);
}
// This should not be done in initialize():
keypad.key[0].kstate = (KeyState)0;
keypad.key[1].kstate = (KeyState)0;
// Should be the last line in setup:
g.setup_flag = 0;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void loop()
{
#ifdef TEST_SWITCH
test_switch();
#endif
// Performing backlash compensation after bad direction moves:
backlash();
#ifdef BUZZER
buzzer();
#endif
// Display related regular activities:
display_stuff();
// Processing the keypad:
process_keypad();
// All the processing related to the two extreme limits for the macro rail movements:
limiters();
// Perform calibration of the limiters if requested:
calibration();
// Camera control:
camera();
// Issuing write to stepper motor driver pins if/when needed:
motor_control();
// Cleaning up at the end of each loop:
cleanup();
}