Shop OBEX P1 Docs P2 Docs Learn Events
Question about reading multiple SHTxx sensors — Parallax Forums

Question about reading multiple SHTxx sensors

LeeWLeeW Posts: 14
edited 2009-08-27 00:00 in BASIC Stamp
Hello,

As a student I'm quite new at all of this, but I was curious as to how I would go about reading multiple (2-6) SHTxx Humidity/Temperature sensors.·I understand that you can use one SCK line for all 6 sensors and individual data lines for each, but I'm confused as to how you would handle them going to the BS2. confused.gif

Programming the controller to handle·more than·2 separate sensors seems like it would be too big of a program for just simply memory reasons. I'm betting that it's not possible using PBASIC?


If anyone could point me in the right direction or offer some suggestions and help, it'd be very much appreciated.

Thanks in advance! hop.gif

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-24 19:54
    You would just connect all the SCK lines from the sensors to one Stamp I/O pin and the data line from each sensor would be connected to a separate I/O pin. I'd suggest having one pulldown resistor (4.7K) from the SCK I/O pin to ground on the Stamp.

    If you use successive I/O pins for the data lines, you can easily modify the sample program to read each sensor in turn, one at a time and display the data. The pin number in the I/O statements (like INPUT, LOW, HIGH, SHIFTOUT, and SHIFTIN) can be an expression. For example, if you use I/O pins 1-6 for the six sensors' data lines, you can change all the statements in the sample program and substitute "ShtData+i" for "ShtData" where "i" is a new byte variable. Near the end of the program, you'll have to change "IF (ShtData = 0) THEN EXIT" to "IF (ShtData(i) = 0) THEN EXIT". I'm not sure, but I think that will compile ... try it. You may need to replace the "ShtData PIN 1" with "ShtData CON 1".

    Replace the DO / LOOP in the Main section of the program with
    FOR i = 0 to 5
       DO
          ...
       LOOP
    NEXT
    


    and the program will read the sensors one at a time with a 1 second pause between displaying each sensor's results.
  • WBA ConsultingWBA Consulting Posts: 2,934
    edited 2009-07-29 18:07
    I spent a little time modifying the SHT11_Advanced sample code from Parallax's SHT11 web page to make it work with multiple sensors. I set up 3 SHT11 sensors on my PDB with a BS2 and was able to get it to work fairly easily. I had to do some recycling of variables to gain room for the arrays used and there is still much room to improve that. Currently, my code structure is limited to 3 sensors because you cannot increase the two arrays (rhTrue and tF) due to insufficent variable space.

    I have already thought of a couple ways to streamline the code to reduce the usage of variable space. The sample program is written for ease of use and understanding, not code efficiency. I could easily get rid of tC, soT, and soRH by streamlining the code structure. I will be working on that since I believe that the BS2 should be able to read numerous sensors and run an LCD without running out of space.

    Any other suggestions on streamlining the variable usage with SHT11 sensors would be appreciated.

    (note: the 005 in the filename is my revision)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andrew Williams
    WBA Consulting
    IT / Web / PCB / Audio
  • WBA ConsultingWBA Consulting Posts: 2,934
    edited 2009-07-30 05:32
    Made some modifications and it's a little cleaner and up to 4 sensors now. I used the math from the Propeller object for the SHT11 to eliminate the tC variable. I created some constants for number of sensors so as I streamline code, I can just change the "NumSens" value and see the changes in the memory map and functioning of the code. From what I have found so far, I don't think I can get the BS2 to read 12 sensors uses this code structure. I will need to use another method to store the values (eeprom, etc)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andrew Williams
    WBA Consulting
    IT / Web / PCB / Audio
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-07-30 15:42
    Hi Andrew,

    If resolution to 0.5 %RH and to 0.5 degree in temperature is acceptable, then your structure could easily do 8 sensors.

    Of course, in answer to the original post, there is not that limitation if you do not need to store the data in the BS2 RAM. It can be sent one sensor at a time to an LCD or terminal screen, or it can be logged in sequence in the eeprom or in external memory. Note that Andrew's program does not occupy anywhere near the full capacity of the BS2 eeprom.

    I have a program that I use for environmental chamber testing of 8 at a time. But it uses the BS2pe, so it has the scratchpad RAM available as a data buffer, and from there it logs the data to a vDrive.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • WBA ConsultingWBA Consulting Posts: 2,934
    edited 2009-07-30 17:16
    So after reviewing the code again and the datasheet for the SHT11, I assume that you are referring to using 8 bit rH and 12bit Temp values instead of 12 bit/14 bit? That should allow me to change some of the Word variables to Byte variables, correct? Also, maybe getting rid of the compensation calculations?

    Something else I noticed in the datasheet that I did not ever before. Page 5, ss3.1 states:

    Values higher than 99% RH indicate fully saturated air and must be processed and displayed as 100%2 RH.

    Note 2 on the bottom of the page states:
    If wetted excessively (strong condensation of water on sensor surface), sensor output signal can drop below 100%RH (even below 0%RH) in some cases, but sensor will recover completely when water droplets evaporate. Sensor is not damaged by water immersion or condensation.

    The first part of that last sentence caught my eye: "Sensor is not damaged by water immersion". I wonder if that means the sensor will function properly under water if the substrate and leads are conformally coated. I think I will be coating a sensor this weekend and giving it a "filter cap free" dunk. Obviously, this won't protect the sensor element from particles in the water contaminating the sensor.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andrew Williams
    WBA Consulting
    IT / Web / PCB / Audio
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-07-30 21:31
    I was actually thinking of acquiring the data at full resolution, and then some math to squeeze it into 8 bits. 0% to 100% fits easily in a byte, even at 0.5 degree resolution, if, for example, the stored value 99 becomes 5 * 99 = 49.5 %RH on display. And 0 to 128 Fahrenheit neatly covers the freezing point of water up to any comfortable ambient temperature, and a similar trick can extend it to 0.5 degree resolution or adjust the range as required.

    I think the part about "contaminating" is a crucial point. It may be relatively okay with DiH2O from pure condensation. I remember a conversation with one of the Sensirion engineers about condensation, and they indicated that a long dryout period at a high temperature might be necessary to restore the best calibration. That was a while ago, so they may have improved that now. He said that the internal heater would not be sufficient to bake it out. I think there is a document on the Sensirion web site about this.

    Cloride in tap water or a host of other chemicals could I bet wreak havoc. Sulfur in agricultural chemical, PAH and metals in diesel emissions, and ocean salt spay come to mind.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • WBA ConsultingWBA Consulting Posts: 2,934
    edited 2009-07-30 23:29
    I thought about doing a little more math upfront, but since that part of the code has always been a little complicated to me, I was looking at other things. That makes a lot of sense though. For my current work in progress (house thermostat that monitors every room), accuracy of +/- 2 degrees will be satisfactory. I think I will look into that path of code modification and see what I can do.

    Thanks for the detail on contamination, I was unaware of how critical it could be. My only current plan for an underwater SHT11 is for the annual polar bear plunge logger.

    In regards to condensation and moisture, you are right on. Section 1.4 of the datasheet has the reconditioning process for when the sensor has experienced excessive moisture or solvent vapors from processing.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andrew Williams
    WBA Consulting
    IT / Web / PCB / Audio
  • LeeWLeeW Posts: 14
    edited 2009-08-26 17:34
    Sorry for the late response, but thanks so much for that code. I didn't realize you could change the pin #'s like you did in your program, being a newbie I thought you had to have them defined with each pin # defined to a constant. Using a variable makes a whole lot more sense and is much easier on the memory usage and the program. Thanks a bunch.
  • WBA ConsultingWBA Consulting Posts: 2,934
    edited 2009-08-27 00:00
    No problem, glad it helped. I actually moved onto using the propeller for my project because my SPIN learning starting picking up speed and I was not wanting to spend more time hacking up the code for the SHT on the stamp. It can be done as Tracy suggests. One easy way to read multiple sensors is to not use the arrays for the readings. If you cycle through one at a time and send the value to a display, you can keep re-using the variables without the array. I did some quick tweaking on my 007 version code and here is 008. It should work the same, but has a lot more memory space leftover because the values are immediately written to the debug window instead of stored into an array.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andrew Williams
    WBA Consulting
    WBA-TH1M Sensirion SHT11 Module

    Post Edited (WBA Consulting) : 8/27/2009 12:25:24 AM GMT
Sign In or Register to comment.