Shop OBEX P1 Docs P2 Docs Learn Events
Trouble Programming Sensirion Temperature on Activity Board in Propeller C — Parallax Forums

Trouble Programming Sensirion Temperature on Activity Board in Propeller C

Hi, I want to use the Sensiroin temperature sensor on the Activity Board, but the example code for the sensor is in Basic Stamp. Anybody know how to program the sensor in Propeller C? I attached the example code I downloaded from Parallax's documentation for the sensor.




Comments

  • While I couldn't find any Propeller C code for the SHT11, here are some links to Propeller SPIN code examples:

    obex.parallax.com/object/186
    obex.parallax.com/object/515
    obex.parallax.com/object/516
    obex.parallax.com/object/517

    Here is a link to a Arduino C code example:

    https://github.com/practicalarduino/SHT1x/

    Here is a link to another Forum posting regarding SHT11 module:

    forums.parallax.com/discussion/145830/sht11-sensor-incorrect-readings-calibration

    Hopefully the above will help, good luck...



  • I didn't realize from the first post that this was the SHT11. This thread might contain some useful information for you (though be warned, I've been having trouble with PropWare on Windows recently so it might not end up being very useful)

    http://forums.parallax.com/discussion/164647/c-language-sensirion-sht11-temperature-humidity-part-28018
  • yoyoyoyo Posts: 15
    edited 2017-05-02 00:28
    Thank you both for replying.
  • Have you tried this link? http://forums.parallax.com/discussion/148116/sensirion-sht11-simpletools-code I have worked with the sht11 module, and have some C code that works as expected, but it is stored some where, not readily available.

    I am probably going to be putting together another PropGCC sht11 project, so somewhere down the line I will have to dig up the code, but not at this moment. If I happen to stumble across it, I will post it again. By the way, back in 2013 I did have a thread going for the sht11 module, and if you dig a little you might find the code listing in the thread.

    Ray
  • There may be some useful code examples on the page for my SHT11 module. I haven't verified links in a while, so some may be broken:

    http://www.aestheticacoustics.com/SHT11_05.htm
  • I've been writing a program in C code, which I pasted below, and there are 4 errors. I'd like to get advice on how the program could be better, and I'm having trouble fixing the errors. The errors are

    line 69:34 "expected ')' before ',' token"
    line 69:54"expected expression before ';' token"
    line 93:6 "expected identifier or '*' before 'while'"
    line 94:1 "expected declaration or statement at end of input".

    Thank you for reading, and have a great day.




    /*
    Blank Simple Project.c
    http://learn.parallax.com/propeller-c-tutorials
    */
    #include "simpletools.h" // Include simple tools
    #include "simpletext.h"
    #include "simplei2c.h"
    #include "ping.h"

    const int ShtData = 14;
    const int Clock = 13;

    const int ShtTemp = 00011;
    const int ShtStatW = 00110;
    const int ShtStatR = 00111;
    const int ShtReset = 11110;

    const int Ack = 0;
    const int NoAck = 1;

    const int MoveTo = 2;
    const int ClrRt = 11;

    const int DegSym = 186;

    int ioByte;
    int ackBit;
    int toDelay;
    int timeOut;

    int soT;
    int status;

    int shiftout();
    int shiftin();

    #define int16_t

    int main() // Main function
    {
    shiftout(ShtData, Clock, LSBFIRST, 00000011); // Add startup code here.
    pause(250);
    CLS;
    print("SHT1x Demo", CR);
    print("
    ", CR);


    while(1)
    { // Add main loop code here.
    // measuretemp();


    input(ShtData);
    low(Clock);
    high(Clock);
    low(ShtData);
    low(Clock);
    high(Clock);
    input(ShtData);
    low(Clock);

    ioByte = ShtTemp;

    shiftout(ShtData, Clock, MSBPRE, ioByte);
    shiftin(ShtData, Clock, LSBFIRST, ackBit);

    input(ShtData);// particular trouble with this section <-
    for(int n = 1; n <= 250; n++) // <-
    timeOut = (unsigned (int16_t), LSBFIRST, ShtData);
    if(timeOut = 0);
    {
    (ackBit = Ack);

    shiftin(ShtData, Clock, MSBPRE, ioByte);
    shiftout(ShtData, Clock, LSBFIRST, ackBit);
    input(ShtData);

    MSBFIRST, soT = ioByte;
    ackBit = NoAck;

    shiftin(ShtData, Clock, MSBPRE, ioByte);
    shiftout(ShtData, Clock, LSBFIRST, ackBit);
    input(ShtData);

    print("Raw Data Temp: ShtTemp = %d ", ShtTemp);
    pause(1000);

    goto while(1);

    }

    pause(1);

    }
    goto while(1);
    }



  • Can you repost the code, but this time highlight the whole block of code and click the "C" above the text box? This will wrap your code in code blocks so that it is easier to read here on the forums
  • Could you also identify lines 69, 93, and 94.

    Thanks
    Tom
  • In the for statement you marked the only statement that is repeated 250 times is:
    timeOut = (unsigned (int16_t), LSBFIRST, ShtData);
    
    

    Is that what you intended?

    Tom
  • Line 37: #define int16_t   ( what  is the variable name?
    Line 45:    print("      (print what? No "); at the end
    Line 46:    ", CR);      ( was this supposed to be part of Line 45 (above))?
    Line 71:      if(timeOut = 0);    (a single = is an ASSIGNMENT, a double == tests for equality. The block following this line will never execute.
    Line 89 to end:  
          goto while(1);
    
        }
    
        pause(1);
    
      }
      goto while(1);   Why the goto while(1)???  It happens automagically when the end of the while(1) block is reached
    
    
  • [code][code][code][code][code]/*
    Blank Simple Project.c
    http://learn.parallax.com/propeller-c-tutorials
    */
    #include "simpletools.h" // Include simple tools
    #include "simpletext.h"
    #include "simplei2c.h"
    #include "ping.h"
    
    const int ShtData = 14;
    const int Clock = 13;
    
    const int ShtTemp = 00011;
    const int ShtStatW = 00110;
    const int ShtStatR = 00111;
    const int ShtReset = 11110;
    
    const int Ack = 0;
    const int NoAck = 1;
    
    const int MoveTo = 2;
    const int ClrRt = 11;
    
    const int DegSym = 186;
    
    int ioByte;
    int ackBit;
    int toDelay;
    int timeOut;
    
    int soT;
    int status;
    
    int shiftout();
    int shiftin();
    
    #define int16_t
    
    int main() // Main function
    {
    shiftout(ShtData, Clock, LSBFIRST, 00000011); // Add startup code here.
    pause(250);
    CLS;
    print("SHT1x Demo", CR);
    print(" ", CR);
    
    
    while(1)
    { // Add main loop code here.
    // measuretemp();
    
    
    input(ShtData);
    low(Clock);
    high(Clock);
    low(ShtData);
    low(Clock);
    high(Clock);
    input(ShtData);
    low(Clock);
    
    ioByte = ShtTemp;
    
    shiftout(ShtData, Clock, MSBPRE, ioByte);
    shiftin(ShtData, Clock, LSBFIRST, ackBit);
    
    input(ShtData);// particular trouble with this section <-
    for(int n = 1; n <= 250; n++) // <-
    line 69 timeOut = (unsigned (int16_t), LSBFIRST, ShtData);
    if(timeOut = 0);
    {
    (ackBit = Ack);
    
    shiftin(ShtData, Clock, MSBPRE, ioByte);
    shiftout(ShtData, Clock, LSBFIRST, ackBit);
    input(ShtData);
    
    MSBFIRST, soT = ioByte;
    ackBit = NoAck;
    
    shiftin(ShtData, Clock, MSBPRE, ioByte);
    shiftout(ShtData, Clock, LSBFIRST, ackBit);
    input(ShtData);
    
    print("Raw Data Temp: ShtTemp = %d ", ShtTemp);
    pause(1000);
    
    goto while(1);
    
    }
    
    pause(1);
    line 93
    line 94 }
    goto while(1);
    }[code]
    
    [/code][/code][/code][/code][/code][/code]
  • twm47099, yes, I want that to repeat 250 times. But I'm having trouble figuring out how to set TimeOut to the lower 8 bits of the 16 bit variable.

    HalAlbach, can you please explain line 71 more thoroughly? Thanks.
  • The construct of the if statement in line 71 is a little strange.
    if(timeOut = 0);
    
    which is followed by a body of code enclosed in braces which makes it appear that the body of code is to be executed if timeOut is equal to 0. If that was your intention then there are two errors in the if statement. The first error is that (timeOut = 0) actually assigns 0 to timeOut, and second, the semicolon terminates the if statement.
    So, if you want to execute the code body after the if statement then you need to make the following change to the statement;
    if(timeOut == 0)        // note the absence of ; and the double == now compares timeOut to 0
    {
       -code to execute;
    }
    

    I believe I was in error when I stated that the code following the if statement would never execute, rather, it will execute regardless what value timeOut held. I failed to notice the terminating semicolon.
  • Thank you so much Hal Albbach :)
Sign In or Register to comment.