I've modified the first lump of stepper code ...nothing that will fix the problem.... I've simply moved the serial print block up the code and added in a set start position for the stepper.
NOTE:- I never used or programmed steppers.
This should give you something to see on the screen.... but I suspect that it will be static.
However ...try it ...press the buttons on the phone and wiggle the stick..see if ANYTHING changes on the serial monitor screen.
#define VERSION "\n\nAndroTest V2.0 - @kas2014\ndemo for V5.x App"
#include "SoftwareSerial.h"
#include <Stepper.h>
#define rxPin 2
#define txPin 3
// change this to the number of steps on your motor
#define STEPSREV 2047 // 64(fullsteps) * 64 (reduction ratio)= 4096
#define COIL1_A 11
#define COIL2_A 9
#define COIL3_A 10
#define COIL4_A 8
#define COIL1_B 4 // ??? PIN NUMBERS GUESSED
#define COIL2_B 5
#define COIL3_B 6
#define COIL4_B 7
#define ENER_A 13 //Motor A Status led
//#define ENER_B ? //Motor B Status led do you wish a seperate one?
#define TIMEOUT 3000 //Turns off after 3 secs of inactivity.
// create an instance of the stepper class, specifying
// the number of steps per revolution and pins atached to motor coils.
Stepper myStepperA(STEPSREV, COIL1_A, COIL2_A, COIL3_A, COIL4_A);
Stepper myStepperB(STEPSREV, COIL1_B, COIL2_B, COIL3_B, COIL4_B);
int PotValA;
int PotValB;
int pos_A = 1024; // stepper A position(0-4096)->(0-360°) CENTERED
int pos_B = 1024; // stepper B position (0-4096)->(0-360°)CENTERED
unsigned long stamp_A = 0; // last A move time stamped.
unsigned long stamp_B = 0; // last B move time stamped.
#define STX 0x02
#define ETX 0x03
//#define ledPin 13
#define SLOW 750 // Datafields refresh rate (ms)
#define FAST 250 // Datafields refresh rate (ms)
SoftwareSerial mySerial(rxPin,txPin); // BlueTooth module: pin#2=TX pin#3=RX
byte cmd[8] = {
0, 0, 0, 0, 0, 0, 0, 0}; // bytes received
byte buttonStatus = 0; // first Byte sent to Android device
long previousMillis = 0; // will store last time Buttons status was updated
long sendInterval = SLOW; // interval between Buttons status transmission (milliseconds)
String displayStatus = "xxxx"; // message to Android device
void setup() {
PotValA = 1023;
PotValB = 1023;
Serial.begin(57600);
mySerial.begin(57600); // 57600 = max value for softserial
pinMode(txPin, OUTPUT);
pinMode(rxPin, INPUT);
myStepperA.setSpeed(4); // set the motor speed to 4 RPM
myStepperB.setSpeed(4); // set the motor speed to 4 RPM
pinMode(ENER_A , OUTPUT);
// pinMode(ENER_B , OUTPUT);
Serial.println(VERSION);
while(mySerial.available()) mySerial.read(); // empty RX buffer
}
void loop() {
if(mySerial.available()) { // data received from smartphone
delay(2);
cmd[0] = mySerial.read();
if(cmd[0] == STX) {
int i=1;
while(mySerial.available()) {
delay(1);
cmd[i] = mySerial.read();
if(cmd[i]>127 || i>7) break; // Communication error
if((cmd[i]==ETX) && (i==2 || i==7)) break; // Button or Joystick data
i++;
}
if (i==2) getButtonState(cmd[1]); // 3 Bytes ex: < STX "C" ETX >
else if(i==7) getJoystickState(cmd); // 6 Bytes ex: < STX "200" "180" ETX >
}
if(abs(PotValA - pos_A)> 4){ //if diference is greater than 4 steps.
if((PotValA - pos_A)> 0){
digitalWrite(ENER_A, HIGH); //Motor ENER_Agized.
myStepperA.step(1); // move one step to the right.
pos_A++;
}
if((PotValA - pos_A)< 0){
digitalWrite(ENER_A, HIGH); //Motor ENER_Agized.
myStepperA.step(-1); // move one step to the left.
pos_A--;
}
stamp_A = millis(); // stamp actual time.
}
if(abs(PotValB - pos_B)> 4){ //if diference is greater than 4 steps.
if((PotValB - pos_B)> 0){
digitalWrite(ENER_A, HIGH); //Motor ENER_Agized. ******** ENER_A led used ...change to ENER_B if required and define another led number
myStepperB.step(1); // move one step to the right.
pos_B++;
}
if((PotValB - pos_B)< 0){
digitalWrite(ENER_A, HIGH); //Motor ENER_Agized.******** ENER_A led used ...change to ENER_B if required and define another led number
myStepperB.step(-1); // move one step to the left.
pos_B--;
}
stamp_B = millis(); // stamp actual time.
}
else {
if((millis() - stamp_A) > TIMEOUT){ //Turn Off coils after TIMEOUT.
digitalWrite(COIL1_A, LOW);
digitalWrite(COIL2_A, LOW);
digitalWrite(COIL3_A, LOW);
digitalWrite(COIL4_A, LOW);
digitalWrite(ENER_A, LOW); //Motor de-ENER_Agized.
if((millis() - stamp_B) > TIMEOUT)//Turn Off coils after TIMEOUT.
digitalWrite(COIL1_B, LOW);
digitalWrite(COIL2_B, LOW);
digitalWrite(COIL3_B, LOW);
digitalWrite(COIL4_B, LOW);
digitalWrite(ENER_A, LOW);//Motor de-ENER_Agized.Motor ********* ENER_A led used ...change to ENER_B if required and define another led number
}
}
}
sendBlueToothData();
Serial.print("PotValA");
Serial.print(" : ");
Serial.print(PotValA);
Serial.print(" : ");
Serial.print("pos_A");
Serial.print(" : ");
Serial.print(pos_A);
Serial.print(" : ");
Serial.print("PotValB");
Serial.print(" : ");
Serial.print(PotValB);
Serial.print(" : ");
Serial.print("pos_B");
Serial.print(" : ");
Serial.println(pos_B);
}
void sendBlueToothData() {
static long previousMillis = 0;
long currentMillis = millis();
if(currentMillis - previousMillis > sendInterval) { // send data back to smartphone
previousMillis = currentMillis;
// Data frame transmitted back from Arduino to Android device:
// < 0X02 Buttons state 0X01 DataField#1 0x04 DataField#2 0x05 DataField#3 0x03 >
// < 0X02 "01011" 0X01 "120.00" 0x04 "-4500" 0x05 "Motor enabled" 0x03 > // example
mySerial.print((char)STX); // Start of Transmission
mySerial.print(getButtonStatusString());
mySerial.print((char)0x1); // buttons status feedback
mySerial.print(GetdataInt1());
mySerial.print((char)0x4); // datafield #1
mySerial.print(GetdataFloat2());
mySerial.print((char)0x5); // datafield #2
mySerial.print(displayStatus); // datafield #3
mySerial.print((char)ETX); // End of Transmission
}
}
String getButtonStatusString() {
String bStatus = "";
for(int i=0; i<6; i++) {
if(buttonStatus & (B100000 >>i)) bStatus += "1";
else bStatus += "0";
}
return bStatus;
}
int GetdataInt1() { // Data dummy values sent to Android device for demo purpos_Ae
static int i= -30; // Replace with your own code
i ++;
if(i >0) i = -30;
return i;
}
float GetdataFloat2() { // Data dummy values sent to Android device for demo purpos_Ae
static float i=50; // Replace with your own code
i-=.5;
if(i <-50) i = 50;
return i;
}
void getJoystickState(byte data[8]) {
int joyX = (data[1]-48)*100 + (data[2]-48)*10 + (data[3]-48); // obtain the Int from the ASCII representation
int joyY = (data[4]-48)*100 + (data[5]-48)*10 + (data[6]-48);
joyX = joyX - 200; // Offset to avoid
joyY = joyY - 200; // transmitting negative numbers
if(joyX<-100 || joyX>100 || joyY<-100 || joyY>100) return; // commmunication error
PotValA = map (joyX,-100,100,0,2047);// Map joyX range in the stepper range motor 1
PotValB = map (joyY,-100,100,0,2047);// Map joyY range in the stepper range motor 2
}