I am trying to create a control system that reads in a temperature using a thermocouple and transmits that to an arduino micro-controller, which then sends a signal to a stepper motor control box (Anaheim Automation DPD75601) which then controls the motion of the step motor and has it move a certain number of steps based on the difference between current temperature and previous temperature.
In order to do so, we needed to interface the Arduino with the stepper control box. This involved using a TTL comm to RS232 adapter. We have implemented the adapter and successfully interfaced with HyperTerminal on another computer via the RS232 port. We are able to send the string output command (needed to send to the control box) to HyperTerminal and print the command on the HyperTerminal dialog box.
However, when we connect the Arduino to the control box via the RS232 serial port (on the control box), we are not getting any communication. We THINK there might be a discrepency between the format of the string the Arduino is outputting and the format of the string the stepper control box needs to move the motor.
I am copying and pasting the code: I realize my if/else statement could be condensed.. going to do that soon.
/*
This example code is in the public domain.
/
//establish LED pin, used for troubleshooting
int led = 13;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 38400 bits per second (required by control box):
Serial.begin(38400);
pinMode(led,OUTPUT);
//Serial.println(" ");
}
//initializing initial temperature value (called prevVal) needed to decide # of steps to move
float prevVal=70;
// the loop routine runs over and over again forever:
void loop() {
//LED blink code, used for troubleshooting
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
//print headings
// read the temperature transmitter input on analog pin 0:
int sensorValue = analogRead(A0);
//converting Arudino 0-1023 to Voltage Value supplied by TC
float voltVal = sensorValue0.004887585;
//converting voltVal to tempVal
float tempVal = (60.162voltVal)-131.88;
//calculating degrees Fahrenheit difference between now and last reading
float tempDegreeMove=tempVal-prevVal;
//converting from degrees Fahrenheit to circumferential degrees
float circumfDegreeMove=4.5tempDegreeMove;
//calculating number of steps needed to move
int numSteps= circumfDegreeMove/1.8;
//calculating the temperature value needle is at, taking into account
//rounding of numSteps.. in other words, prevVal is the temperature the
//needle moves to, but not necessarily the temperature that was just
//deciphered by the Arduino
prevVal=prevVal+(numSteps*(1.8/4.5));
//if statement deciding if motion is clockwise or counterclockwise
if (numSteps > 0)
{
//String commands sent to control box
Serial.println("@0.");
Serial.println("@0T0");
Serial.println("@0B400");
Serial.println("@0M600");
//(+) for clockwise
Serial.println("@0+");
String string1 ="@0N";
//making number of steps positive number... direction controlled in "@0+"
int numStepsAbs = abs(numSteps);
String string2 = String(numStepsAbs);
String string3 = string1+string2;
Serial.println(string3);
Serial.println("@0CH100");
Serial.println("@0G");
}
//negatives..
else
{
Serial.println("@0.");
Serial.println("@0T0");
Serial.println("@0B400");
Serial.println("@0M600");
Serial.println("@0-");
String string1 = "@0N";
int numStepsAbs = abs(numSteps);
String string2 = String(numStepsAbs);
String string3 = string1+string2;
Serial.println(string3);
Serial.println("@0CH100");
Serial.println("@0G");
}
delay(10000); // delay in between reads
}