Skip to content

Commit 169ae92

Browse files
Major refactor
- Moved each menu into their own file - Moved utitlity functions into their own file - Created functions to handle key processing and display in those files - Added CTRL menu to allow free movement of the steppers (and to calibrate to zero point (celestial pole)). Use SELECT/LEFT to start moving RA, UP/DOWN to start moving DEC, click again to stop) - Added HOME menu to return to zero point (celestial pole) - Made CAL input speed up the longer you hold it down - Made HEAT menu optional - Added 'splashscreen' on startup - Allowed some debug code to be excluded from compilation - Fixed tracker stepper not being stepped all the time - Added some limits to stepper movements to prevent physical damage (DEC requires config for latitudes far away from 47N) - Added code to move and stop steppers in both blocking and non-blocking ways, allowing for correct deceleration. - Added status displays for all movements (percentage for RA/DEC, stepper position for CTRL) - Added lots of comments
1 parent 6e5f363 commit 169ae92

20 files changed

+946
-578
lines changed
Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
=======================================================================================================================================
33
4-
Version 1.2.4
4+
Version 1.4.0
55
66
1. Connect your Arduino, under tools choose "Arduino Uno", set the right Port and set "Arduino ISP" as the Programmer.
77
2. Hit upload
@@ -10,27 +10,47 @@
1010
1111
=======================================================================================================================================
1212
*/
13-
boolean north = true; // change this to 'false' if youre in the southern hemisphere
13+
String version = "V1.4.0";
14+
15+
boolean north = true; // change this to 'false' if youre in the southern hemisphere
1416

1517
float speed = 1.000; // Use this value to slightly increase or decrese tracking speed. The values from the "CAL" menu will be added to this.
1618

17-
int RAsteps = 330; // adjust this value to calibrate RA movement
19+
int RAsteps = 330; // adjust this value to calibrate RA movement
1820
int DECsteps = 163;
1921

20-
float RevSteps = 4096;
2122
// This is how many steps your 28BYJ-48 stepper needs for a full rotation. It is almost always 4096.
2223
// This code drives the steppers in halfstep mode
24+
float RevSteps = 4096;
2325

2426
int RAspeed = 400; // You can change the speed and acceleration of the steppers here. Max. Speed = 600. High speeds tend to make
25-
int RAacceleration = 600; // these cheap steppers unprecice
27+
int RAacceleration = 600; // these cheap steppers unprecice
2628
int DECspeed = 800;
2729
int DECacceleration = 400;
2830

31+
// Define some stepper limits to prevent physical damage to the tracker. This assumes that the home
32+
// point (zero point) has been correctly set to be pointing at the celestial pole.
33+
float RAStepperLimit = 15500; // Going much more than this each direction will make the ring fall off the bearings.
34+
35+
// These are for 47N, so they will need adjustment if you're a lot away from that.
36+
// You can use the CTRL menu to find the limits and place them here. I moved it
37+
// down until my lens was horizontal. Not the DEC number. Then move it up until
38+
// the lens is horizontal and note that number. Put those here. Always watch your
39+
// tracker and hit RESET if it approaches a dangerous area.
40+
float DECStepperDownLimit = 10000; // Going much more than this will make the lens collide with the ring
41+
float DECStepperUpLimit = -22000; // Going much more than this is going below the horizon.
42+
2943
// These values are needed to calculate the current position during initial alignment.
30-
int h = 21;
31-
int m = 2;
32-
int s = 25;
44+
int h = 21;
45+
int m = 2;
46+
int s = 25;
3347
// You get these values by calculating 24h minus the current (not J2000) RA of Polaris.
3448
// This changes slightly over weeks, so adjust every couple of months.
3549
// This value is from 27.Nov.19, I suggest next adjustment in mid 2020
3650
// The same could be done for the DEC coordinates but they dont change significantly for the next 5 years
51+
52+
// Comment this out to save some code space
53+
//#define DEBUG_MODE
54+
55+
// Uncomment this to support the heating menu
56+
//#define SUPPORT_HEATING

