Tilt Sensor Reading


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2010
    Location
    Las Vegas, NV USA
    Posts
    5

    Default Tilt Sensor Reading

    Hi Folks,

    I've read and read and I am in need of some advice. I am completely green, and I would appreciate a push in the right direction. Here is what I am trying to do. I have an electronic tilt sensor that outputs a 4 byte HEX string on a RS232 line when an ASCII character is sent to it. For example, if I send it a "C" via a terminal program, it may respond with 85F (2143), the last byte isn't shown as it is a CR. To get an actual angle I need to do this: (2143-2048) * .0125. Which turns out to be 1.18°. BTW 2048 and .0125 are static variables.
    I've only successfully been able to send the ASCII character from my pic to the tilt sensor and what I end up getting back is nonsense. I guess what I am having a hard time with is how I go about setting up my variables to be able to receive my 4 byte string (ignoring the last) and then correctly displaying it on my LCD.
    Am I looking at setting up an array, naming the bytes in the array doing the math and then send those bytes out to the LCD?

    Currently I am using a 16F877A on a LABX1 board.

    I'm sorry, what I have so far is at work, as soon as I get back on Wednesday I can post what I have so far. It is ugly, and I welcome any constructive advice.
    Please be patient, I haven't messed with any of this stuff in about 6 years, and even then the most I did were the examples from the RCG Research class!

  2. #2
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    637

    Default

    sincity337,

    It would be better if you post the datasheet of the tilt sensor. Without the datasheet it would be hard to help you .

    Robert
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  3. #3
    Join Date
    Sep 2010
    Location
    Las Vegas, NV USA
    Posts
    5

    Default Before I go to bed...

    Here is a link to the data sheet...

    http://www.spectronsensors.com/appsh...0Operating.pdf

  4. #4
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    637

    Default

    Quote Originally Posted by sincity337 View Post
    I've only successfully been able to send the ASCII character from my pic to the tilt sensor and what I end up getting back is nonsense. I guess what I am having a hard time with is how I go about setting up my variables to be able to receive my 4 byte string (ignoring the last) and then correctly displaying it on my LCD.
    What exactly are you getting back? Remember to display a number greater than 2048 you need to define the variable as a WORD (or LONG).
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  5. #5
    Join Date
    Sep 2010
    Location
    Las Vegas, NV USA
    Posts
    5

    Default Here is what I have so far....

    Let me caveat this by saying I am a schlub and forgot to look and find out what version
    of PBP I am running currently. I just received the upgrade disk for 2.60 yesterday, and will take it to work next week.

    Here is a snippet of one of the variations of the code I have tried:


    Code:
    sd_tran VAR portC.6
    sd_receive VAR portC.7
    
    hexout VAR BYTE[4]
    one VAR hexout[0]
    two VAR hexout[1]
    three VAR hexout[2]
    four VAR hexout[3]
    
    mainloop:
    serout2 sd_tran, 32, ["C", 13, 10]
    pause 200
    serin2 sd_receive, 32, [hexout]
    pause 200
    LCDOUT $fe, 1, HEX one, HEX two, HEX three, HEX four
    PAUSE 500
    GOTO mainloop
    END
    What I get displayed on the LCD looks something like this 5F 00 00 00

    What I am trying to do is display the actual hex string of characters that I get back from
    the sensor. When connected to the computer via a terminal window, I usually get back something like "7AF", the last character is an ASCII "10" which get's dropped in the terminal window because it is a line feed. What I would like to display would be the whole four byte string, like "7AFA". Once I can do that, I know I can do the math to be able to get my angular number. I know it is a matter of telling PBP which bytes to to receive, store, retreive and display, but the correct way to do that is eluding me at the moment. I've tried various combination's of the SERIN2, LCDOUT, and BYTE or WORD variable to no avail. I keep getting very unlikely numbers.
    Any assistance would be greatly appreciated.

  6. #6
    Join Date
    May 2008
    Location
    Italy
    Posts
    825

    Default

    sincity337

    Remove the PAUSE 200 between serout2 and serin2. Pause in that place will delay the receiver and you will loose characters.

    Cheers

    Al.
    All progress began with an idea

  7. #7
    Join Date
    Sep 2010
    Location
    Las Vegas, NV USA
    Posts
    5

    Default Thx

    Thanks, I'll give that a shot, I appreciate it.

Members who have read this thread : 1

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