Skip to content

Commit 4241ade

Browse files
author
openastrotech
committed
add NEMA configurations
1 parent 9890ea0 commit 4241ade

File tree

6 files changed

+107
-24
lines changed

6 files changed

+107
-24
lines changed

Software/Arduino code/OpenAstroTracker/Globals.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ void EEPROMupdate(int loc, byte val);
1010
#define NORTHERN_HEMISPHERE 1
1111

1212
// Time in ms between LCD screen updates during slewing operations
13-
#define DISPLAY_UPDATE_TIME 200
13+
#define DISPLAY_UPDATE_TIME 400
14+
15+
// Stepper selection ///////////
16+
#define RAStepper 1 // 28BYJ-48 = 0 | NEMA = 1
17+
#define DECStepper 0 // 28BYJ-48 = 0 | NEMA = 1
1418

1519
// Make some variables in the sketch files available to the C++ code.
1620
extern bool inSerialControl;

Software/Arduino code/OpenAstroTracker/Mount.cpp

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ void Mount::writePersistentData(int which, int val)
173173
// configureRAStepper
174174
//
175175
/////////////////////////////////
176+
#if RAStepper == 0 // 28BYJ
176177
void Mount::configureRAStepper(byte stepMode, byte pin1, byte pin2, byte pin3, byte pin4, int maxSpeed, int maxAcceleration)
177178
{
178179
_stepperRA = new AccelStepper(stepMode, pin1, pin2, pin3, pin4);
@@ -186,12 +187,28 @@ void Mount::configureRAStepper(byte stepMode, byte pin1, byte pin2, byte pin3, b
186187
_stepperTRK->setMaxSpeed(10);
187188
_stepperTRK->setAcceleration(2500);
188189
}
190+
#endif
191+
#if RAStepper == 1 //NEMA
192+
void Mount::configureRAStepper(byte stepMode, byte pin1, byte pin2, int maxSpeed, int maxAcceleration)
193+
{
194+
_stepperRA = new AccelStepper(stepMode, pin1, pin2);
195+
_stepperRA->setMaxSpeed(maxSpeed);
196+
_stepperRA->setAcceleration(maxAcceleration);
197+
_maxRASpeed = maxSpeed;
198+
_maxRAAcceleration = maxAcceleration;
189199

200+
// Use another AccelStepper to run the RA motor as well. This instance tracks earths rotation.
201+
_stepperTRK = new AccelStepper(DRIVER, pin1, pin2);
202+
_stepperTRK->setMaxSpeed(10);
203+
_stepperTRK->setAcceleration(2500);
204+
}
205+
#endif
190206
/////////////////////////////////
191207
//
192208
// configureDECStepper
193209
//
194210
/////////////////////////////////
211+
#if DECStepper == 0
195212
void Mount::configureDECStepper(byte stepMode, byte pin1, byte pin2, byte pin3, byte pin4, int maxSpeed, int maxAcceleration)
196213
{
197214
_stepperDEC = new AccelStepper(stepMode, pin4, pin3, pin2, pin1);
@@ -200,7 +217,17 @@ void Mount::configureDECStepper(byte stepMode, byte pin1, byte pin2, byte pin3,
200217
_maxDECSpeed = maxSpeed;
201218
_maxDECAcceleration = maxAcceleration;
202219
}
203-
220+
#endif
221+
#if DECStepper == 1
222+
void Mount::configureDECStepper(byte stepMode, byte pin1, byte pin2, int maxSpeed, int maxAcceleration)
223+
{
224+
_stepperDEC = new AccelStepper(stepMode, pin2, pin1);
225+
_stepperDEC->setMaxSpeed(maxSpeed);
226+
_stepperDEC->setAcceleration(maxAcceleration);
227+
_maxDECSpeed = maxSpeed;
228+
_maxDECAcceleration = maxAcceleration;
229+
}
230+
#endif
204231
/////////////////////////////////
205232
//
206233
// getSpeedCalibration
@@ -1111,7 +1138,7 @@ void Mount::calculateRAandDECSteppers(float& targetRA, float& targetDEC) {
11111138
float stepsPerSiderealHour = _stepsPerRADegree * siderealDegreesInHour;
11121139

11131140
// Where do we want to move RA to?
1114-
float moveRA = hourPos * stepsPerSiderealHour / 2;
1141+
float moveRA = hourPos * stepsPerSiderealHour;
11151142

11161143
// Where do we want to move DEC to?
11171144
// the variable targetDEC 0deg for the celestial pole (90deg), and goes negative only.
@@ -1122,7 +1149,7 @@ void Mount::calculateRAandDECSteppers(float& targetRA, float& targetDEC) {
11221149
#endif
11231150

11241151
// We can move 6 hours in either direction. Outside of that we need to flip directions.
1125-
float RALimit = (6.0f * stepsPerSiderealHour / 2);
1152+
float RALimit = (6.0f * stepsPerSiderealHour);
11261153

11271154
// If we reach the limit in the positive direction ...
11281155
if (moveRA > RALimit) {
@@ -1132,7 +1159,7 @@ void Mount::calculateRAandDECSteppers(float& targetRA, float& targetDEC) {
11321159

11331160
// ... turn both RA and DEC axis around
11341161
float oldRA = moveRA;
1135-
moveRA -= long(12.0f * stepsPerSiderealHour / 2);
1162+
moveRA -= long(12.0f * stepsPerSiderealHour);
11361163
moveDEC = -moveDEC;
11371164
#ifdef DEBUG_MODE
11381165
logv("Mount::CalcSteppers: Adjusted Target Step pos RA: %f, DEC: %f", moveRA, moveDEC);
@@ -1145,7 +1172,7 @@ void Mount::calculateRAandDECSteppers(float& targetRA, float& targetDEC) {
11451172
#endif
11461173
// ... turn both RA and DEC axis around
11471174
float oldRA = moveRA;
1148-
moveRA += long(12.0f * stepsPerSiderealHour / 2);
1175+
moveRA += long(12.0f * stepsPerSiderealHour);
11491176
moveDEC = -moveDEC;
11501177
#ifdef DEBUG_MODE
11511178
logv("Mount::CalcSteppers: Adjusted Target Step pos RA: %f, DEC: %f", moveRA, moveDEC);

Software/Arduino code/OpenAstroTracker/Mount.hpp

Lines changed: 13 additions & 1 deletion
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
@@ -41,10 +42,21 @@ class Mount {
4142
Mount(int stepsPerRADegree, int stepsPerDECDegree, LcdMenu* lcdMenu);
4243

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

4652
// Configure the DEC stepper motor.
53+
#if DECStepper == 0
4754
void configureDECStepper(byte stepMode, byte pin1, byte pin2, byte pin3, byte pin4, int maxSpeed, int maxAcceleration);
55+
#endif
56+
#if DECStepper == 1
57+
void configureDECStepper(byte stepMode, byte pin1, byte pin2, int maxSpeed, int maxAcceleration);
58+
#endif
59+
4860

4961
// Get the current RA tracking speed factor
5062
float getSpeedCalibration();

Software/Arduino code/OpenAstroTracker/OpenAstroTracker.ino

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

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

27-
// This is how many steps your 28BYJ-48 stepper needs for a full rotation. It is almost always 4096.
28-
// This code drives the steppers in halfstep mode for TRK and DEC, and full step for RA
29-
float StepsPerRevolution = 4096;
27+
28+
// RA stepper //////////////////////////////////////////////////////////////////////////////////
29+
30+
31+
// This is how many steps your stepper needs for a full rotation. E.g. a 0.9° stepper in Fullstep has 400,
32+
// with 1/16 microstepping it has 6400. If youre using the 28BYJ, use 4096
33+
float RAStepsPerRevolution = 6400;
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,13 +61,13 @@ 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

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

61-
int RAspeed = 400; // You can change the speed and acceleration of the steppers here. Max. Speed = 600. High speeds tend to make
62-
int RAacceleration = 600; // these cheap steppers unprecice
69+
int RAspeed = 1000; // You can change the speed and acceleration of the steppers here. Max. Speed = 600. High speeds tend to make
70+
int RAacceleration = 1600; // these cheap steppers unprecice
6371
int DECspeed = 800;
6472
int DECacceleration = 400;
6573

Software/Arduino code/OpenAstroTracker/a_inits.ino

Lines changed: 21 additions & 9 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

@@ -50,15 +51,26 @@
5051
#endif
5152

5253
#ifdef __AVR_ATmega2560__ // Arduino Mega
53-
#define RAmotorPin1 22 // IN1 auf ULN2003 driver 1 // 2 / 22
54-
#define RAmotorPin3 24 // IN2 auf ULN2003 driver 1 // 3 / 24
55-
#define RAmotorPin2 26 // IN3 auf ULN2003 driver 1 // 11 / 26
56-
#define RAmotorPin4 28 // IN4 auf ULN2003 driver 1 // 12 / 28
57-
58-
#define DECmotorPin1 30 // IN1 auf ULN2003 driver 2
59-
#define DECmotorPin3 32 // IN3 auf ULN2003 driver 2
60-
#define DECmotorPin2 34 // IN2 auf ULN2003 driver 2
61-
#define DECmotorPin4 36 // IN4 auf ULN2003 driver 2
54+
#if RAStepper == 0 // 28BYJ
55+
#define RAmotorPin1 22 // IN1 auf ULN2003 driver 1 // 2 / 22
56+
#define RAmotorPin3 24 // IN2 auf ULN2003 driver 1 // 3 / 24
57+
#define RAmotorPin2 26 // IN3 auf ULN2003 driver 1 // 11 / 26
58+
#define RAmotorPin4 28 // IN4 auf ULN2003 driver 1 // 12 / 28
59+
#endif
60+
#if RAStepper == 1 // NEMA
61+
#define RAmotorPin1 22
62+
#define RAmotorPin2 24
63+
#endif
64+
#if DECStepper == 0 // 28BYJ
65+
#define DECmotorPin1 30 // IN1 auf ULN2003 driver 2
66+
#define DECmotorPin3 32 // IN3 auf ULN2003 driver 2
67+
#define DECmotorPin2 34 // IN2 auf ULN2003 driver 2
68+
#define DECmotorPin4 36 // IN4 auf ULN2003 driver 2
69+
#endif
70+
#if DECStepper == 1 // NEMA
71+
#define DECmotorPin1 26
72+
#define DECmotorPin2 28
73+
#endif
6274
#endif
6375

6476
// Menu IDs

Software/Arduino code/OpenAstroTracker/b_setup.ino

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ WifiControl wifiControl(&mount, &lcdMenu);
1010
#endif
1111

1212
void setup() {
13+
//Enable Microstepping
14+
//RA
15+
digitalWrite(40, HIGH);
16+
digitalWrite(42, HIGH);
17+
digitalWrite(44, HIGH);
18+
//DEC
19+
digitalWrite(41, HIGH);
20+
digitalWrite(43, HIGH);
21+
digitalWrite(45, HIGH);
22+
1323

1424
//debug_init();
1525
//Serial.begin(38400);
@@ -37,9 +47,19 @@ void setup() {
3747
// Configure the mount
3848

3949
// Set the stepper motor parameters
50+
#if RAStepper == 0 && DECStepper == 0
4051
mount.configureRAStepper(FULLSTEP, RAmotorPin1, RAmotorPin2, RAmotorPin3, RAmotorPin4, RAspeed, RAacceleration);
4152
mount.configureDECStepper(HALFSTEP, DECmotorPin1, DECmotorPin2, DECmotorPin3, DECmotorPin4, DECspeed, DECacceleration);
42-
53+
#endif
54+
#if RAStepper == 1 && DECStepper == 0
55+
mount.configureRAStepper(DRIVER, RAmotorPin1, RAmotorPin2, RAspeed, RAacceleration);
56+
mount.configureDECStepper(HALFSTEP, DECmotorPin1, DECmotorPin2, DECmotorPin3, DECmotorPin4, DECspeed, DECacceleration);
57+
#endif
58+
#if RAStepper == 1 && DECStepper == 1
59+
mount.configureRAStepper(DRIVER, RAmotorPin1, RAmotorPin2, RAspeed, RAacceleration);
60+
mount.configureDECStepper(DRIVER, DECmotorPin1, DECmotorPin2, DECspeed, DECacceleration);
61+
#endif
62+
4363
// The mount uses EEPROM storage locations 0-10 that it reads during construction
4464

4565
// Read other persisted values and set in mount

0 commit comments

Comments
 (0)