RS232 Aanderaa Conductivity sensor to Arduino

Hi all

I am on a project to make an instrument to measure salinity at Artic glaciers. We have implemented multiple I2C sensors to do so, but want a new sensor attached for benchmark. However I have problems communicating with it, so I hope you can help me. I am using an Arduino Mega and serial communication.

I am using the Breakout - MAX3232 (SparkFun Transceiver Breakout - MAX3232 - BOB-11189 - SparkFun Electronics).
I have attached a picture of the wiring: Yellow to sensor = RS-232-RXD, green to sensor = RS-232-TXD

The sensor I am using is the Aanderaa Conductivity Sensor 4319.
Datasheet for sensor: https://www.aanderaa.com/media/pdfs/TD263-Condcutivity-sensor-4319.pdf
The specific RS232 protocol is explained from page 27 and forward.

I have some limited experience with the serial/UART communication. I have tried setting up the attached code, but all I get in return is -1’s so it is obviously not working. Have you guys any advice for me?

Thanks in advance. Let me know if you need more information.

Best
Lucas Sandby (Stud. Mech. Eng.)

#define CondSerial Serial3
char message;

void setup()
{
  // Start the console serial port
  Serial.begin(9600);
  while (!Serial);

//Starter C-sensor
  CondSerial.begin(9600);

if(CondSerial.available()>0) {
  message = CondSerial.read();
  Serial.print(message);
}
  
}

void loop()
{

CondSerial.write("Do Sample\r\n");
Serial.println(CondSerial.read());

delay(1000);
}

Cond_test.ino (405 Bytes)

you need to check if something is available before reading (moved/modified your code from setup() to loop(). assume it generates a linefeed

#define CondSerial Serial3
char message;

void setup()
{
  // Start the console serial port
  Serial.begin(9600);
  while (!Serial);

//Starter C-sensor
  CondSerial.begin(9600);
}

void loop()
{
  if(CondSerial.available ()>0) {
    Serial.print (CondSerial.read());
  }
}

not sure what causes the sensor to generate output

Thanks gcjr. I have tried that, so it probably is the syntax/protocol which is wrong, but I think I can manage to figures that out somehow.

But to look at the code for another sec:
So the datasheet says, that the string “Get Data” terminated by Carriage Return and Line Feed will cause the sensor to generate an output. I want it to do that for like every second or so. Shouldn’t it be like:

#define CondSerial Serial3
char message;

void setup()
{
  // Start the console serial port
  Serial.begin(9600);
  while (!Serial);

//Starter C-sensor
  CondSerial.begin(9600);
}

void loop()
{

  CondSerial.write("Get Data \r\n");


  if(CondSerial.available ()>0) {
    Serial.print (CondSerial.read());
  }

  delay(1000);

}

what happens if characters are sent during the delay and overflow the serial buffer

#define CondSerial Serial3

void setup()
{
    // Start the console serial port
    Serial.begin(9600);
    while (!Serial);
    //Starter C-sensor
    CondSerial.begin(9600);
}

void loop()
{
    static unsigned long msecLst = 0;
           unsigned long msec    = millis();

    // send request every second
#define ONE_SECOND 1000
    if (msec - msecLst > ONE_SECOND)  {
        msecLst = msec;
        CondSerial.write("Get Data \r\n");
    }

    // wait for response
    if (CondSerial.available ()>0) {
        Serial.print (CondSerial.read());
    }
}

So true. I believe the coding should be okay, but I still have no response from the sensor. Could it have something to do with the setup. The datasheet says:

The following RS-232 setup should be used: 9600 Baud (which I have set i up through the serial port) 8 Data bits 1 Stop bit No Parity Xon/Xoff Handshake

The parity, stop- and data bits are not entered anywhere, but I guess it is included in the serial.write/read? If it still doesn't work this is correct it must be my way of writing to the sensor, which is wrong.

I appreciate your help Best

describe all the pins you've connected between the Arduino and sensor and the power supply pins?