Hi.
This might seem like a weird thing to do, but I'm trying to use an existing code written for DC-motors, and replace them with steppers. The reason is that I want to control some precise peristaltic pumps. These pumps come with both DC and tepper motors, and I have the stepper version. They are quite expensive, so I'd like to be able to use the ones I have.
For now, all the steppers do is buzz a little every second within the timeframe they are suppose to be running, and getting very hot.
I have tested my circuits with a simpler code to verify that everything works.
I'm using a Arduino Mega 2560 R3 board, and two A4988 stepper drivers. The motors are these:https://mm.digikey.com/Volume0/opasdata/d220001/medias/docus/571/PG20L-D20-HHC0.pdf
I have adjusted the current limiter on the A4988 boards to match the 350mA of the motors.
The code also controls some solenoid valves, but they are not connected for now.
I'm in way over my head, so any help is appreciated.
The code I'm trying to modify is this:
```cpp
//Code for Arduino Mega1
//This code
//1. Take commands from PC and execute (liquid transfer pumps).
//2. Send voltage to gas sparger.
//3. Send voltage to pumps for liquid transfer.
//The following time stamps are all in seconds
//Start is earlier for inlet than outlet to compensate for evaporation
//For this, we just need food to colon and colon to waste
//Feed every 4 hours. Transfers for all reactors will happen at exact same time
//Inputting ~4.5ml of content and outputing ~4ml of content
//This ensures an overall ~30 hours retention time
#define TimeStamp1 14000//Food to start inputting liquid into reactors
#define TimeStamp2 14040 //Food to start removing liquid from reactors
#define TimeStamp3 14280 //Time to stop both transfers
#define TimeStamp4 14400 //Time to reset the system
// Define pin connections & motor's steps per revolution
const int dirPin = 2;
const int stepPin = 3;
const int stepsPerRevolution =3636;
char instring[4]; //This stores the input from the Serial port
int instring_int[4]; //This stores the input from the Serial port converted to integer
int i;
int k;
int j;//Placeholder counter
int inputpin = 3; //pin for multichannel pump of adding liquid into reactors
int outputpin = 2;//pin for multichannel pump of removing liquid from reactors
//only 1 pin used because of using 6-channel pump
int spargerpin = 10;
int timer = 0;//Timer for liquid transfer
int tspa = 0; // Timer for sparging gas
void setup() {
Serial.begin(9600);
pinMode (inputpin,OUTPUT);
pinMode (outputpin,OUTPUT);
pinMode (spargerpin,OUTPUT);
//Serial.setTimeout(50);
}
void loop() {
//Now, check if we need liquid transfer
if ((timer > TimeStamp1) && (timer < TimeStamp3)){
digitalWrite(inputpin,HIGH);
Serial.println("Pumping1");
}
else {
digitalWrite(inputpin,LOW);
}
if ((timer > TimeStamp2) && (timer < TimeStamp3)){
digitalWrite(outputpin,HIGH);
}
else {
digitalWrite(outputpin,LOW);
}
if (timer > TimeStamp4){
timer = 0;
}
timer += 1;
//Now, handles the gas sparging
if (tspa > 5){//reset timer if it exceeds 5 secs
tspa = 0;
}
tspa += 1;
if (tspa > 3 && tspa < 5){//At the fifth second, sparge
digitalWrite(spargerpin,HIGH);
}
else {
digitalWrite(spargerpin,LOW);
}
//After everything, wait for 1 sec
delay(1000);
Serial.println(timer);
}
My attempt at incorporating steppers looks like this:
//Code for Arduino Mega1
//This code
//1. Take commands from PC and execute (liquid transfer pumps).
//2. Send voltage to gas sparger.
//3. Send voltage to pumps for liquid transfer.
//The following time stamps are all in seconds
//Start is earlier for inlet than outlet to compensate for evaporation
//For this, we just need food to colon and colon to waste
//Feed every 4 hours. Transfers for all reactors will happen at exact same time
//Inputting ~4.5ml of content and outputing ~4ml of content
//This ensures an overall ~30 hours retention time
#define TimeStamp1 5 //Food to start inputting liquid into reactors
#define TimeStamp2 70 //Food to start removing liquid from reactors
#define TimeStamp3 120 //Time to stop both transfers
#define TimeStamp4 240 //Time to reset the system
char instring[4]; //This stores the input from the Serial port
int instring_int[4]; //This stores the input from the Serial port converted to integer
int i;
int k;
int j; //Placeholder counter
//only 1 pin used because of using 6-channel pump
int spargerpin = 10;
//Pin1 is input and Pin2 output
const int dirPin1 = 2; //direction of input pump
const int dirPin2 = 4; //direction of output pump
const int stepPin1 = 3; //Pump for adding liquid to reactors
const int stepPin2 = 5; //Pump for removing liquid from reactors.
const int stepsPerRevolution = 3636;
int timer = 0; //Timer for liquid transfer
int tspa = 0; // Timer for sparging gas
void setup() {
Serial.begin(9600);
// Declare pins as Outputs
pinMode(stepPin1, OUTPUT);
pinMode(dirPin1, OUTPUT);
pinMode(stepPin2, OUTPUT);
pinMode(dirPin2, OUTPUT);
//Serial.setTimeout(50);
}
void loop() {
//Now, check if we need liquid transfer
if ((timer > TimeStamp1) && (timer < TimeStamp3)) {
// Set motor direction clockwise
// Spin motor
digitalWrite(dirPin1, HIGH);
for (int x = 0; x < stepsPerRevolution; x++)
digitalWrite(stepPin1, HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin1, LOW);
delayMicroseconds(1000);
Serial.println("Pumping1");
} else {
//digitalWrite(dirPin1, HIGH);
digitalWrite(stepPin1, LOW);
}
if ((timer > TimeStamp2) && (timer < TimeStamp3)) {
// Spin motor
digitalWrite(dirPin2, HIGH);
for (int x = 0; x < stepsPerRevolution; x++)
digitalWrite(dirPin2, HIGH);
digitalWrite(stepPin2, HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin2, LOW);
delayMicroseconds(1000);
Serial.println("Pumping2");
} else {
digitalWrite(stepPin2, LOW);
}
if (timer > TimeStamp4) {
timer = 0;
}
timer += 1;
//Now, handles the gas sparging
if (tspa > 5) { //reset timer if it exceeds 5 secs
tspa = 0;
}
tspa += 1;
if (tspa > 3 && tspa < 5) { //At the fifth second, sparge
digitalWrite(spargerpin, HIGH);
Serial.println("Sparging");
} else {
digitalWrite(spargerpin, LOW);
}
//After everything, wait for 1 sec
delay(1000);
Serial.println(timer);
}
