Well, I tried it again and nothing seems to be communicating. I do not have S1 pin or S1 gnd plugged into arduino as I am not using it at this time, just S2. I have a picture of why work but can’t seem to get it onto my computer.
I have the pin6 from arudino going to first pin on S2, nothing connected to middle pin of S2 and ground going to back pin of S2.
I have the actuator into M2A and M2B and the 12V into +/- and also the wiper motor into M1A/M1B. I flip the switch to power on and am using the code below, I marked the areas of concern with ‘****’.
[b]*****#include "BMSerial.h"
//receive and transmit. Not receiving so transmit pin 6 should go to roboclaw S2
BMSerial brake(5,6);********[/b]
//pin 3 should go to roboclaw S1
//BMSerial steer(2,3);
#define PWML 10 //PWM pin for Low, do not need to direction of motor.
#define PWMH 11 //PWM pin for High, needed for direction of motor
#define DIR 12 //non PWM pin for direction control
//#define SWTCH 8; //switch enable for forward/reverse
//read till end of packet
char string[8]; //long enough string for value
byte var; //store each byte
int index = 0;
int val; //store the integer
char ltr; //store the character
boolean started=false;
boolean ended=false;
void setup()
{
Serial.begin(9600);
[b] ********* brake.begin(9600);[/b]
//steer.begin(9600);
}
void loop()
{
while(Serial.available() > 0)
{
var=Serial.read();
// less than, <, starts the current value
if(var=='<')
{
started = true;
index=0;
string[index]='\0';
}
//break out of while loop when '>' received
else if(var=='>')
{
ended = true;
break;
}
//if value has started, create string
else if(started)
{
string[index]=var;
index++;
string[index]='\0';
}
}
//if you have value, grab character to determine which pot and create integer
if(started && ended)
{
ltr = ' ';
if(strlen(string) > 0)
{
ltr = string[0];
string[0] = ' ';
val=atoi(string);
}
//Steering algorithm
if(ltr == 'S')
{
Serial.print("This is letter: ");
Serial.println(ltr);
Serial.print("<");
Serial.print(val);
Serial.println(">");
//Test wiper motor, channel 1: 1 full rev, 0-stop, 127-forward
//steerval=map(val,0,1023,0,127);
//steer.write(steerval);
/* double steeringInput = val; //Need to use the value calculated above
steeringInput = constrain(steeringInput, steeringpotMin, steeringpotMax);
double targetPos = map(steeringInput, steeringpotMin, steeringpotMax, -100, 100);
double wheelInput = analogRead(potPin3);
wheelInput = constrain(wheelInput, wheelpotMin, wheelpotMax);
double currentPos = map(wheelInput, wheelpotMin, wheelPotMax, -100,100);
int error = targetPos - currentPos;
//If error > 10 then apply new turn position
if(error > 10)
{
int Kp = 2; //Will change depending upon testing
int Turn = Kp*error;
Turn = constrain(Turn,-63,63);
Turn = Turn+64;
Serial.print("Turn position: ");
Serial.print(Turn);
steer.write(Turn);
//send to roboclaw, value between 1 and 127
//roboclaw datasheet: 1 = fullreverse, 127=fullforward, 64=stop
}*/
}
[b]*************** //Brake
else if(ltr == 'B')
{
Serial.print("This is letter: ");
Serial.println(ltr);
Serial.print("<");
Serial.print(val);
Serial.println(">");
//int Bval = map(val, 0 , 1023, 0,);
if(val > 250) //check this number as seems to record B without being pressing sometimes and want to make
//it where it has high enough value to not engage brake while not pressed and motor running
{
//stopFunction(); //cut the motor while applying brake
//send 128 to the roboclaw Channel 2 to apply full brake
Serial.println("Brake is applied");
brake.write(128);
}
else
{
//send 255 to roboclaw to not brake
Serial.println("Brake is not applied");
brake.write(255);
}
}*********************[/b]
//Throttle
else if(ltr == 'G')
{
Serial.print("This is letter: ");
Serial.println(ltr);
Serial.print("<");
Serial.print(val);
Serial.println(">");
//map down to 1/4 of full speed of 36V motor
int PWMval = map(val, 0,1023, 0,64); //PWM between 0-255 with 255 being max
//if(digitalRead(switchPin)==HIGH)
if (PWMval>0)
{
Serial.print("Speed Value Forward: ");
Serial.println(PWMval);
motorForward(PWMval);
}
}
//next time
started = false;
ended = false;
index = 0;
string[index]='\0';
}
}
//Implement to shut down motor
void stopFunction()
{
analogWrite(PWML, 0);
analogWrite(PWMH, 0);
}
//Forard of the motor
void motorForward(int PWMforward)
{
digitalWrite(DIR, LOW);
digitalWrite(PWML, HIGH);
analogWrite(PWMH, PWMforward);
}