Shop OBEX P1 Docs P2 Docs Learn Events
Is I2C & 2 wire communication for sensirion temperature/humidity sensor — Parallax Forums

Is I2C & 2 wire communication for sensirion temperature/humidity sensor

CreeCree Posts: 132
edited 2013-07-16 06:17 in BASIC Stamp
I was looking around the internet and found out that 2 wire is the same as I2C, but I2C is a trade mark from Philips.

as mentioned in this forum link from AVR Freaks (correct me if i'm wrong)

So with a PCF8574P IO expander , I'm going to hook up 2 of the sensors mentioned above. Ill add more later if it works.

I'm using the basic stamp sx micro-controller module.

I found this on parallax from the nuts & volts I2C example

I
f the are other examples can you direct me to them? or have any recommendations?
«13

Comments

  • tdlivingstdlivings Posts: 437
    edited 2013-06-07 14:13
    The sensor ion sensors are not I2C.protocall while they do have the same two type of connections they will not work with an I2C lib
  • CreeCree Posts: 132
    edited 2013-06-09 11:57
    So I can't use the I2C library because the sensor are not I2C, but can I still use the IO expander with the sensor?
  • SRLMSRLM Posts: 5,045
    edited 2013-06-09 12:35
    From the Sensiron SHT11 datasheet, it's clear that the device is not I2C. It shares many of the low level signal characteristics, but is missing two components: a device address and an ACK/NACK after every eight bits.

    For the first point, you could probably still use the sensiron sensor in an unmodified I2C setup. You'd just have to pretend that it was 6x as many devices (one for each command).

    The second point is more of a problem. I2C assumes that each 8 bits comes with an ACK/NACK from the receiver. From page 7 of the datasheet, you can see that it transmits up to 16 bits without an ACK/NACK. I think this could be a problem in some hardware based I2C drivers.

    Of course, the best thing you could do would be to test and see what happens. Electrically, the signals are compatible so it should be safe for the chips.

    Edit: I should have been more careful: I see the ACK/NACK now. Yes, I think you can use it on an I2C bus. You'll have to do some experimentation to get command sequence working, and you'll have to make sure that you don't accidentally reset the device with the RESET command, but it looks like it (more or less) compatible.
  • CreeCree Posts: 132
    edited 2013-06-10 06:29
    Would I have an issue with the sensirion because it douse not have any address pins?
  • SRLMSRLM Posts: 5,045
    edited 2013-06-10 07:27
    Cree wrote: »
    Would I have an issue with the sensirion because it douse not have any address pins?

    I2C does not use address pins. All I2C has is CLK and DATA.
  • CreeCree Posts: 132
    edited 2013-06-10 08:19
    Ok, well first I'm going to try to get the PCF8574 to work with the I2C example that's in the nuts and volts just to get the initial portion to work. (with out the sensor)
  • CreeCree Posts: 132
    edited 2013-06-10 08:57
    so far i'm getting an error

    (error: no ACK from PCF85754)

    This is just one PCF8574P conected to see if it would work properly.
  • SRLMSRLM Posts: 5,045
    edited 2013-06-10 08:59
    You'll have to post some source code if you want more detailed help...
  • CreeCree Posts: 132
    edited 2013-06-10 09:50
    sry, found out it was a wiring issue.
  • CreeCree Posts: 132
    edited 2013-06-10 12:57
    k so I got the PCF85754 to work, but how do I go about connecting my sensirion.

    It has a 2 wire serial communication. is it possible to send and receive data through the pcf8574p?
  • CreeCree Posts: 132
    edited 2013-06-10 13:29
    The issue that I have is this that I found in the data sheet.

    2.2
    Serial Interface (Bidirectional 2-wire) The serial interface of the SHTxx is optimized for sensor
    readout and power consumption and is not compatible with
    I2C interfaces, see FAQ for details.
  • SRLMSRLM Posts: 5,045
    edited 2013-06-10 13:37
    Cree wrote: »
    The issue that I have is this that I found in the data sheet.

    2.2
    Serial Interface (Bidirectional 2-wire) The serial interface of the SHTxx is optimized for sensor
    readout and power consumption and is not compatible with
    I2C interfaces, see FAQ for details.


    I don't know where you're getting that from. This is what I see in the datasheet:
    The serial interface of the SHT1x is optimized for sensor
    readout and effective power consumption. The sensor
    cannot be addressed by I2C protocol; however, the sensor
    can be connected to an I2C bus without interference with
    other devices connected to the bus. The controller must
    switch between the protocols.

    You'll need to make sure that what you send (from your microcontroller) falls within the specs given in the datasheet. If you use an I2C object/command, then you'll need to study up on the I2C protocol so you can figure out how to hack it to fit into the protocol required by the Sensiron sensor. I don't know if what you're using is amenable to that. At the very least you could bitbang the two signals (CLK and DATA) and have a slow but functional interface.
  • CreeCree Posts: 132
    edited 2013-06-11 06:36
    K, I think there may be confusion on what we are trying to talk about, let me rephrase myself in what I am trying to do. (I'm not using the PCF8574p anymore)


    I am trying to use multiple sensirion temp/humidity sensors (2 wire serial communication). But my issue is that they do no have addresses and is not I2C. I have gotten a single to work and now i am trying to use multiple. I'm sure if I had multiple sensors in an I2c set up I would be able to get data from them, but I wouldn't be able to tell which one is which.
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2013-06-11 08:34
    One possible solution would be to use a CD4051 (74HC4051) analog multiplexer with the common point connected to a Stamp pin, and each of the 8 mux points connected to the data pin of a sensirion and to its own pullup resistor. The clock line can be shared. The CD4051 also needs 3 address lines from the Stamp, to select one sensirion at a time. So that is 5 Stamp pins for 8 sensirions.

    Another way I've used 8 on one Stamp: each has its own data pin, the clock line is shared, so 9 pins for 8 sensirions.

    Sensirion also offers the SHT21 with true i2c, but it has only one address possibility, no solution to your problem.
  • CreeCree Posts: 132
    edited 2013-06-11 09:05
    One possible solution would be to use a CD4051 (74HC4051) analog multiplexer with the common point connected to a Stamp pin, and each of the 8 mux points connected to the data pin of a sensirion and to its own pullup resistor. The clock line can be shared. The CD4051 also needs 3 address lines from the Stamp, to select one sensirion at a time. So that is 5 Stamp pins for 8 sensirions.

    Another way I've used 8 on one Stamp: each has its own data pin, the clock line is shared, so 9 pins for 8 sensirions.

    Sensirion also offers the SHT21 with true i2c, but it has only one address possibility, no solution to your problem.

    Ya had looked at the SHT21, the only solution to my problem would be to get a temp sensor with addresses.

    I figured a way arround it to use switches, but that would end up having more wires, which is not what I wanted.
  • SRLMSRLM Posts: 5,045
    edited 2013-06-11 12:09
    Cree wrote: »
    Ya had looked at the SHT21, the only solution to my problem would be to get a temp sensor with addresses.

    The SHT21 has both temperature and humidity in the same device: http://www.sensirion.com/en/products/humidity-temperature/humidity-sensor-sht21/
  • CreeCree Posts: 132
    edited 2013-06-11 13:24
    SRLM wrote: »
    The SHT21 has both temperature and humidity in the same device: http://www.sensirion.com/en/products/humidity-temperature/humidity-sensor-sht21/

    That is not the issue, its that I need to use multiple sensors and that they do not have addresses to tell which sensor is which.

    If these sensors had addresses it would solve my problem.
  • CreeCree Posts: 132
    edited 2013-06-12 11:51
    Hi I'm trying to create a counter in order to change the pin in which I am sending my clock pulses to a different sensor every time I push a button.

    My issue is that I am getting an error that symbol is already defined and my first if function is highlighted.

    this what I have in a subroutine:
    Clockcounter:
    IF (senscnt > 5) THEN
    senscnt=0
    NEXT


    IF PIN 17 = HIGH THEN
    senscnt=snscnt+1
    NEXT ,


    IF (senscnt = 0) THEN
    clock PIN 2
    NEXT
    IF (senscnt = 1) THEN
    PIN 2 = 0,
    clock PIN 3
    NEXT
    IF (senscnt = 2) THEN
    PIN 3=0,
    clock PIN 4
    NEXT
    IF (senscnt = 3) THEN
    pin4=0 ,
    clock PIN 5
    NEXT
    IF (senscnt = 4) THEN
    pin5=0 ,
    clock PIN 6
    NEXT
    IF (senscnt = 5) THEN
    PIN 6=0,
    clock PIN 9
    RETURN


    I learned to make a counter in C, but it seems to have to be done differently in basic stamp.
  • CreeCree Posts: 132
    edited 2013-06-12 13:31
    Simply how do you count the number of presses on the push button.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-06-12 13:54
    Please either include your source file as an attachment (use the Go Advanced button when replying) or, if you want to cut and paste your program, use [ code ] and [ /code ] tags around the program (without the extra spaces). Please include your actual program, otherwise we can't tell whether a misspelling is a copying error or the actual error.

    Please look at the description of the PIN directive. This declares the name starting in column 1 as an I/O pin and you're re-defining "clock" over and over again. What are you trying to do with that?
  • CreeCree Posts: 132
    edited 2013-06-13 06:16
    I was given a project for my internship to create a string of digital temperature sensors in a grain silo.
    It was supposed to be a total of four lines; 1 voltage, 1 GND, 1 Data and 1 CLK.

    But because the Sht 11 is both temperature, humidity and has a heater in the sensor, it would be a full package in terms of a sensor.


    Currently I'm trying to send the clock to different sensors every time I press a button. I am doing this because the sht11 temperature/ humidity sensor is 2 wire serial comm and does not have any address pins. I have 6 of theses sensors, the original plan was to have only two wires for data and the clock, but without address pins or I2C communication I was forced to change the design to having one data lines and one clock line per sensor. That makes 6 clock lines.

    Sry I forgot to check "what is a micro controller?". I'm going to look for examples.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-06-13 07:14
    You have another thread in the Sensors forum. Please keep the discussion on the use of the SHT11 sensor in one thread and on counting button presses in the other thread or have only one thread for the whole project. We can merge the two threads if you like or move a thread from one forum to another, but having two similar discussions going on in two places is neither productive nor allowed.
  • CreeCree Posts: 132
    edited 2013-06-13 07:29
    Ok if its not aloud to have multiple threads for one project then, plz do merge them. I actually have a third in the basic stamp forum. If you can move and merge them all the at threat that would be nice.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-06-13 07:56
    You will want to have the clock lines for the SHT11 sensors wired sequentially, probably with I/O pin #0 attached to sensor #1 clock line, I/O pin #1 attached to sensor #2 clock line, and so on. The shared data line would be attached to I/O pin #6 or higher. The clocked serial protocol used by the SHT11 is done using the SHIFTIN and SHIFTOUT statements and these allow the pin numbers (for data and clock) to be variables as well as constants. You can set the variable to a value from 0 to 5 and a single subroutine or section of code can read the values from the selected sensor. Look at the description of the SHIFTIN and SHIFTOUT statements in the Basic Stamp Syntax and Reference Manual. You might also browse through the Nuts & Volts Columns for examples of the use of various sensors and other examples as well.

    The product page in Parallax's webstore for the SHT11 has links to the documentation and sample code and links to Nuts & Volts Column #91 which discusses the SHT11

    Note that the HIGH and LOW statements, also used in the Nuts & Volts examples, allow the use of a variable for the pin number.
  • CreeCree Posts: 132
    edited 2013-06-13 08:15
    Mike Green wrote: »
    You will want to have the clock lines for the SHT11 sensors wired sequentially, probably with I/O pin #0 attached to sensor #1 clock line, I/O pin #1 attached to sensor #2 clock line, and so on. The shared data line would be attached to I/O pin #6 or higher. The clocked serial protocol used by the SHT11 is done using the SHIFTIN and SHIFTOUT statements and these allow the pin numbers (for data and clock) to be variables as well as constants. You can set the variable to a value from 0 to 5 and a single subroutine or section of code can read the values from the selected sensor. Look at the description of the SHIFTIN and SHIFTOUT statements in the Basic Stamp Syntax and Reference Manual. You might also browse through the Nuts & Volts Columns for examples of the use of various sensors and other examples as well.

    The product page in Parallax's webstore for the SHT11 has links to the documentation and sample code and links to Nuts & Volts Column #91 which discusses the SHT11

    Note that the HIGH and LOW statements, also used in the Nuts & Volts examples, allow the use of a variable for the pin number.

    Thx for the links, I already have a set up for one Sht11 with LCD working displaying temperature and humidity. The current set up I am working on is with multiple sensors is basically what you explained in the first sentence. I am currently working on the subroutine for selecting which which sensor I want, which is the push button thing i am working on now.
  • CreeCree Posts: 132
    edited 2013-06-13 08:16
    K I'm on the right direction now, but my issue now is that I need it to count for every on/off, not just when it is on.
    I have looked
    I have tried a few ways, was not able to get it to work.

    How do I ensure it only counts every time the pin goes on/off (to count every push)? Because with the code below it will keep counting until 255 (a byte) until i release the button.
    ' {$STAMP BS2sx}' {$PBASIC 2.5}
     senscnt VAR  Byte
     senscnt = 0
     DO
       DEBUG ? senscnt 'push button counter
      IF (IN7 = 1 ) THEN
    
      senscnt = senscnt + 1
    
      ENDIF
    
    
     LOOP
    
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2013-06-13 08:24
    As you discovered, your program is counting rapidly when the button is high and not at all when it is low. The following snippet counts a button press only when it first makes contact. There is are two state bits, old and new, and the logic statement looks for the condition where the old state of the button was high and the new state is low.
    [FONT=courier new][SIZE=1]' {$STAMP BS2pe}
    ' {$PBASIC 2.5}
    old VAR BIT
    new VAR BIT
    clk VAR NIB    ' counts button presses
    
    old = IN15  'pb
    DO 
      new = IN15
      IF new ^ old & old THEN
        clk = clk + 1 // 5
        DEBUG DEC clk, CR
      ENDIF
      old = new
    LOOP[/SIZE][/FONT]
    

    The counter variable here is called clk, and in another subroutine to read the SHT sensor, that would specify the pin to use for the clock.
  • CreeCree Posts: 132
    edited 2013-06-13 08:35
    As you discovered, your program is counting rapidly when the button is high and not at all when it is low. The following snippet counts a button press only when it first makes contact. There is are two state bits, old and new, and the logic statement looks for the condition where the old state of the button was high and the new state is low.
    [FONT=courier new][SIZE=1]' {$STAMP BS2pe}
    ' {$PBASIC 2.5}
    old VAR BIT
    new VAR BIT
    clk VAR NIB    ' counts button presses
    
    old = IN15  'pb
    DO 
      new = IN15
      IF new ^ old & old THEN
        clk = clk + 1 // 5
        DEBUG DEC clk, CR
      ENDIF
      old = new
    LOOP[/SIZE][/FONT]
    

    The counter variable here is called clk, and in another subroutine to read the SHT sensor, that would specify the pin to use for the clock.

    Thx, I would have never thought of doing it like this. I'm going to look at it more closely to understand it.
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2013-06-13 09:41
    Well, here is another way to do it, for you to look at and compare.
    [FONT=courier new][SIZE=1]' {$STAMP BS2pe}
    ' {$PBASIC 2.5}
    clk VAR NIB    ' counts button presses
    
        
    DO
      DO : LOOP WHILE IN15   ' stay here while pin is high
        clk = clk + 1  // 5  ' pin has gone low, count
        DEBUG DEC clk, CR
      DO : LOOP UNTIL IN15   ' stay here until pin returns high
    LOOP
    [/SIZE][/FONT]
    

    This version uses program modes; the program code itself waits for the state of the switch to change. The previous program uses bit variables to store the states of the switch. I generally prefer the state variable approach over the modal approach, especially when a developing program has several tasks that will need to be executed quasi-simultaneously.
  • CreeCree Posts: 132
    edited 2013-06-13 10:15
    Well, here is another way to do it, for you to look at and compare.
    [FONT=courier new][SIZE=1]' {$STAMP BS2pe}
    ' {$PBASIC 2.5}
    clk VAR NIB    ' counts button presses
    
        
    DO
      DO : LOOP WHILE IN15   ' stay here while pin is high
        clk = clk + 1  // 5  ' pin has gone low, count
        DEBUG DEC clk, CR
      DO : LOOP UNTIL IN15   ' stay here until pin returns high
    LOOP
    [/SIZE][/FONT]
    

    This version uses program modes; the program code itself waits for the state of the switch to change. The previous program uses bit variables to store the states of the switch. I generally prefer the state variable approach over the modal approach, especially when a developing program has several tasks that will need to be executed quasi-simultaneously.

    ok, thx for the suggestion.
Sign In or Register to comment.