Scheduling Installation / Boot-up Sequence for 10x Steppers in Storefront

Status
Not open for further replies.

jingleby

Member
I am finalizing an installation involving 10x stepper motors on a 24V PSU and trying to wrap my head around how to schedule the performance as it is in a storefront window.

For previous installations (involving LEDs) I simply used a WeMo smart outlet and turned on the plug at defined times. Is this an issue? I worry switching on 24v to 10x steppers is quite the burst of electricity.

Up until now I've found plugging in the PSU sometimes results in everything working normally once the Teensy loads up (3 sec), and other times it requires that I unplug/plug the USB OR reset the Teensy. I'm not sure why this is the case but suspect it has to do with everything getting powered at the same time versus sequentially.

Appreciate any input. For context, here is the WIP code:

Code:
#include <Wire.h>
#include <StepControl.h>

unsigned long targetInterval = 5000; // read speed from master
unsigned long pulsePerSec = 1000000/targetInterval;

//Step, Dir
Stepper M1(15, 14), M3(17, 16), M5(1, 0), M7(21, 20);
StepControl<> controller;   // Use default settings 

constexpr int spr = 16*200; // 3200 steps per revolution
int acceleration = 1500;
int pullInSpeed = 100;
const byte numMotors = 4;
int microSteps = 4; 
int PPR = 5000; //pulses per rotation wo microstepping

//int targetDist[numMotors] = {100}; //50x decent
int targetDist[numMotors] = {30*spr}; //50x decent
//int MaxSpeed[numMotors] = {50000};
//int MaxSpeed[numMotors] = {1*PPR*microSteps};
int MaxSpeed[numMotors] = {8000};

int scene = 0;

int speed_high = 0;
int speed_low = 1;
int acc_high = 2;
int acc_low = 3;

// SCL/SDA Stuff
byte b[3];  //byte array
byte buff[10];
bool flag1 = LOW; 

void setup() {
  delay(2000);
  Wire.begin(9);                // join i2c bus with address #8
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);           // start serial for output
  delay(2000);

  Stepper* motorSet_A[] = {&M1, &M3, &M5, &M7};
  for (int i = 0; i < numMotors; i++) {
    motorSet_A[i]->setPullInSpeed(pullInSpeed);
    motorSet_A[i]->setAcceleration(acceleration);
  }
  
}

void loop() {
  delay(2000);
  Stepper* motorSet_A[] = {&M1, &M3, &M5, &M7};
  
  scene = 0;
    switch (scene){
      case 0:                 
        M1.setMaxSpeed(MaxSpeed[0]);
        M3.setMaxSpeed(MaxSpeed[0]);
        M5.setMaxSpeed(MaxSpeed[0]);
        M7.setMaxSpeed(MaxSpeed[0]);;
        M1.setTargetRel(targetDist[0]);
        M3.setTargetRel(targetDist[0]);
        M5.setTargetRel(targetDist[0]);
        M7.setTargetRel(targetDist[0]);
        
        for (int i = 0; i < numMotors; i++) {                    // loop through all motors in motorSet_A...
//          motorSet_A[i]->setTargetRel(targetDist[i]);                // ... set targets to 0...
//          motorSet_A[i]->setMaxSpeed(MaxSpeed[i]);
          Serial.print(i); Serial.print(": MaxSpeed "); Serial.println(MaxSpeed[i]);
          Serial.print(i); Serial.print(": targetDist "); Serial.println(targetDist[i]);
        }
        
        controller.move(motorSet_A);
        
        break;
//      default:
//        Serial.println("error");
//        break;
    }
//  lastScene = scene; 
//  }
 
    if (flag1 == HIGH){
      if (b[0] == '*')
      {
        targetInterval = (b[1] << 8) | b[2]; 
        pulsePerSec = 1000000/targetInterval; //OLD SPEED STUFF
//        Serial.print("Slave Speed: ");
//        Serial.println(targetInterval, DEC); //target speed
        flag1 = LOW;
      }
    }
  controller.move(motorSet_A);
  delay(5000);
}

void receiveEvent(int howMany){
  for (int i = 0; i < howMany; i++){
    b[i] = Wire.read();
  }
  flag1 = HIGH;
}
 
Status
Not open for further replies.
Back
Top