Robin2:
You have not posted your latest Arduino code so how can we help?...R
I updated my code on the beginning post but I'll post it in here as well
#include <L298N.h>
#include <Stepper.h>
#include <A4988.h>
// Define Constants
String readString;
unsigned int integerValue=0; // Max value is 65535
char incomingByte;
// Stepper Motor1 Connections to A4988
const int sm1_dirPin = 2; // Direction
const int sm1_stepPin = 3; // Step
// Motor1 steps per rotation
const int sm1_step_rev = 1.8;
int sm1_enPin = 10;
// Stepper Motor2 Connections to A4988
const int sm2_dirPin = 4; // Direction
const int sm2_stepPin = 5; // Step
// Motor2 steps per rotation
const int sm2_step_rev = 1.8;
int sm2_enPin = 11;
// DC Motor A
int enA = 9;
int in1 = 8;
int in2 = 7;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Connected via serial"); // so I can keep track of what is loaded
// For DC Motor setup
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
// Setup the pins as Outputs for Stepper Motor1
pinMode(sm1_stepPin,OUTPUT);
pinMode(sm1_dirPin,OUTPUT);
pinMode(sm1_enPin,OUTPUT);
// Setup the pins as Outputs for Stepper Motor2
pinMode(sm2_stepPin,OUTPUT);
pinMode(sm2_dirPin,OUTPUT);
pinMode(sm2_enPin,OUTPUT);
}
//digitalWrite(sm1_dirpin,HIGH); set to HIGH for CW Stepper Motor1
//digitalWrite(sm1_dirpin,LOW); set to LOW for CCW Stepper Motor1
//digitalWrite(sm2_dirpin,HIGH); set to HIGH for CW Stepper Motor1
//digitalWrite(sm2_dirpin,LOW); set to LOW for CCW Stepper Motor1
//<-------------- DC MOTOR -------------->
void dm1off(){
// Turn off DC motor
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
}
void dm1cw(){
// Turn on DC motor A move CW
analogWrite(enA, 200);
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
// *secs before it moves to the second command.
delay(500);
}
void dm1ccw(){
// Turn on DC motor A move CCW
analogWrite(enA, 200);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
// *secs before it moves to the second command.
delay(500);
}
//<-------------- STEPPER MOTOR1 -------------->
void sm1cw(){
// Set motor direction clockwise case 10785
digitalWrite(sm1_dirPin,HIGH);
}
void sm1ccw(){
// Set motor direction counterclockwise case 42185
digitalWrite(sm1_dirPin,LOW);
}
void sm1on(){
// Spin motor
for(int x = 0; x < (sm1_step_rev * integerValue); x++) {
digitalWrite(sm1_stepPin,HIGH);
delayMicroseconds(1000);
digitalWrite(sm1_stepPin,LOW);
delayMicroseconds(1000);
}
}
//<-------------- STEPPER MOTOR2 -------------->
void sm2cw(){
// Set motor direction clockwise case 10885
digitalWrite(sm2_dirPin,HIGH);
}
void sm2ccw(){
// Set motor direction counterclockwise case 43185
digitalWrite(sm2_dirPin,LOW);
}
void sm2on(){
// Spin motor
for(int x = 0; x < (sm2_step_rev * integerValue); x++) {
digitalWrite(sm2_stepPin,HIGH);
delayMicroseconds(1000);
digitalWrite(sm2_stepPin,LOW);
delayMicroseconds(1000);
}
}
//<-------------- VOID LOOP -------------->
void loop() {
if (Serial.available() > 0) { // something came across serial
integerValue = 0; // throw away previous integerValue
while(1) { // force into a loop until 'n' is received
incomingByte = Serial.read();
if (incomingByte == '\n') break; // exit the while(1), we're done receiving
if (incomingByte == -1) continue; // if no characters are in the buffer read() returns -1
integerValue *= 10; // shift left 1 decimal place
// convert ASCII to integer, add, and shift left 1 decimal place
integerValue = ((incomingByte - 48) + integerValue);
}
Serial.println(integerValue); // Do something with the value
if (integerValue > 0 && integerValue < 201){
sm1on();
sm2on();
}
}
switch(integerValue){
case 50726: // turn off dc motor
dm1off();
break;
case 57393: // move dc motor clockwise
dm1cw();
break;
case 49513: // move dc motor counterclockwise
dm1ccw();
break;
case 10785: // move stepper motor1 clockwise
sm1cw();
digitalWrite(sm2_enPin,HIGH);
digitalWrite(sm1_enPin,LOW);
break;
case 42185: // move stepper motor1 counterclockwise
sm1ccw();
digitalWrite(sm2_enPin,HIGH);
digitalWrite(sm1_enPin,LOW);
break;
case 10885: // move stepper motor2 clockwise
sm2cw();
digitalWrite(sm1_enPin,HIGH);
digitalWrite(sm2_enPin,LOW);
break;
case 43185: // move stepper motor2 counterclockwise
sm2ccw();
digitalWrite(sm1_enPin,HIGH);
digitalWrite(sm2_enPin,LOW);
break;
}
delay(100); // delay in between reads for stability
}