They seem to work as RS232 using low voltage so no need for any interfacing with an Arduino UART ports.
Where I am a bit confused is the data reading part. It looks like the temperature argument needs to be passed for a temperature corrected pH value; i.e. read(26.5) where 26.5 is the temperature in Celsius.
Would a line like this work with the serial library:
val_pH = Serial.read(26.5) ???
Would a line like this work with the serial library:
val_pH = Serial.read(26.5) ???
No. The Serial.read() function does not take any arguments. It simply reads whatever is on the serial port.
You send the device commands, like "read(someTemp)" using Serial.print() assuming that you have the device connected to the serial port pins. It responds with character data that you read using Serial.read(), one character at a time.
They seem to work as RS232 using low voltage so no need for any interfacing with an Arduino UART ports.
A serial device without the need to use the serial port. How's that working for you?
What I don't is why you made inData a 24 positions vector (why 24 ??)
It needs to be some size. I didn't look at the size of the responses sent back by the sensor, but I don't think they are going to be all that long. If necessary, you can increase the size.
what this line does; inData[index] = '\0';
It adds a NULL to that position in the array (after the last character added). The NULL is necessary to tell the string functions (print(), strlen(), strcmp(), etc.) where the end of the string is.
void loop() {
char inData[24];
byte index = 0;
int ORP;
while (Serial.available() && index <24)
{
inData[index] = Serial.read();
index++;
inData[index] = '\0';
ORP = atoi(inData);
}
Serial.println(ORP);
Suppose that there is no serial data available. I'll explain, in a minute, why this is probably always true.
What does this code do? It prints the value in ORP. What value is in ORP? It's a local variable that is not initialized. So, who knows? It's value is whatever that memory location was last used for.
Local variables are not initialized by default, so YOU must initialize them.
So, why is there no serial data to read? Because you haven't asked the sensor to send you any.
You need to send a request to the sensor, to make it send you a reply.
Paul, thank you very much for your answer.
I have connected the stamp to the Rx/Tx of Arduino and the green led for transmission blinks. I assume somehow serial data is available.
I am not an expert at this (the first time programming for the serial port) so bear with my innocence.
I was under the assumption that the inData cycle will read on bit at a time from the serial device and will store it in this vector. After that I thought that atoi() will convert the char string into a decimal value.
Are all this correct ? Can you please help me understand how to read the ORP from this stamp.
I don't' have the physical ORP probe connected, but the stamp should change the output when the probe pin goes to gnd.
Can you please help me understand how to read the ORP from this stamp.
Sure. First, you request information. Then, you read the response. Like this:
Arduino: "Hey, stamp! What is the temperature there?"
Stamp: "The temperature is mighty cold"
You use Serial.print() to send messages to the stamp. You look at the link you provided way back when, to see what messages to send. I'm pretty sure that "Hey, stamp! What is the temperature there?" isn't valid, but the document you linked to does have the correct messages.
Then, the code that you have will listen for a response. That response might be just an integer value as a string, or it might not. You'll probably want to connect the stamp to a different pair of pins, and use NewSoftSerial to talk to it, so you can use the main serial port to talk to the Serial Monitor, to confirm what you get back from the stamp, before you can figure out how to parse the reply.
As you can see there are some intermittent glitches. It looks like the '\0' is not present all the time. Should I impose inData[23] = 0 ???
And the biggest problem now (at least for me since I have zero experience handling strings) the stamps for some reason respond prefixing the measurements with "ORP=" and "pH=" followed by the numerical value. How can I extract only the numerical value ?
pH and ORP measurement are not instantaneous measurements they are suppose to be averaged over some time.
Many thanks,
Marian
code:
void setup()
{
Serial.begin(9600);
}
void loop()
{
char inData_pH[24];
int index =0;
float pH_val = 0.0;
Serial.println("read(26.0)c");
delay(1000);
while (Serial.available() > 0 && index < 24)
{
inData_pH[index] = Serial.read();
index++;
inData_pH[index] = '\0';
}