Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    SI7021 I2C pin setup (SOLVED)

    Scheduled Pinned Locked Moved MicroPython
    micropythonsi7021i2c
    59 Posts 4 Posters 13.2k Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • E Offline
      Eric73 @tttadam
      last edited by

      @tttadam Sorry, it's wrong place to do your change, create your i2c object in your main.py and then use it as arguments when you create your SI7021 object. P22 and P23 are for example only, use the rigth pin of your board instead.

      from machine import I2C
      import SI7021
      Bus=I2C(0, I2C.MASTER, baudrate=100000, pins=('P23','P22'))
      Sensor=SI7021(i2c=Bus)
      print(Sensor.readTemp())
      
      T 1 Reply Last reply Reply Quote 2
      • T Offline
        tttadam @Eric73
        last edited by

        @eric73

        Something is still wrong...
        This is my code:

        import pycom
        from machine import I2C
        import SI7021
        
        # i2c = I2C(0, I2C.MASTER, baudrate=100000, pins=(Pin.exp_board.G7,Pin.exp_board.G8))
        bus = I2C(0, I2C.MASTER, baudrate=100000, pins=("P7","P8"))
        sensor = SI7021(i2c=bus)
        print(sensor.readTemp())
        print(sensor.readRH())
        

        and this is the error what I get.

         Traceback (most recent call last):
          File "main.py", line 12, in <module>
        TypeError: 'module' object is not callable
        robert-hhR 1 Reply Last reply Reply Quote 0
        • robert-hhR Offline
          robert-hh @tttadam
          last edited by

          @tttadam I see 9 lines of code, the error is flagged in line 12 of main.py. What is the content of line 12 or line 11?

          T 1 Reply Last reply Reply Quote 1
          • T Offline
            tttadam @robert-hh
            last edited by

            @robert-hh My bad, so sorry. The error is in this line:

            sensor = SI7021(i2c=bus)
            
            robert-hhR 1 Reply Last reply Reply Quote 0
            • robert-hhR Offline
              robert-hh @tttadam
              last edited by robert-hh

              @tttadam Try:

              sensor = SI7021.SI7021(i2c=bus)
              

              = class SI7021 in module SI7021. Quite confusing at the beginning. You could also have imported the class as:
              from SI7021 import SI7021, then the initial code would work.

              T 1 Reply Last reply Reply Quote 2
              • T Offline
                tttadam @robert-hh
                last edited by

                @robert-hh Now I am getting a totaly different error, so I think We are getting somewhere.
                I checked the wiring multiple times. That should be okay.
                VIN-->VIN
                GND-->GND
                G8-->SCL
                G7-->SDA)

                Traceback (most recent call last):
                  File "main.py", line 14, in <module>
                  File "/flash/lib/SI7021.py", line 31, in readTemp
                  File "/flash/lib/SI7021.py", line 28, in write_command
                OSError: I2C bus error
                

                Line 14 is this: print(sensor.readTemp())

                import pycom
                import time
                from machine import I2C, Pin
                from dth import DTH
                from SI7021 import SI7021
                
                bus = I2C(0, I2C.MASTER, baudrate=100000, pins=(Pin.exp_board.G8,Pin.exp_board.G7))
                # bus = I2C(0, I2C.MASTER, baudrate=100000, pins=("P8","P7"))
                sensor = SI7021(i2c=bus)
                print(sensor.readTemp())
                print(sensor.readRH())
                
                E robert-hhR 2 Replies Last reply Reply Quote 0
                • E Offline
                  Eric73 @tttadam
                  last edited by Eric73

                  @tttadam Have you add a 1K or 4K7 or 10K pull-up resistor on G8 and G7 ?
                  What is the board you use ?

                  T 1 Reply Last reply Reply Quote 1
                  • T Offline
                    tttadam @Eric73
                    last edited by

                    @eric73

                    Oh, I did not. I just tried out the built in resistances, but doesn't make a difference, still getting the same error.
                    I am using right now a lopy4 with ExpansionBoard V3r (But in the final product I will use a pytrack board)

                    import pycom
                    import time
                    from machine import I2C, Pin
                    from dth import DTH
                    from SI7021 import SI7021
                    
                    bus = I2C(0, I2C.MASTER, baudrate=100000, pins=(Pin(Pin.exp_board.G8,mode= Pin.OPEN_DRAIN, pull= Pin.PULL_UP),Pin(Pin.exp_board.G7,mode= Pin.OPEN_DRAIN, pull= Pin.PULL_UP)))
                    # bus = I2C(0, I2C.MASTER, baudrate=100000, pins=("P8","P7"))
                    sensor = SI7021(i2c=bus)
                    print(sensor.readTemp())
                    print(sensor.readRH())
                    
                    1 Reply Last reply Reply Quote 0
                    • robert-hhR Offline
                      robert-hh @tttadam
                      last edited by robert-hh

                      @tttadam On the expansion board G7 and G8 are also connected to CTS and RTS of the USB/UART bridge. If you want to use them for other means, you have to remove the respective jumpers.

                      T 1 Reply Last reply Reply Quote 2
                      • T Offline
                        tttadam @robert-hh
                        last edited by

                        @robert-hh Okay, I changed the pins to 5 and 4. I am still getting the same error, but now it takes some time, like a second or so. Before that a I got the error immediately.

                        Traceback (most recent call last):
                          File "main.py", line 16, in <module>
                          File "/flash/lib/SI7021.py", line 31, in readTemp
                          File "/flash/lib/SI7021.py", line 28, in write_command
                        OSError: I2C bus error
                        
                        pin5 = Pin(Pin.exp_board.G5,mode= Pin.OPEN_DRAIN, pull= Pin.PULL_UP)
                        pin4 = Pin(Pin.exp_board.G4,mode= Pin.OPEN_DRAIN, pull= Pin.PULL_UP)
                        bus = I2C(0, I2C.MASTER, baudrate=100000, pins=(pin5,pin4))
                        # bus = I2C(0, I2C.MASTER, baudrate=100000, pins=("P8","P7"))
                        sensor = SI7021(i2c=bus)
                        print(sensor.readTemp())
                        print(sensor.readRH())
                        
                        

                        line16 is this: print(sensor.readTemp())

                        robert-hhR 1 Reply Last reply Reply Quote 0
                        • robert-hhR Offline
                          robert-hh @tttadam
                          last edited by robert-hh

                          @tttadam G5 and G4 aka P13 and P14 are input only ports. I wonder that it does not give an error immedetaly when declaring. Why don't you use the default pins G16 and G17 aka "P9" for SDA and "P10" for SCL, at least for a first test?
                          Edit: You do not have to initialize the pins yourself. In the i2c constructor, you can write ... pins=("P9", "P10") or pins=("G16", "G17").

                          T 1 Reply Last reply Reply Quote 1
                          • T Offline
                            tttadam @robert-hh
                            last edited by

                            @robert-hh Yes You are right, I should thought about this earlier.
                            So I modified my code like this. Something is still wrong, because I still get the same error.
                            My pins are correct, now but I took a picture just in case.

                            sensor = SI7021(i2c=I2C())
                            print(sensor.readTemp())
                            print(sensor.readRH())
                            

                            layout

                            T 1 Reply Last reply Reply Quote 0
                            • T Offline
                              tttadam @tttadam
                              last edited by

                              @tttadam said in SI7021 I2C pin setup:

                              Looks like my picture didn't make it.
                              Here is the url: [https://imgur.com/a/j8fPQxZ](link url)

                              robert-hhR 1 Reply Last reply Reply Quote 0
                              • robert-hhR Offline
                                robert-hh @tttadam
                                last edited by

                                @tttadam According to the picture, your wiring seems wrong. You connected SDA to P10 and SCL to P9.

                                T 1 Reply Last reply Reply Quote 1
                                • T Offline
                                  tttadam @robert-hh
                                  last edited by

                                  @robert-hh I switched them back and for forth. Maybe a I took the picture on the wrong state but I tried both way (just to make sure).

                                  robert-hhR 1 Reply Last reply Reply Quote 0
                                  • robert-hhR Offline
                                    robert-hh @tttadam
                                    last edited by robert-hh

                                    @tttadam In order to test the communication, do some basics like:

                                    from machine import I2C
                                    i2c = I2C(0, I2C.MASTER)
                                    i2c.scan()
                                    

                                    That already should return the adress of the connected device. If that works, then you know at least that the I2C connection is fine and which address your device is using.

                                    T 1 Reply Last reply Reply Quote 1
                                    • T Offline
                                      tttadam @robert-hh
                                      last edited by

                                      @robert-hh said in SI7021 I2C pin setup:

                                      i2c.scan()
                                      This is what it returns:

                                      [64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120]

                                      E robert-hhR 2 Replies Last reply Reply Quote 0
                                      • E Offline
                                        Eric73 @tttadam
                                        last edited by

                                        @tttadam Strange things, i have a look to your wire connexion, i hope my eyes are wrong but it seem you power your sensor with VIN (approx 5V), but your device SI7021 have +3.6V maximum power supply voltage so +5V can destroy your device.

                                        If i take time to watch your wire it because typically on a scan i2c your device seem to ACK all address starting by 0x40 (64) and this can be happen in case of bad gnd connexion, please check your power supply +3.3V and GND for your SI7021.
                                        If you have an oscilloscope for probin SDA and SCL this will be very helpfull.

                                        T 1 Reply Last reply Reply Quote 1
                                        • robert-hhR Offline
                                          robert-hh @tttadam
                                          last edited by

                                          @tttadam Definitely Vcc should be 3.3 V. And I cannot tell whether pull-up resistors are present on the board. Adding some with a value of about 4.7 - 10 kOhm should not hurt.

                                          1 Reply Last reply Reply Quote 1
                                          • T Offline
                                            tttadam @Eric73
                                            last edited by

                                            @eric73 Well, you are right. I gave the sensor 5v instead of 3.3. I think I killed it.. well least a learned something. I also tried with 10k resistor but still getting I2C bus error...
                                            Thanks for the help anyway.

                                            robert-hhR 1 Reply Last reply Reply Quote 0

                                            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                            With your input, this post could be even better 💗

                                            Register Login
                                            • 1
                                            • 2
                                            • 3
                                            • 1 / 3
                                            • First post
                                              Last post

                                            Pycom on Twitter

                                            Pycom