Go Down

Topic: pH/ORP stamp using UART port (Read 8 times) previous topic - next topic

PaulS

Quote
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.

Quote
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.

Marian

Hello,

I followed Paul's instructions using this little sketch, but when I run it I get always the same value in the Port Monitor: 16961
What's wrong ?

void setup() {
 Serial.begin(9600);
}

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);
 delay(1000);
 }


Many thanks,
Marian

PaulS

You have this code:
Code: [Select]
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.

Marian

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.

cheers,
Marian

PaulS

Quote
Are all this correct ?

Yes it all are.

Quote
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.

Go Up