I'm trying to connect a chiller to an arduino nano via tx/rx RS232 pins and poll the temperature.
The datasheet of the chiller specifies that the commands must be sent in hex (eg: CA 00 01 20 00 DE) before the chiller will respond with a similarly formatted answer.
Hardware wise, I have the nano hooked up to an MAX232 Transceiver which connects to the chiller via a spliced RS232 Cable
Coding wise i'm not really sure the best way to send these commands (rather new to serial communications)
what i've got so far is something along these lines:
Stuff to consider:
Grounds connected?
Correct serial configuration? 9600,8,N,1 is what you now have.
Need "Null Modem" connection, Rx-Tx, Tx-Rx ?
RTS/CTS Handshake?
Does command string need lineend(s), \n and/or \r, in correct order ?
I just checked the Nano and, as you say, it only has one hardware serial port.
That means you will have to use the SoftwareSerial library to communicate with the chiller. You can't communicate with two devices on the same serial connection. SoftwarSerial allows you to use a couple of other pins for Rx and Tx for talking to the chiller.
From a quick look at the datasheet it does indeed just need bytes of data so the style you already have
Finally figured out the problem
Turns out the datasheet i've been trying to use is not the right one (exact same make and model of chiller, different control panel >_<)
This is the correct one.
These commands are specified in ASCII, however am I able to convert them to hex and send them that way still?
EDIT:
Finally got it to work!! Thanks to everyone for all of the help, this a great community here
I'm communicating with a chiller using softwareSerial on an arduino nano
After a command is received by the chiller, it sends a confirmation. The trouble I have is reading in this confirmation after the command is sent because the time between the arrival of the confirmation varies.
adding delay(1500) works most of the time for most commands, but its hit-or-miss
@daflippymaster,
Let's keep the topic on track please.
You're comm's are pretty slow.
Could you connect Rx in parallel to an interrupt pin, and capture micros() in the ISR and then process the data?
Do you mean use the interrupt to find how long the confirmation took to arrive? Or do you mean use the interrupt to actually display the data once it comes in?
EDIT: Got it working, I was forgetting the 'my' in front of while(!Serial.available());
For some reason when this function is called, it causes the serial monitor to freeze up and it won't respond until i've uploaded a completely different sketch a couple times to the arduino
The bug seems to be occurring somewhere around the "while(!mySerial.available());" and I can't for the life of me figure out whats wrong. No errors when compiling.
void SetSetpoint(){
String SetPoint;
byte command[10];
char temp[8];
char Start[]={'S','S'};
char End[]={'\r'};
char answer[8];
Serial.println("Enter a temperature between -30.00 and +150.00C");
while(!Serial.available());
Serial.readBytesUntil('\r',temp,6);
SetPoint+=Start;
SetPoint+=temp;
//SetPoint+=End;
SetPoint.getBytes(command,8);
mySerial.write(command,8);
while(!mySerial.available());
mySerial.readBytesUntil('\r',answer,6);
Serial.println(answer);
Serial.println(SetPoint);
}
This is like a delay() of unknown length. Try to rewrite your code so that it is not needed - unless you really want the Arduino to be completely inactive until some data is received.
Serial.readBytesUntil('\r',temp,6);
And this is not much better because the Arduino can do nothing useful until all the data has arrived.
If you look at the Arduino code here (Reply #4) you will see how the Serial data can be collected byte by byte without holding up other stuff.
Its not too incredibly critical that the arduino not be tied up waiting for data, and this is one instance where it needs to wait for input from the user.
After a little more debugging it looks like the arduino freezes right after the "mySerial.write"
Using a logic analyzer, the correct data is being sent expect for at the very end. The last byte is a null character instead of a carriage return, which I think might be the problem