From d7a10f9737d2670097ef90d13fa9450dbaf11bc5 Mon Sep 17 00:00:00 2001 From: mattmcw Date: Tue, 29 Aug 2023 19:48:49 -0400 Subject: [PATCH] Enable different modes of stepping by using the settings pins. Previously was causing odd behavior because they were being used for LEDs. --- .../McopyProjector.cpp | 39 ++++++++++++++++++- ino/mcopy_projector_firmware/McopyProjector.h | 13 ++++--- .../mcopy_projector_firmware.ino | 21 +++++++--- 3 files changed, 60 insertions(+), 13 deletions(-) diff --git a/ino/mcopy_projector_firmware/McopyProjector.cpp b/ino/mcopy_projector_firmware/McopyProjector.cpp index 92db11a..126c64a 100644 --- a/ino/mcopy_projector_firmware/McopyProjector.cpp +++ b/ino/mcopy_projector_firmware/McopyProjector.cpp @@ -2,9 +2,14 @@ #include "McopyProjector.h" -McopyProjector::McopyProjector (AccelStepper takeup, AccelStepper feed) { +McopyProjector::McopyProjector (AccelStepper takeup, AccelStepper feed, uint8_t takeupSettingA, uint8_t takeupSettingB, uint8_t feedSettingA, uint8_t feedSettingB) { _takeup = takeup; _feed = feed; + + _takeupSettingA = takeupSettingA; + _takeupSettingB = takeupSettingB; + _feedSettingA = feedSettingA; + _feedSettingB = feedSettingB; } void McopyProjector::begin () { @@ -15,6 +20,8 @@ void McopyProjector::begin () { _feed.setMaxSpeed(_speed); _feed.setSpeed(_speed); _feed.setAcceleration(1000.0); + + setStepperMode(1); } void McopyProjector::setDirection (bool dir) { @@ -80,3 +87,33 @@ void McopyProjector::loop () { } } } + +//https://wiki.iteadstudio.com/Arduino_Dual_Step_Motor_Driver_Shield +void McopyProjector::setStepperMode (uint8_t mode) { + switch (mode) { + case 1 : + digitalWrite(_takeupSettingA, LOW); + digitalWrite(_takeupSettingB, LOW); + digitalWrite(_feedSettingA, LOW); + digitalWrite(_feedSettingB, LOW); + break; + case 2 : + digitalWrite(_takeupSettingA, HIGH); + digitalWrite(_takeupSettingB, LOW); + digitalWrite(_feedSettingA, HIGH); + digitalWrite(_feedSettingB, LOW); + break; + case 4 : + digitalWrite(_takeupSettingA, LOW); + digitalWrite(_takeupSettingB, HIGH); + digitalWrite(_feedSettingA, LOW); + digitalWrite(_feedSettingB, HIGH); + break; + case 8 : + digitalWrite(_takeupSettingA, HIGH); + digitalWrite(_takeupSettingB, HIGH); + digitalWrite(_feedSettingA, HIGH); + digitalWrite(_feedSettingB, HIGH); + break; + } +} diff --git a/ino/mcopy_projector_firmware/McopyProjector.h b/ino/mcopy_projector_firmware/McopyProjector.h index 72bcd03..ad98193 100644 --- a/ino/mcopy_projector_firmware/McopyProjector.h +++ b/ino/mcopy_projector_firmware/McopyProjector.h @@ -13,17 +13,17 @@ class McopyProjector { uint8_t _motorSteps = 1600; //microstepped uint8_t _frames = 8; - uint8_t _stepsPerFrame = 25; //round(_motorSteps / _frames); + uint8_t _stepsPerFrame = 50; //round(_motorSteps / _frames); float _speed = 500.0; int64_t _posTakeup = 0; int64_t _posFeed = 0; - const uint8_t FORWARD = 1; //CW - const uint8_t BACKWARD = 0; //CCW - const uint8_t TAKEUP = 0; - const uint8_t FEED = 0; + uint8_t _takeupSettingA = 4; + uint8_t _takeupSettingB = 5; + uint8_t _feedSettingA = 8; + uint8_t _feedSettingB = 9; bool _dir = true; @@ -32,7 +32,7 @@ class McopyProjector { public: - McopyProjector(AccelStepper takeup, AccelStepper feed); + McopyProjector(AccelStepper takeup, AccelStepper feed, uint8_t takeupSettingA, uint8_t takeupSettingB, uint8_t feedSettingA, uint8_t feedSettingB); void begin(); //0 = takeup, 1 = feed void adjust(uint8_t motor, int64_t steps); @@ -40,6 +40,7 @@ class McopyProjector { //true = forward, false = back void frame(bool dir); void setDirection(bool dir); + void setStepperMode(uint8_t mode); void loop(); }; diff --git a/ino/mcopy_projector_firmware/mcopy_projector_firmware.ino b/ino/mcopy_projector_firmware/mcopy_projector_firmware.ino index 49506dd..841d214 100644 --- a/ino/mcopy_projector_firmware/mcopy_projector_firmware.ino +++ b/ino/mcopy_projector_firmware/mcopy_projector_firmware.ino @@ -31,16 +31,20 @@ #define FEED_DIR_PIN 7 #define FEED_STEP_PIN 6 +#define TAKEUP_SETTING_A 4 +#define TAKEUP_SETTING_B 5 +#define FEED_SETTING_A 8 +#define FEED_SETTING_B 9 + AccelStepper takeup(AccelStepper::DRIVER, TAKEUP_STEP_PIN, TAKEUP_DIR_PIN); AccelStepper feed(AccelStepper::DRIVER, FEED_STEP_PIN, FEED_DIR_PIN); -//CAMERA CONSTANTS -const int BUTTON = 7; -const int LED_FWD = 8; -const int LED_BWD = 9; +//PROJECTOR CONSTANTS +const int BUTTON = 10; +const int LED_FWD = 11; +const int LED_BWD = 12; const int PROJECTOR_MOMENT = 240; -const int PROJECTOR_STEPS = 25; //VARIABLES volatile int projectorFrame = -1; @@ -50,7 +54,7 @@ volatile bool direction = true; volatile long start; McopySerial mcopy; -McopyProjector projector(takeup, feed); +McopyProjector projector(takeup, feed, TAKEUP_SETTING_A, TAKEUP_SETTING_B, FEED_SETTING_A, FEED_SETTING_B); void setup () { pins(); @@ -78,6 +82,11 @@ void pins () { pinMode(LED_BWD, OUTPUT); pinMode(BUTTON, INPUT_PULLUP); + pinMode(TAKEUP_SETTING_A, OUTPUT); + pinMode(TAKEUP_SETTING_B, OUTPUT); + pinMode(FEED_SETTING_A, OUTPUT); + pinMode(FEED_SETTING_B, OUTPUT); + digitalWrite(LED_FWD, LOW); digitalWrite(LED_BWD, LOW); }