Software/Arduino code/OpenAstroTracker/a_inits.ino

Lines changed: 47 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -5,90 +5,78 @@
55
#include <AccelStepper.h>
66
#include <LiquidCrystal.h>
77
#include <SoftwareSerial.h>
8+
89
#define HALFSTEP 8
910
#define FULLSTEP 4
1011

1112
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
1213
//SoftwareSerial BT(10,11);
1314

15+
// RA Motor pins
1416
#define motorPin1 2 // IN1 auf ULN2003 driver 1 // 2 / 22
1517
#define motorPin2 3 // IN2 auf ULN2003 driver 1 // 3 / 24
1618
#define motorPin3 11 // IN3 auf ULN2003 driver 1 // 11 / 26
1719
#define motorPin4 12 // IN4 auf ULN2003 driver 1 // 12 / 28
1820

21+
// DEC Motor pins
1922
#define motorPin11 15 // IN1 auf ULN2003 driver 2
2023
#define motorPin12 16 // IN2 auf ULN2003 driver 2
2124
#define motorPin13 17 // IN3 auf ULN2003 driver 2
2225
#define motorPin14 18 // IN4 auf ULN2003 driver 2
2326

27+
// LCD shield buttons
2428
#define btnRIGHT 0
2529
#define btnUP 1
2630
#define btnDOWN 2
2731
#define btnLEFT 3
2832
#define btnSELECT 4
2933
#define btnNONE 5
3034

35+
// Menu IDs
3136
#define RA_Menu 0
3237
#define DEC_Menu 1
3338
#define HA_Menu 2
3439
#define Polaris_Menu 3
3540
#define Heat_Menu 4
3641
#define Calibration_Menu 5
3742
#define Control_Menu 6
43+
#define Home_Menu 7
3844

