Serial Comm. using Arduino for temperature reading

Hey all, any help with this is much appreciated. Here’s my setup: I’m using the Arduino to communicate with a temperature monitor (which receives a reading from a PRTD)via serial port. The monitor needs a query of the form “KRDG? [term]” to respond with a kelvin temperature reading, where [term] are terminating characters (line feed and carriage return). The returned value according to the manual will be of the form “+nnnnnn” where n is an integer OR a decimal (temp monitor has 5 digit precision, so it will shift one place when going from <100 to >100). Seems like it ought to be fairly straight forward, but when I run my code (below), I get an output of zeroes. If I make the temp[11] array of the char type, I get unprintable characters. I use 11 elements because the temp monitor transmits one start bit, 7 bits for data in ASCII characters, one parity bit (odd), and one stop bit, plus the null character from the Arduino.

Could the zeroes/unprintable chars be a result of reading form the serial buffer incorrectly? Any advice is much appreciated. If I’ve left something out or need clarification, I’ll tell all I can.

#include <SoftwareSerial.h>
SoftwareSerial mySerial(2,3); //(RX,TX)
int temp[11];  //char array to be temp acquired
int n;  //counting number
void setup()
{
  Serial.begin(9600);
  mySerial.begin(9600);
}
void loop()
{
  mySerial.write("KRDG? \r\n");  //Send query to temp monitor
  while(mySerial.available()>0)
  {
    for(n=0; n<11; ++n)
    {
      temp[n] = mySerial.read();
    }
  }
  for(n=0; n<11; ++n)
  {
    Serial.print(temp[n]);
  }
  Serial.println();
  delay(1000);
}
 while(mySerial.available()>0)
  {
    for(n=0; n<11; ++n)
    {
      temp[n] = mySerial.read();
    }
  }

No. You have checked if you have at least one byte available and then read 11. Won’t work.

http://www.gammon.com.au/serial

Misconception here too:

I use 11 elements because the temp monitor transmits one start bit, 7 bits for data in ASCII characters, one parity bit (odd), and one stop bit, plus the null character from the Arduino.

All that stuff about bits is telling you the protocol that is used to put a single byte on the wire - it says nothing about how many bytes you'll get. The number of bytes received will determine the size of the buffer required (plus one for the null as you observe). +nnnnnn suggests you'll need eight, although I'd add a few extra until you've sorted out what you actually get.

Note also, that you will need to mask out the parity bit - the arduino is not expecting it, so ~half your characters will display as garbage until you do.

Sorry about that confusion. I was looking at one thing and typing another. I understand that Serial.read() gathers one BYTE at a time, rather than individual bits; thus 8 elements per array will suffice.

Note also, that you will need to mask out the parity bit - the arduino is not expecting it, so ~half your characters will display as garbage until you do.

Forgive me for not knowing, but I've looked around with no luck on how to mask out a single bit. I've read concept material and I think I grasp it, but I'm at a loss when coding. Any useful links? I've found the following thread in my search; maybe someone could point out which parts are necessary to the masking?

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1249846069

      temp[n] = mySerial.read() & 0x7F;

Many thanks for the replies thus far. I’ve placed a Serial-TTL converter between the temp monitor and Arduino, so I’m closer to my goal, but I’m still getting garbage output. When I run the code shown here, I get a different number of received bytes every time.

#include <SoftwareSerial.h>
SoftwareSerial mySerial(2,3); //(RX,TX)
int temp[10];  //int array to be temp acquired
int n;  //counting number
void setup()
{
  Serial.begin(9600);
  mySerial.begin(9600);
}
void loop()
{
  mySerial.write("\xCB\x52\xC4\xC7\xBF\x20\x0D\x8A");  //Send query to temp monitor
  n=0;
  while(mySerial.available()>0)
  {
     temp[n] = mySerial.read(); & 0x7F;
     ++n;
  }
  Serial.println(n);
  for(n=0; n<8; ++n)
  {
    Serial.print(temp[n]);
  }
  Serial.println();
  delay(1000);
}

I’ve checked the output of the Arduino on an oscilloscope only and I can see a digital signal being sent, but when I connect it to the temp monitor via the converter I get a very small signal (~300mV). Can anyone see something I’ve missed regarding the Arduino code, or perhaps an electrical limitation with it?

I am currently trying to verify everything with the temp monitor is working properly (the digital readout is working), but I cannot seem to get Hyper Terminal to send the correct query. If anyone knows why it wouldn’t be sending after I check “echo typed characters locally”, I’d love some advice.

  mySerial.write("\xCB\x52\xC4\xC7\xBF\x20\x0D\x8A");  //Send query to temp monitor
  n=0;
  while(mySerial.available()>0)
  {
     temp[n] = mySerial.read(); & 0x7F;
     ++n;
  }

You are expecting a response within nanoseconds of sending the request. Patience is a virtue.

Huh?

     temp[n] = mySerial.read(); & 0x7F;

Lose that semicolon in the middle.

     temp[n] = mySerial.read() & 0x7F;