To start programming the stepper motor control, I did some tests having the stepper motor turning the drum at different pulse frequencies.

 

Checking some other rotary growing systems I found that it normally takes 30 to 45 minutes to give a complete turn. I found it very slow (about 0.025 RPM). The beauty of having a stepper motor is that we can virtually set it at any speed below its maximum RPM.

 

I decided to physically check the drum RPM applying different pulse frequencies to the stepper controller and measure the turn time. Doing this test I could get the constant relation in between pulse width (ms) and the actual drum RPM.

 

Below is the code for the testing. I set different pulse frequencies at different pins so I shift the pulse wire through the pins and measured the rotation time.

 

 

 

//Pulses pins 13, 9 & 8 at different frequencies

 

 

const int pulsePin13 = 13;             // pin 13 @ 1000ms (on board LED)

const long interval13 = 1000;          // interval at which to pulse pin (milliseconds)

int pinState13 = LOW;                  // set pinState to 0

unsigned long previousMillis13 = 0;    // store last time pin was updated

 

 

const int pulsePin8 = 8;              // pin 8 @ 50ms

const long interval8 = 50;            // interval at which to pulse pin (milliseconds)

int pinState8 = LOW;                  // set pinState to 0

unsigned long previousMillis8 = 0;    // store last time pin was updated

 

 

 

 

 

 

 

//Pin13

  if (currentMillis - previousMillis13 >= interval13) {

    // save the last pulse time

    previousMillis13 = currentMillis;

 

 

    // if the pin is off turn it on and vice-versa:

    if (pinState13 == LOW) {

      pinState13 = HIGH;

 

const int pulsePin9 = 9;              // pin 9 @ 100ms

const long interval9 = 100;           // interval at which to pulse pin (milliseconds)

int pinState9 = LOW;                  // set pinState to 0

unsigned long previousMillis9 = 0;    // store last time pin was updated

    } else {

      pinState13 = LOW;

    }

 

 

    // set the pin with the pinState of the variable:

    digitalWrite(pulsePin13, pinState13);

  }

 

 

//Pin9

  if (currentMillis - previousMillis9 >= interval9) {

    // save the last pulse time

    previousMillis9 = currentMillis;

 

 

    // if the pin is off turn it on and vice-versa:

    if (pinState9 == LOW) {

      pinState9 = HIGH;

    } else {

      pinState9 = LOW;

    }

 

 

    // set the pin with the pinState of the variable:

    digitalWrite(pulsePin9, pinState9);

  }

 

 

//Pin8

  if (currentMillis - previousMillis8 >= interval8) {

    // save the last pulse time

    previousMillis8 = currentMillis;

 

 

    // if the pin is off turn it on and vice-versa:

    if (pinState8 == LOW) {

      pinState8 = HIGH;

    } else {

      pinState8 = LOW;

    }

 

 

    // set the pin with the pinState of the variable:

    digitalWrite(pulsePin8, pinState8);

  }

 

 

 

 

void setup() {

 

    pinMode(pulsePin13, OUTPUT);

    pinMode(pulsePin9, OUTPUT);

    pinMode(pulsePin8, OUTPUT);

      

}

 

 

void loop() {

 

 

  unsigned long currentMillis = millis();

 

}

 

The results are the following:

Pin 8: 50ms - 1m 15s per turn = 0.8RPM = 48RPH

Pin 9: 100ms - 2m 30s per turn = 0.4RPM = 24RPH

(I didn't take the time for 1000ms, it would take ages and I was happy with the consistency of the previous results)

 

This gives us an inversely proportional relation of 40. Therefore, dividing 40 for the required RPM, we can get the interval to set the program to give the required pulses.

 

As the drum will normally be set to under 1 RPM, seeing such small RPM values might be awkward so I am using RPH "Rotation per Hour".

 

At this stage will limit the range to be set from 1 RPH to 60 RPH (1 RPM). I don't need anything faster than 1 RPM but I might want to try the balearicdynamics suggestion injecting more gravity to the plants in the future. I am not sure about the results but it sounds fun.

 

Maybe in the future, we could also have a database with the best turning speed for the different group of plants so it can be easily set once we start a new cycle.

 

Below is a table with some values relating RPM, RPH and pulse interval.

 

RPMRPHPulse Interval (ms)
0.016712400
0.033321200
0.16400
0.166710240
0.424100
0.84850
16040

 

As we are going to inform the desired RPH through MQTT. Once we get the RPH value we need to calculate the Pulse Interval as following.

 

Pulse Interval = 2400/RPH

 

After all the boring stuff you can relax having a glimpse of the drum turning at 0.8 RPM or 48 RPH