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 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);
}
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);
}
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.