Serial Communication


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2006
    Posts
    89

    Default Serial Communication

    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.
    Last edited by Travin77; - 9th March 2006 at 22:15.

  2. #2


    Did you find this post helpful? Yes | No

    Default Serial killer?

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

  3. #3
    Join Date
    Feb 2006
    Posts
    89


    Did you find this post helpful? Yes | No

    Default Tried it

    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.
    Last edited by Travin77; - 10th March 2006 at 04:08.

  4. #4
    jheissjr's Avatar
    jheissjr Guest


    Did you find this post helpful? Yes | No

    Default

    Just curious, what humidity sensor are you using.

  5. #5


    Did you find this post helpful? Yes | No

    Default converting array data

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

  6. #6
    Join Date
    Feb 2006
    Posts
    89


    Did you find this post helpful? Yes | No

    Default Maybe I am not doing something right

    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

  7. #7


    Did you find this post helpful? Yes | No

    Default Ascii vs value

    Yep, you need to subtract 48 from each ASCII value to come up with the numerical value before you do the factoring.

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

  8. #8
    Join Date
    Feb 2006
    Posts
    89


    Did you find this post helpful? Yes | No

    Default Works

    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.

  9. #9
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    the answer is located in the ASCII table in your PBP manual. Character 0 is decimal ASCII 48.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  10. #10
    Join Date
    Mar 2006
    Location
    Garden Grove, Ca
    Posts
    5


    Did you find this post helpful? Yes | No

    Default serial communication

    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

Similar Threads

  1. Wireless serial communication question
    By Ahmadabuomar in forum Serial
    Replies: 3
    Last Post: - 21st December 2009, 03:49
  2. PIC to PIC "wired" serial one-way communication - SERIN2/SEROUT2
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 14th April 2008, 20:02
  3. Bootloader,MCSP and Serial communication
    By surfer0815 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd March 2006, 10:52
  4. Serial Communication using 12F629
    By charudatt in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 14th March 2005, 04:24
  5. Replies: 8
    Last Post: - 11th November 2004, 20:08

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts