Shop OBEX P1 Docs P2 Docs Learn Events
Sensiron + Propeller — Parallax Forums

Sensiron + Propeller

KlazenKlazen Posts: 12
edited 2008-10-12 17:45 in Propeller 1
Hello all,
After working with the sensiron temperature/humidity sensor all last night, I finally get it to output something. Onle problem is, something is wrong, and I don't know what it is.

Here's a couple of links that·make it easier·to understand where I'm coming from:
http://www.parallax.com/Portals/0/Downloads/docs/prod/datast/shtx.pdf·- Data sheet for sensiron
http://www.parallax.com/Portals/0/Downloads/docs/prod/acc/SensirionDocs.pdf·- BASIC Stamp code for sensiron

Here is the function that I'm using to read the data:

PUB read(sendByte)

  temptemp := 0
 
  dataHigh  'Sends an "incoming transmission" message to the sensiron
  clkLow
  waitcnt(CLKFREQ / 100 + CNT)
  clkHigh  
  waitcnt(CLKFREQ / 100 + CNT)
  dataLow
  waitcnt(CLKFREQ / 100 + CNT)          
  clkLow  
  waitcnt(CLKFREQ / 100 + CNT)
  clkHigh
  waitcnt(CLKFREQ / 100 + CNT)
  dataHigh
  waitcnt(CLKFREQ / 100 + CNT)
  clkLow
  waitcnt(CLKFREQ / 100 + CNT) 

  BS2.SHIFTOUT(DATAPIN,CLKPIN,sendByte,BS2#MSBFIRST,8) 'send a command to the sensiron        
  dataHigh 'Let go of data pin
  clkHigh
  if (ina[noparse][[/noparse]DATAPIN] == 0)               
  clkLow
                        
  REPEAT UNTIL (ina[noparse][[/noparse]DATAPIN] == 0)
    waitcnt(CLKFREQ / 100 + CNT)   'Wait until datapin is pulled low, check every 10 ms 

  temptemp.BYTE[noparse][[/noparse]1] := BS2.SHIFTIN(DATAPIN,CLKPIN,BS2#MSBPRE,8)
  BS2.SHIFTOUT(DATAPIN,CLKPIN,0,BS2#LSBFIRST,1) 
  temptemp.BYTE[noparse][[/noparse]0] := BS2.SHIFTIN(DATAPIN,CLKPIN,BS2#MSBPRE,8)
  dataHigh


  temptemp := calibrateTemp(temptemp)
  Result := temptemp


Note that the dataHigh function sets the data pin to input, rather than forcing it high (supposed to let a pull-up resistor push it high)

The main problems that I am having are these:
The temperature (a 14 bit value) is output as two consecutive bytes. So, I want to read the first byte into the first half of temptemp (a word), and the second byte into the last half of temptemp. Am I using the BYTE command correctly? Its syntax is symbol.BYTE<[noparse][[/noparse]offset]>.

Secondly, when I actually have the value, I don't know if I'm converting it correctly. The formula (from the sensiron datasheet) is d1 + d2 • SOT, where d1 is -40, d2 is 0.01, and SOT is the read temperature. Here is the code I'm using to convert:

PUB calibrateTemp(given)
  Result := given ** 0.01 - 40


From the BASIC code sample, it gave this formula:
tC = soT ** $1999 - 400

Where soT is the read remperature. It also noted that the·conversion factors·were multiplied by 10 to give tenths of degrees.

I'm attaching the propeller code, since I'm sure it would help to see everything in context. Note that there is a lot of commented out code, I was using that before I switched to using BS2_Functions (and it didn't work until I switched).

Thanks for your time, and I hope I made some sense.

Comments

  • StefanL38StefanL38 Posts: 2,292
    edited 2008-10-12 17:31
    Hello Klazen,

    I donwloaded your ZIP-File and tried to compile it. But several errors occurred.
    So I guess that the zipped code is not that one that you compiled or that you used for your latest tests.
    Is this right ? Did your code compile ?

    I think it will be good to post a zip-file that wil compile. After Uploading make an ultimative check by downloading this zipfile to a new tempfolder
    load it from there and try to compile it.

    edit: as I took a closer look: there are so many syntaxerrors. Please attach code that does compile.

    best regards

    Stefan

    Post Edited (StefanL38) : 10/12/2008 5:39:59 PM GMT
  • TimmooreTimmoore Posts: 1,031
    edited 2008-10-12 17:37
    Have you looked at the sensiron object in obex, I have used that without problem. It may show you where you are going wrong.
  • KlazenKlazen Posts: 12
    edited 2008-10-12 17:45
    @Stefan:

    Sorry, I see what I did wrong. I thought the compiler saved the file every time I compiled. I saved the file this time, and I'm attaching it to this post.

    @Tim

    Awesome, I didn't know there was an object for this. I will definitely take a look at it.
Sign In or Register to comment.