39-
int lcd_key = 0;
40-
int adc_key_in = 0;
41-
int read_LCD_buttons() {
42-
adc_key_in = analogRead(0);
43-
if (adc_key_in > 1000) return btnNONE;
44-
if (adc_key_in < 50) return btnRIGHT;
45-
if (adc_key_in < 250) return btnUP;
46-
if (adc_key_in < 450) return btnDOWN;
47-
if (adc_key_in < 600) return btnLEFT;
48-
if (adc_key_in < 920) return btnSELECT;
49-
//return btnNONE;
50-
}
51-
52-
// Adjust the given number by the given adjustment, wrap around the limits.
53-
// Limits are inclusive, so they represent the lowest and highest valid number.
54-
int adjustWrap(int current, int adjustBy, int minVal, int maxVal)
55-
{
56-
current += adjustBy;
57-
if (current > maxVal) current -= (maxVal + 1);
58-
if (current < minVal) current += (maxVal + 1);
59-
return current;
60-
}
61-
62-
// Adjust the given number by the given adjustment, clamping to the limits.
63-
// Limits are inclusive, so they represent the lowest and highest valid number.
64-
int adjustClamp(int current, int adjustBy, int minVal, int maxVal)
65-
{
66-
current += adjustBy;
67-
if (current > maxVal) current = maxVal;
68-
if (current < minVal) current = minVal;
69-
return current;
70-
}
71-
72-
int adjustSecond(int current, int adjustBy) {
73-
return adjustWrap(current, adjustBy, 0, 59);
74-
}
75-
76-
int adjustMinute(int current, int adjustBy) {
77-
return adjustWrap(current, adjustBy, 0, 59);
78-
}
79-
80-
int adjustHour(int current, int adjustBy) {
81-
return adjustWrap(current, adjustBy, 0, 23);
82-
}
83-
84-
String inString = "";
85-
int controlDisplay =0;
86-
45+
// Stepper control for RA and DEV.
46+
// TRK is used for live tracking and runs in parallel with RA.
47+
// GUIDE is used for Stellarium control
8748
AccelStepper stepperRA(FULLSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
8849
AccelStepper stepperDEC(HALFSTEP, motorPin11, motorPin13, motorPin12, motorPin14);
8950
AccelStepper stepperTRK(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4); //yes, this is the same motor as stepperRA, dont ask why
9051
AccelStepper stepperGUIDE(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
9152

53+
int lcd_key = 0; // The current key state
54+
int adc_key_in = 0; // The analog value of the keys
55+
56+
String inString = "";
57+
58+
int calDelay = 150; // The current delay when changing calibration value. The longer a button is depressed, the samller this gets.
59+
60+
bool waitForButtonRelease = false; // When a button is pressed should we wait for its release before another loop?
61+
62+
// Variables for use in the CONTROL menu
63+
int StateMaskDEC = 0x0011; // Is the DEC stepper running?
64+
int StateMaskUp = 0x0001; // Is the DEC stepper moving upwards?
65+
int StateMaskDown = 0x0010; // Is the DEC stepper moving downwards?
66+
int StateMaskRA = 0x1100; // Is the RA stepper running?
67+
int StateMaskLeft = 0x0100; // Is the RA stepper moving left (CW)?
68+
int StateMaskRight = 0x1000; // Is the RA stepper moving right (CCW)?
69+
70+
int controlState = 0x0000; // The current state of the steppers (combination of above values)
71+
int controlDisplay = 0; // How many loop cycles left before updating the display
72+
bool inControlMode = false; // Is manual control enabled
73+
74+
int lastKey = btnNONE; // The key state when we last came through the loop
75+
76+
float totalDECMove = 0; // The number of DEC steps we asked for
77+
float totalRAMove = 0;
78+
bool isUnreachable = false;
79+
9280
//String inCmd;
9381
//String inputString = "";
9482
//String commandString = "";
@@ -116,15 +104,9 @@ int mPolarisPosition;
116104
int tracking = 1;
117105
float trackingspeed;
118106

119-
//RA stuff
120-
int hourRA=0;
121-
int minRA = 0;
122-
int secRA = 0;
107+
// RA stuff
123108
float moveRA;
124109
int RAselect;
125-
int hourRAprint;
126-
int minRAprint;
127-
int secRAprint;
128110

129111
//DEC stuff
130112
int degreeDEC;
@@ -134,19 +116,13 @@ float moveDEC;
134116
int DECselect;
135117
int printdegDEC;
136118

137-
//Hour correction
138-
int hourHA = 0;
139-
int minHA = 0;
119+
//Hour stuff
140120
int HAselect;
141-
int hHAcorrection;
142-
int mHAcorrection = -5 ; //wenn minus dann hHAcorrection -1
143-
int sHAcorrection;
144-
int hourHAzeit;
145-
int minHAzeit;
146121

147-
int heatselect;
148-
int RAheat = 0;
149-
int DECheat = 1;
122+
// HEAT menu settings
123+
int heatselect; // Which stepper are we changing?
124+
int RAheat = 0; // Are we heating the RA stepper?
125+
int DECheat = 0; // Are we heating the DEC stepper?
150126

151127
//Stellarium
152128
char current_RA[9];
@@ -156,10 +132,11 @@ int HAm_save;
156132
float slew_RA;
157133
float slew_DEC;
158134

159-
int rightArrow = 4;
135+
// LCD special chars
160136
int leftArrow = 3;
137+
int rightArrow = 4;
161138

162-
byte DEG[8] = {
139+
byte DegreesBitmap[8] = {
163140
B01100,
164141
B10010,
165142
B10010,
@@ -170,7 +147,7 @@ byte DEG[8] = {
170147
B00000
171148
};
172149

173-
byte min[] = {
150+
byte MinutesBitmap[] = {
174151
B10000,
175152
B10000,
176153
B10000,
@@ -181,7 +158,7 @@ byte min[] = {
181158
B00000
182159
};
183160

184-
byte sec[] = {
161+
byte SecondsBitmap[] = {
185162
B10100,
186163
B10100,
187164
B10100,

Software/Arduino code/OpenAstroTracker/b0_functions.ino

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,87 @@
1+
2+
int read_LCD_buttons() {
3+
adc_key_in = analogRead(0);
4+
if (adc_key_in > 1000) return btnNONE;
5+
if (adc_key_in < 50) return btnRIGHT;
6+
if (adc_key_in < 250) return btnUP;
7+
if (adc_key_in < 450) return btnDOWN;
8+
if (adc_key_in < 600) return btnLEFT;
9+
if (adc_key_in < 920) return btnSELECT;
10+
}
11+
12+
// Adjust the given number by the given adjustment, wrap around the limits.
13+
// Limits are inclusive, so they represent the lowest and highest valid number.
14+
int adjustWrap(int current, int adjustBy, int minVal, int maxVal)
15+
{
16+
current += adjustBy;
17+
if (current > maxVal) current -= (maxVal + 1);
18+
if (current < minVal) current += (maxVal + 1);
19+
return current;
20+
}
21+
22+
// Adjust the given number by the given adjustment, clamping to the limits.
23+
// Limits are inclusive, so they represent the lowest and highest valid number.
24+
int adjustClamp(int current, int adjustBy, int minVal, int maxVal)
25+
{
26+
current += adjustBy;
27+
if (current > maxVal) current = maxVal;
28+
if (current < minVal) current = minVal;
29+
return current;
30+
}
31+
32+
// Adjust the given seconds by the given adjustment, wrapping around.
33+
int adjustSecond(int current, int adjustBy) {
34+
return adjustWrap(current, adjustBy, 0, 59);
35+
}
36+
37+
// Adjust the given minutes by the given adjustment, wrapping around.
38+
int adjustMinute(int current, int adjustBy) {
39+
return adjustWrap(current, adjustBy, 0, 59);
40+
}
41+
42+
// Adjust the given hour by the given adjustment, wrapping around.
43+
int adjustHour(int current, int adjustBy) {
44+
return adjustWrap(current, adjustBy, 0, 23);
45+
}
46+
47+
// Clamp the given number to the limits.
48+
// Limits are inclusive, so they represent the lowest and highest valid number.
49+
long clamp(long current, long minVal, long maxVal)
50+
{
51+
if (current > maxVal) current = maxVal;
52+
if (current < minVal) current = minVal;
53+
return current;
54+
}
55+
56+
// Clamp the given number to the limits.
57+
// Limits are inclusive, so they represent the lowest and highest valid number.
58+
float clamp(float current, float minVal, float maxVal)
59+
{
60+
if (current > maxVal) current = maxVal;
61+
if (current < minVal) current = minVal;
62+
return current;
63+
}
64+
65+
#ifdef DEBUG_MODE
166
void log(const char* input) {
267
Serial.println(input);
368
Serial.flush();
469
}
570

71+
void log(String input) {
72+
Serial.println(input);
73+
Serial.flush();
74+
}
75+
676
void logv(const char* input, ...) {
777
va_list argp;
878
va_start(argp, input);
9-
// Serial.println("HERE");
1079
Serial.println(formatArg(input, argp));
1180
Serial.flush();
1281
va_end(argp);
1382

1483
}
84+
#endif
1585

1686
String format(const char* input, ...) {
1787
va_list argp;
@@ -22,7 +92,7 @@ String format(const char* input, ...) {
2292
}
2393

2494
String formatArg(const char* input, va_list args) {
25-
char achBuffer[256];
95+
char achBuffer[128];
2696
char*p = achBuffer;
2797

2898
for (const char* i = input; *i != 0; i++) {
@@ -38,8 +108,8 @@ String formatArg(const char* input, va_list args) {
38108
break;
39109

40110
case 'c': {
41-
byte b = (byte) (va_arg(args, int) && 0x00FF);
42-
*p++ = (char)b;
111+
char *ch = va_arg(args, char*);
112+
*p++ = *ch;
43113
}
44114
break;
45115

0 commit comments

Comments
 (0)