Serial Comm. using Arduino for temperature reading
hey all, appreciated. here's setup: i'm using arduino communicate temperature monitor (which receives reading prtd)via serial port. monitor needs query of form "krdg? [term]" respond kelvin temperature reading, [term] terminating characters (line feed , carriage return). returned value according manual of form "+nnnnnn" n integer or decimal (temp monitor has 5 digit precision, shift 1 place when going <100 >100). seems ought straight forward, when run code (below), output of zeroes. if make temp[11] array of char type, unprintable characters. use 11 elements because temp monitor transmits 1 start bit, 7 bits data in ascii characters, 1 parity bit (odd), , 1 stop bit, plus null character arduino.
could zeroes/unprintable chars result of reading form serial buffer incorrectly? advice appreciated. if i've left out or need clarification, i'll tell can.
could zeroes/unprintable chars result of reading form serial buffer incorrectly? advice appreciated. if i've left out or need clarification, i'll tell can.
code: [select]
#include <softwareserial.h>
softwareserial myserial(2,3); //(rx,tx)
int temp[11]; //char array temp acquired
int n; //counting number
void setup()
{
serial.begin(9600);
myserial.begin(9600);
}
void loop()
{
myserial.write("krdg? \r\n"); //send query 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);
}
code: [select]
while(myserial.available()>0)
{
for(n=0; n<11; ++n)
{
temp[n] = myserial.read();
}
}no. have checked if have @ least one byte available , read 11. won't work.
http://www.gammon.com.au/serial
Arduino Forum > Using Arduino > Project Guidance > Serial Comm. using Arduino for temperature reading
arduino
Comments
Post a Comment