PDA

View Full Version : Serial Communication



Travin77
- 9th March 2006, 22:10
Hello all. I just need some suggestions as to how to fix a problem. I am using the SERIN command. The sensor is a precon humidity/temp sensor that outputs a ASCII text serial string 8 bits long, no parity, one stop bit at 9600 baud. The string looks like this : H:xx.x T+xx.x <CR>. I input this into my variable. I then try to use the LCDout command to put the value on the LCD. the only thing that shows up on the LCD is the H. I am using a 16F876a with 20mhz crystal. Any ideas?

Thanks for any help.

picster
- 9th March 2006, 22:56
Have you brought all the text in from the sensor into an array? As long as you know the length of the string it outputs, you can plop each byte into one slot in an array with a single SERIN command, and then spit it all out at once to the LCD with LCDOUT STR MYARRAY\16 (substitute the string length for the 16). Then just loop, rinse, repeat.

---------------Picster--------------

Travin77
- 10th March 2006, 02:34
I finally got it to work, sorta. The only problem is that if I hook up two sensors, then one of them can't be on the usart pin of the the pic. The sensor on the usart pin displays fine, however the one not on the usart pin displays garbage. Can you suggest a solution other than a pic with 3 usarts. Also how do I work with the data in the array? I need to compare some of the values in the array and convert some of the numbers to different numbers. Thanks a lot for your help.

jheissjr
- 10th March 2006, 06:46
Just curious, what humidity sensor are you using.

picster
- 11th March 2006, 01:56
If you know WHERE the data digits are, you can simply do math on the ascii characters.

result=100*(array[5]-48)+10*(array[6]-48)+array[7]-48

As for bringing in the 2nd sensor, can you look at using a chip enable if they're open collector outputs, and then just select one or the other on the same hserin input?

-------------------Picster-----------------

Travin77
- 11th March 2006, 05:50
My array is 13 bits long. Assuming the array numbers start with 0 and ends at 12. Here is the string (the x's represent numbers in ascii) H xx.x T xx.x with the spaces (I assume) part of the array. I need to use the numbers after T xx.x (which is temperature in Celsius) and convert it to Fahrenheit. Here is what I used:

temp=(humidity1[9]* 90) / 5
temp1=(humidity1[10]*9)/ 5
temp2=(humidity1[12]*9)/50
tempfin=temp+temp1+temp2+32

Humidity is the str array variable that holds the information. When I get the final value and output it on the lcd, I get an unrecognizable character. Any suggestions? thanks

picster
- 11th March 2006, 14:00
Yep, you need to subtract 48 from each ASCII value to come up with the numerical value before you do the factoring.

------------------Picster-----------------

Travin77
- 13th March 2006, 00:34
It works now. thanks. Just out of curiosity, why do you subtract 48? I forgot to mention earlier, I am using HS-2000D humidity sensor made by PRECONUSA.

mister_e
- 13th March 2006, 03:39
the answer is located in the ASCII table in your PBP manual. Character 0 is decimal ASCII 48.

Joval
- 11th April 2006, 05:29
Hi,
check the thread R/H Temp sensor.
Bruce used the same sensor and posted the code to show H and Temp in C and F.
I am using the same sensor and some of Bruces work in my code.
Works like a champ!!!

Joe