Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

changed to new pololu electronics and 1/16 ms direct drive table

  • Loading branch information...
commit 4d70101b106fedb2001f4e63c5d3dd778699abcc 1 parent 99271e4
@tbuser authored
Showing with 54 additions and 44 deletions.
  1. +54 −44 firmware/firmware.ino
View
98 firmware/firmware.ino
@@ -1,58 +1,67 @@
-int ledPin = 13;
-int laserPin = 2;
-int dirPin = 3;
-int stepPin = 4;
-float gearRatio = 61.0/10.0;
+// define some pins
+//=================
+#define DIR_PIN 3
+#define STEP_PIN 4
+#define ENABLE_PIN 8
+#define SLEEP_PIN 9
+#define MS1_PIN 11
+#define MS2_PIN 12
+#define MS3_PIN 13
+#define LASER_PIN 2
+#define LED_PIN 13
+
+// define stepper
+//===============
+// 200 * 16 microstepping
+#define STEPS_PER_REV 3200
+
+#define RPM 0.5
void setup() {
- pinMode(laserPin, OUTPUT);
- pinMode(dirPin, OUTPUT);
- pinMode(stepPin, OUTPUT);
- pinMode(ledPin, OUTPUT);
+ pinMode(LASER_PIN, OUTPUT);
+ pinMode(DIR_PIN, OUTPUT);
+ pinMode(STEP_PIN, OUTPUT);
+ pinMode(LED_PIN, OUTPUT);
+
+ // initialise the Pololu
+ //==========================
+ digitalWrite(MS1_PIN, HIGH);
+ digitalWrite(MS2_PIN, HIGH);
+ digitalWrite(MS3_PIN, HIGH);
+ digitalWrite(ENABLE_PIN, LOW);
+ digitalWrite(SLEEP_PIN, LOW);
+ delay(100);
Serial.begin(9600);
}
-void rotate(int steps, float speed){
- //rotate a specific number of microsteps (8 microsteps per step) - (negitive for reverse movement)
- //speed is any number from .01 -> 1 with 1 being fastest - Slower is stronger
- int dir = (steps > 0)? HIGH:LOW;
- steps = abs(steps);
-
- digitalWrite(dirPin,dir);
-
- float usDelay = (1/speed) * 70;
-
- for(int i=0; i < steps; i++){
- digitalWrite(stepPin, HIGH);
- delayMicroseconds(usDelay);
-
- digitalWrite(stepPin, LOW);
- delayMicroseconds(usDelay);
- }
-}
-
-void rotateDeg(float deg, float speed){
- //rotate a specific number of degrees (negitive for reverse movement)
- //speed is any number from .01 -> 1 with 1 being fastest - Slower is stronger
- int dir = (deg > 0)? HIGH:LOW;
- digitalWrite(dirPin,dir);
+// speed = rpm
+void rotate(float degrees, float speed) {
+ digitalWrite(SLEEP_PIN, HIGH);
+ digitalWrite(ENABLE_PIN, LOW);
- int steps = abs(deg)*(1/0.225)*gearRatio;
- float usDelay = (1/speed) * 70;
+ int steps_per_second = speed * STEPS_PER_REV / 60;
+ int step_delay = 1000 / steps_per_second;
+ float steps = STEPS_PER_REV * (degrees/360);
+ int dir = (degrees > 0) ? LOW : HIGH;
+
+ digitalWrite(DIR_PIN, dir);
+ delay(100);
for(int i=0; i < steps; i++){
- digitalWrite(stepPin, HIGH);
- delayMicroseconds(usDelay);
-
- digitalWrite(stepPin, LOW);
- delayMicroseconds(usDelay);
+ digitalWrite(STEP_PIN, HIGH);
+ delayMicroseconds(10);
+ digitalWrite(STEP_PIN, LOW);
+ delay(step_delay);
}
+
+ digitalWrite(SLEEP_PIN, LOW);
+ digitalWrite(ENABLE_PIN, HIGH);
}
void laser(boolean state) {
- digitalWrite(ledPin, state);
- digitalWrite(laserPin, state);
+ digitalWrite(LED_PIN, state);
+ digitalWrite(LASER_PIN, state);
}
void loop() {
@@ -67,11 +76,11 @@ void loop() {
laser(true);
Serial.println("OK");
} else if (val == '2') {
- rotateDeg(360, 0.03);
+ rotate(360.0, RPM);
Serial.println("OK");
} else if (val == '3') {
laser(true);
- rotateDeg(360, 0.03);
+ rotate(360.0, RPM);
laser(false);
Serial.println("OK");
} else {
@@ -82,3 +91,4 @@ void loop() {
Serial.flush();
}
+
Please sign in to comment.
Something went wrong with that request. Please try again.