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

    BME280 on the LoPy

    Scheduled Pinned Locked Moved Issues & Bugs
    bme280lopyi2c
    41 Posts 12 Posters 16.0k Views 12 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.
    • RobTuDelftR Offline
      RobTuDelft
      last edited by RobTuDelft

      You have to specifiy the address when creating the sensor object:
      def __init__(self, address, i2c):. I don't see the address getting the default address assigned here, maybe that's your issue?

      edit:
      I was looking at the wrong class
      address=BME280_I2CADDR

      It gets the default address from there
      self._device = Device(address, i2c)

      Without data you're just another person with an opinion.
      Hackster | About me

      1 Reply Last reply Reply Quote 0
      • ledbelly2142L Offline
        ledbelly2142
        last edited by

        I am trying to use the same library with a BME280 and am experienceing the exact same issue with firmware version 1.7.4.b1
        same error:

        Traceback (most recent call last):                                                                                      
          File "main.py", line 9, in <module>                                                                                   
          File "bme280.py", line 198, in init                                                                               
          File "bme280.py", line 204, in _load_calibration                                                                      
          File "bme280.py", line 164, in readU16LE                                                                              
          File "bme280.py", line 147, in readU16  

        Did anyone get this to work?

        Friends don't let friends run with scissors

        B 1 Reply Last reply Reply Quote 0
        • B Offline
          Butch @ledbelly2142
          last edited by

          @ledbelly2142 said in BME280 on the LoPy:

          I am trying to use the same library with a BME280 and am experienceing the exact same issue with firmware version 1.7.4.b1
          same error:

          Traceback (most recent call last):                                                                                      
            File "main.py", line 9, in <module>                                                                                   
            File "bme280.py", line 198, in init                                                                               
            File "bme280.py", line 204, in _load_calibration                                                                      
            File "bme280.py", line 164, in readU16LE                                                                              
            File "bme280.py", line 147, in readU16  

          Did anyone get this to work?

          Try my fork of the library: https://github.com/ButchAnton/LoPy_BME280

          ledbelly2142L 1 Reply Last reply Reply Quote 0
          • ledbelly2142L Offline
            ledbelly2142 @Butch
            last edited by

            @Butch
            yup, thats what I'm using. I forked it. Why the init.py file?

            Friends don't let friends run with scissors

            B 1 Reply Last reply Reply Quote 0
            • B Offline
              Butch @ledbelly2142
              last edited by

              @ledbelly2142 That makes it into a package: https://docs.python.org/2/tutorial/modules.html#packages

              ledbelly2142L 1 Reply Last reply Reply Quote 0
              • ledbelly2142L Offline
                ledbelly2142 @Butch
                last edited by livius

                @Butch
                I still have the same issue, just updated to the latest firmware 1.7.5.b2
                In the main.py I'm just trying to print out values in the console, I have:

                import pycom
                from machine import I2C
                import time
                import bme280 # from bme280
                
                i2c = I2C(0, I2C.MASTER, baudrate=100000)
                i2c.scan()
                #i2c = machine.I2C(0, pins=('GP11', 'GP10'))
                bme = bme280.BME280(i2c=i2c)
                
                pycom.heartbeat(False)
                
                temp = BME280.temperature()
                humid = BME280.humidity()
                press = BME280.pressure()
                alti = BME280.altitude()
                
                #for cycles in range(10): # stop after 10 cycles
                while(true):
                    print(temp) # read temperature
                    time.sleep(2)
                    print(humid) # read humidity
                    time.sleep(2)
                    print(press) # read Pressure
                    time.sleep(2)
                    print(alti) # read altitude
                    time.sleep(2)
                

                Friends don't let friends run with scissors

                B 1 Reply Last reply Reply Quote 0
                • B Offline
                  Butch @ledbelly2142
                  last edited by

                  @ledbelly2142 Try following the line of logic I tried in the python REPL: import, instantiate, and initialize:

                  >>> from machine import I2C
                  >>> import bme280
                  >>> i2c = I2C(0, I2C.MASTER, baudrate=100000)
                  >>> bme = bme280.BME280(i2c=i2c)
                  

                  See where that takes you.

                  The original problem I ran into and ultimate fixed was that the 8- and 16-bit writes needed the value to be written to be a bytearray, not the raw value. Beyond that, all I added was a wrapper for altitude.

                  ledbelly2142L 1 Reply Last reply Reply Quote 0
                  • ledbelly2142L Offline
                    ledbelly2142 @Butch
                    last edited by ledbelly2142

                    @Butch

                    For me, the issue comes up from :
                    bme = bme280.BME280(i2c=i2c)

                    Thats where I get the errors indicating an I2C bus error.

                    I SDA on pin 9 and SCL on pin 10.

                    Could it be a bad sensor?

                    So I unplugged the BME280 sensor and got the same error.

                    Friends don't let friends run with scissors

                    B 1 Reply Last reply Reply Quote 0
                    • B Offline
                      Butch @ledbelly2142
                      last edited by

                      @ledbelly2142 It's possible that it's a bad sensor. Do you have another one to try? You might also check to make sure that i2c.scan() is returning the same address that is used in the BME280 library. If it isn't, you'll have to change the address in the library.

                      ledbelly2142L 1 Reply Last reply Reply Quote 0
                      • ledbelly2142L Offline
                        ledbelly2142 @Butch
                        last edited by

                        @Butch
                        That looks to be it. The I2C address was 77, not 76... weird. I did not think to check the I2C address.

                        Thanks!

                        Friends don't let friends run with scissors

                        1 Reply Last reply Reply Quote 0
                        • D Offline
                          Devang Sharma
                          last edited by Devang Sharma

                          Hello Everyone,
                          I'm using LoPy and I've got the similar type of error as @binux got.

                          I'm getting the following error:
                          0_1507818167256_error1.png

                          This is my code:
                          0_1507818190356_code1.png

                          Please guide me solving this!
                          Thank You.

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

                            @devang-sharma The required positional argument is 'little' in the call of from_bytes(). The API was changed a while ago. You have to modify the script BM280.py into:

                                    result = int.from_bytes(
                                        self._i2c.readfrom_mem(self._address, register, 2), little) & 0xFFFF
                            

                            The same in function readU8().

                            D 1 Reply Last reply Reply Quote 0
                            • D Offline
                              Devang Sharma @robert-hh
                              last edited by

                              @robert-hh I've done changes as you said but got the NameError as:

                              "name 'little' is not defined". How can I solve it?
                              Thank You.

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

                                @devang-sharma Sorry, it should be a string:

                                        result = int.from_bytes(
                                            self._i2c.readfrom_mem(self._address, register, 2), 'little') & 0xFFFF
                                
                                D 1 Reply Last reply Reply Quote 0
                                • D Offline
                                  Devang Sharma @robert-hh
                                  last edited by Devang Sharma

                                  @robert-hh, that worked! Thanks, but the same error for write8:
                                  1_1507872596119_error2.png
                                  0_1507872596117_code2.png

                                  Is there any link to the changed API or library? That would be better than posting every single error! :'D

                                  EDIT: Solved the error. Replaced value.to_bytes(1) with "value"! No more Errors!

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

                                    @devang-sharma No specific API doc needed, since it is standard Python behaviour now. It was incompatible before, but I'm not shure, for which MicroPython version. It may be that the Pycom branch always was compatible to the Standard.
                                    And yes, even in that case changes toward language compliance may break code, so it should be noted.

                                    1 Reply Last reply Reply Quote 0
                                    • R Offline
                                      robd
                                      last edited by

                                      Hello,
                                      There are quite a few entries on the BME280.
                                      I have been reading them and I am still not able to fix my issues.
                                      I have tried several of the libraries and I am just at a stand still.
                                      When I do a scan of the I2C port I get 0x76 so I know that the sensor is there.
                                      What I get is as follows (firmware rev 1.10.2.b1)

                                      0_1512356556349_56247ec3-a520-4588-b803-29cfce44b408-image.png

                                      Thank you,

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

                                        @robd Actually, which bme280 code are you using at the moment? I'm a little bit lost too.

                                        R 1 Reply Last reply Reply Quote 0
                                        • D Offline
                                          Devang Sharma
                                          last edited by

                                          @robd I've faced a similar issue and added argument 'little' as @robert-hh suggested which worked for me. I don't know which library you're using. But I've been using this:

                                          https://github.com/LoRaWeather/BME280-LoPy-TTN/tree/master/Program/lib

                                          R 1 Reply Last reply Reply Quote 0
                                          • sebS Offline
                                            seb
                                            last edited by

                                            This post is deleted!
                                            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