Skip to content

Commit 2ce8720

Browse files
Merge pull request #36 from OpenAstroTech/NEMA-steppers
Merge the NEMA stepper support branch into develop
2 parents 81ebc09 + 9594d4a commit 2ce8720

File tree

10 files changed

+123
-7
lines changed

10 files changed

+123
-7
lines changed
-26.4 KB
Binary file not shown.

Software/Arduino code/OpenAstroTracker/Globals.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ void EEPROMupdate(int loc, byte val);
1212
// Time in ms between LCD screen updates during slewing operations
1313
#define DISPLAY_UPDATE_TIME 200
1414

15+
// Stepper selection ///////////
16+
#define RA_Stepper_TYPE 0 // 28BYJ-48 = 0 | NEMA = 1
17+
#define DEC_Stepper_TYPE 0 // 28BYJ-48 = 0 | NEMA = 1
18+
1519
// Make some variables in the sketch files available to the C++ code.
1620
extern bool inSerialControl;
1721
extern String version;

Software/Arduino code/OpenAstroTracker/Mount.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ Mount::Mount(int stepsPerRADegree, int stepsPerDECDegree, LcdMenu* lcdMenu) {
6767
_stepperWasRunning = false;
6868
_totalDECMove = 0;
6969
_totalRAMove = 0;
70+
#if RA_Stepper_TYPE == 0
7071
_backlashCorrectionSteps = 16;
72+
#else
73+
_backlashCorrectionSteps = 0;
74+
#endif
7175
_correctForBacklash = false;
7276
_slewingToHome = false;
7377
readPersistentData();
@@ -188,6 +192,7 @@ void Mount::writePersistentData(int which, int val)
188192
// configureRAStepper
189193
//
190194
/////////////////////////////////
195+
#if RA_Stepper_TYPE == 0 // 28BYJ
191196
void Mount::configureRAStepper(byte stepMode, byte pin1, byte pin2, byte pin3, byte pin4, int maxSpeed, int maxAcceleration)
192197
{
193198
#if NORTHERN_HEMISPHERE
@@ -209,12 +214,30 @@ void Mount::configureRAStepper(byte stepMode, byte pin1, byte pin2, byte pin3, b
209214
_stepperTRK->setMaxSpeed(10);
210215
_stepperTRK->setAcceleration(2500);
211216
}
217+
#endif
218+
219+
#if RA_Stepper_TYPE == 1 //NEMA
220+
void Mount::configureRAStepper(byte stepMode, byte pin1, byte pin2, int maxSpeed, int maxAcceleration)
221+
{
222+
_stepperRA = new AccelStepper(stepMode, pin1, pin2);
223+
_stepperRA->setMaxSpeed(maxSpeed);
224+
_stepperRA->setAcceleration(maxAcceleration);
225+
_maxRASpeed = maxSpeed;
226+
_maxRAAcceleration = maxAcceleration;
227+
228+
// Use another AccelStepper to run the RA motor as well. This instance tracks earths rotation.
229+
_stepperTRK = new AccelStepper(DRIVER, pin1, pin2);
230+
_stepperTRK->setMaxSpeed(10);
231+
_stepperTRK->setAcceleration(2500);
232+
}
233+
#endif
212234

213235
/////////////////////////////////
214236
//
215237
// configureDECStepper
216238
//
217239
/////////////////////////////////
240+
#if DEC_Stepper_TYPE == 0 // 28BYJ
218241
void Mount::configureDECStepper(byte stepMode, byte pin1, byte pin2, byte pin3, byte pin4, int maxSpeed, int maxAcceleration)
219242
{
220243
#if NORTHERN_HEMISPHERE
@@ -227,7 +250,18 @@ void Mount::configureDECStepper(byte stepMode, byte pin1, byte pin2, byte pin3,
227250
_maxDECSpeed = maxSpeed;
228251
_maxDECAcceleration = maxAcceleration;
229252
}
253+
#endif
230254

255+
#if DEC_Stepper_TYPE == 1 // NEMA
256+
void Mount::configureDECStepper(byte stepMode, byte pin1, byte pin2, int maxSpeed, int maxAcceleration)
257+
{
258+
_stepperDEC = new AccelStepper(stepMode, pin2, pin1);
259+
_stepperDEC->setMaxSpeed(maxSpeed);
260+
_stepperDEC->setAcceleration(maxAcceleration);
261+
_maxDECSpeed = maxSpeed;
262+
_maxDECAcceleration = maxAcceleration;
263+
}
264+
#endif
231265
/////////////////////////////////
232266
//
233267
// getSpeedCalibration
@@ -1300,7 +1334,11 @@ void Mount::calculateRAandDECSteppers(float& targetRA, float& targetDEC) {
13001334
float stepsPerSiderealHour = _stepsPerRADegree * siderealDegreesInHour;
13011335

13021336
// Where do we want to move RA to?
1337+
#if RA_Stepper_TYPE == 0
13031338
float moveRA = hourPos * stepsPerSiderealHour / 2;
1339+
#else
1340+
float moveRA = hourPos * stepsPerSiderealHour;
1341+
#endif
13041342

13051343
// Where do we want to move DEC to?
13061344
// the variable targetDEC 0deg for the celestial pole (90deg), and goes negative only.
@@ -1312,7 +1350,11 @@ void Mount::calculateRAandDECSteppers(float& targetRA, float& targetDEC) {
13121350
#endif
13131351

13141352
// We can move 6 hours in either direction. Outside of that we need to flip directions.
1353+
#if RA_Stepper_TYPE == 0
13151354
float RALimit = (6.0f * stepsPerSiderealHour / 2);
1355+
#else
1356+
float RALimit = (6.0f * stepsPerSiderealHour);
1357+
#endif
13161358

13171359
// If we reach the limit in the positive direction ...
13181360
if (moveRA > RALimit) {
@@ -1322,7 +1364,11 @@ void Mount::calculateRAandDECSteppers(float& targetRA, float& targetDEC) {
13221364

13231365
// ... turn both RA and DEC axis around
13241366
float oldRA = moveRA;
1367+
#if RA_Stepper_TYPE == 0
13251368
moveRA -= long(12.0f * stepsPerSiderealHour / 2);
1369+
#else
1370+
moveRA -= long(12.0f * stepsPerSiderealHour);
1371+
#endif
13261372
moveDEC = -moveDEC;
13271373
#ifdef DEBUG_MODE
13281374
logv("Mount::CalcSteppersIn: Adjusted Target Step pos RA: %f, DEC: %f", moveRA, moveDEC);
@@ -1335,7 +1381,11 @@ void Mount::calculateRAandDECSteppers(float& targetRA, float& targetDEC) {
13351381
#endif
13361382
// ... turn both RA and DEC axis around
13371383
float oldRA = moveRA;
1384+
#if RA_Stepper_TYPE == 0
13381385
moveRA += long(12.0f * stepsPerSiderealHour / 2);
1386+
#else
1387+
moveRA += long(12.0f * stepsPerSiderealHour);
1388+
#endif
13391389
moveDEC = -moveDEC;
13401390
#ifdef DEBUG_MODE
13411391
logv("Mount::CalcSteppersPost: Adjusted Target. Moved RA, inverted DEC");

Software/Arduino code/OpenAstroTracker/Mount.hpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#define HALFSTEP 8
2828
#define FULLSTEP 4
29+
#define DRIVER 1
2930

3031
#define RA_STEPS 1
3132
#define DEC_STEPS 2
@@ -42,10 +43,20 @@ class Mount {
4243
Mount(int stepsPerRADegree, int stepsPerDECDegree, LcdMenu* lcdMenu);
4344

4445
// Configure the RA stepper motor. This also sets up the TRK stepper on the same pins.
45-
void configureRAStepper(byte stepMode, byte pin1, byte pin2, byte pin3, byte pin4, int maxSpeed, int maxAcceleration);
46+
#if RA_Stepper_TYPE == 0
47+
void configureRAStepper(byte stepMode, byte pin1, byte pin2, byte pin3, byte pin4, int maxSpeed, int maxAcceleration);
48+
#endif
49+
#if RA_Stepper_TYPE == 1
50+
void configureRAStepper(byte stepMode, byte pin1, byte pin2, int maxSpeed, int maxAcceleration);
51+
#endif
4652

4753
// Configure the DEC stepper motor.
48-
void configureDECStepper(byte stepMode, byte pin1, byte pin2, byte pin3, byte pin4, int maxSpeed, int maxAcceleration);
54+
#if DEC_Stepper_TYPE == 0
55+
void configureDECStepper(byte stepMode, byte pin1, byte pin2, byte pin3, byte pin4, int maxSpeed, int maxAcceleration);
56+
#endif
57+
#if DEC_Stepper_TYPE == 1
58+
void configureDECStepper(byte stepMode, byte pin1, byte pin2, int maxSpeed, int maxAcceleration);
59+
#endif
4960

5061
// Get the current RA tracking speed factor
5162
float getSpeedCalibration();

Software/Arduino code/OpenAstroTracker/OpenAstroTracker.ino

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ String version = "V1.7.01";
2424

2525
// See NORTHERN_HEMISPHERE in Globals.h if you not in the northern hemisphere
2626

27+
28+
// RA stepper //////////////////////////////////////////////////////////////////////////////////
29+
30+
2731
// This is how many steps your 28BYJ-48 stepper needs for a full rotation. It is almost always 4096.
2832
// This code drives the steppers in halfstep mode for TRK and DEC, and full step for RA
29-
float StepsPerRevolution = 4096;
33+
float RAStepsPerRevolution = 4096;
3034

3135
// The radius of the surface that the belt runs on (in V1 of the ring) was 168.24mm.
3236
// Belt moves 40mm for one stepper revolution (2mm pitch, 20 teeth).
@@ -43,8 +47,12 @@ float StepsPerRevolution = 4096;
4347
// V2: 1131
4448
#define RACircumference 1131
4549

46-
int RAStepsPerDegree = (RACircumference / (RAPulleyTeeth * 2.0) * StepsPerRevolution / 360.0); // V2 Ring has belt in a groove and belt runs on bearings
50+
int RAStepsPerDegree = (RACircumference / (RAPulleyTeeth * 2.0) * RAStepsPerRevolution / 360.0); // V2 Ring has belt in a groove and belt runs on bearings
51+
52+
53+
// DEC stepper //////////////////////////////////////////////////////////////////////////////////
4754

55+
float DECStepsPerRevolution = 4096;
4856

4957
// Belt moves 40mm for one stepper revolution (2mm pitch, 20 teeth).
5058
// DEC wheel is 2 x PI x 90mm circumference which is 565.5mm
@@ -53,7 +61,7 @@ int RAStepsPerDegree = (RACircumference / (RAPulleyTeeth * 2.0) * StepsPerRevolu
5361
// So there are 160.85 steps/degree (57907/360)
5462
#define DecPulleyTeeth 20
5563

56-
int DECStepsPerDegree = (565.5 / (DecPulleyTeeth * 2.0) * StepsPerRevolution / 360.0);
64+
int DECStepsPerDegree = (565.5 / (DecPulleyTeeth * 2.0) * DECStepsPerRevolution / 360.0);
5765

5866
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.
5967

Software/Arduino code/OpenAstroTracker/a_inits.ino

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#define HALFSTEP 8
1515
#define FULLSTEP 4
16+
#define DRIVER 1
1617

1718
//SoftwareSerial BT(10,11);
1819

@@ -88,6 +89,7 @@
8889
// Arduino Mega
8990
///////////////////////////////////////////////////////////////////////////
9091
#ifdef __AVR_ATmega2560__ // Arduino Mega
92+
#if RA_Stepper_TYPE == 0 // 28BYJ
9193
// RA Motor pins
9294
#ifdef INVERT_RA_DIR
9395
#define RAmotorPin1 22 // IN1 auf ULN2003 driver 1
@@ -100,8 +102,14 @@
100102
#define RAmotorPin2 24 // IN3 auf ULN2003 driver 1
101103
#define RAmotorPin4 22 // IN4 auf ULN2003 driver 1
102104
#endif
105+
#endif
106+
#if RA_Stepper_TYPE == 1 // NEMA
107+
#define RAmotorPin1 22
108+
#define RAmotorPin2 24
109+
#endif
103110

104111
// DEC Motor pins
112+
#if DEC_Stepper_TYPE == 0 // 28BYJ
105113
#ifdef INVERT_DEC_DIR
106114
#define DECmotorPin1 36 // IN1 auf ULN2003 driver 2
107115
#define DECmotorPin3 34 // IN2 auf ULN2003 driver 2
@@ -114,6 +122,13 @@
114122
#define DECmotorPin4 36 // IN4 auf ULN2003 driver 2
115123
#endif
116124
#endif
125+
#if DEC_Stepper_TYPE == 1 // NEMA
126+
#define DECmotorPin1 32
127+
#define DECmotorPin2 30
128+
#endif
129+
130+
#endif
131+
117132

118133
// Menu IDs
119134
#define RA_Menu 1

Software/Arduino code/OpenAstroTracker/b_setup.ino

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,23 @@ WifiControl wifiControl(&mount, &lcdMenu);
1111

1212
void setup() {
1313

14+
// Microstepping ---------------
15+
#if RA_Stepper_TYPE == 1 // RA driver startup (for TMC2209)
16+
pinMode(41, OUTPUT);
17+
//digitalWrite(43, HIGH); // SPREAD
18+
digitalWrite(41, LOW); // ENABLE
19+
20+
digitalWrite(42, LOW); // MS2
21+
digitalWrite(40, HIGH); // MS1
22+
#endif
23+
#if DEC_Stepper_TYPE == 1 // DEC driver startup (for TMC2209)
24+
pinMode(45, OUTPUT);
25+
digitalWrite(45, LOW); // ENABLE
26+
27+
digitalWrite(46, LOW); // MS2
28+
digitalWrite(44, HIGH); // MS1
29+
#endif
30+
1431
//debug_init();
1532
//Serial.begin(38400);
1633
Serial.begin(57600);
@@ -37,8 +54,19 @@ void setup() {
3754
// Configure the mount
3855

3956
// Set the stepper motor parameters
40-
mount.configureRAStepper(FULLSTEP, RAmotorPin1, RAmotorPin2, RAmotorPin3, RAmotorPin4, RAspeed, RAacceleration);
41-
mount.configureDECStepper(HALFSTEP, DECmotorPin1, DECmotorPin2, DECmotorPin3, DECmotorPin4, DECspeed, DECacceleration);
57+
// Set the stepper motor parameters
58+
#if RA_Stepper_TYPE == 0 && DEC_Stepper_TYPE == 0
59+
mount.configureRAStepper(FULLSTEP, RAmotorPin1, RAmotorPin2, RAmotorPin3, RAmotorPin4, RAspeed, RAacceleration);
60+
mount.configureDECStepper(HALFSTEP, DECmotorPin1, DECmotorPin2, DECmotorPin3, DECmotorPin4, DECspeed, DECacceleration);
61+
#endif
62+
#if RA_Stepper_TYPE == 1 && DEC_Stepper_TYPE == 0
63+
mount.configureRAStepper(DRIVER, RAmotorPin1, RAmotorPin2, RAspeed, RAacceleration);
64+
mount.configureDECStepper(HALFSTEP, DECmotorPin1, DECmotorPin2, DECmotorPin3, DECmotorPin4, DECspeed, DECacceleration);
65+
#endif
66+
#if RA_Stepper_TYPE == 1 && DEC_Stepper_TYPE == 1
67+
mount.configureRAStepper(DRIVER, RAmotorPin1, RAmotorPin2, RAspeed, RAacceleration);
68+
mount.configureDECStepper(DRIVER, DECmotorPin1, DECmotorPin2, DECspeed, DECacceleration);
69+
#endif
4270

4371
// The mount uses EEPROM storage locations 0-10 that it reads during construction
4472

Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)