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

    Wipy 2.0 and BME280 sensor

    Scheduled Pinned Locked Moved WiPy 2&3
    8 Posts 5 Posters 3.4k Views 6 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.
    • M Offline
      michal
      last edited by michal

      Hello!

      Was anybody able to use I2C BME280 sensor? It works flawlessly on Wipy 1.0 using a driver from Paul Cunnane (https://bitbucket.org/oscarBravo/wipy_bme280), but I get strange errors on Wipy 2.0:

      >>> from machine import I2C
      >>> import bme280
      >>> i2c = I2C(0, I2C.MASTER, baudrate=100000)
      >>> bme = bme280.BME280(i2c=i2c)
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/flash/lib/bme280.py", line 186, in __init__
        File "/flash/lib/bme280.py", line 106, in write8
      TypeError: object with buffer protocol required
      

      It looks like this operation fails:
      i2c.writeto_mem(0x76, 0xF4, 0x3F)

      I can see the device on I2C bus, so the wiring should be OK. I also have a HD44780 display with PCF8574 backpack connected to I2C bus and it works.

      I am using the latest firmware 0.9.4b1.

      One last thing - I am connected to Wipy via telnet (Putty) and the REPL is almost unusable. After few lines of code it hangs or key presses start to generate weird characters.

      Michal

      B 1 Reply Last reply Reply Quote 0
      • D Offline
        daniel
        last edited by daniel

        @michal when you do the i2c.scan() are you able to see the sensor connected?

        TypeError: object with buffer protocol required

        This error occurs because the function expects a bytes object and you are trying to send an integer. Could you try with:

        i2c.writeto_mem(0x76, 0xF4, bytes([0x3F]))
        

        ?

        Obviously we should make the drivers fully compatible with the old ones. We'll definitely fix it, but please try the workaround above to confirm the problem. Thanks.

        Cheers,
        Daniel

        1 Reply Last reply Reply Quote 0
        • M Offline
          michal
          last edited by

          Hi Daniel!

          I can confirm, that it works with bytes object:-)

          >>> from machine import I2C
          >>> import bme280
          >>> i2c = I2C(0, I2C.MASTER, baudrate=100000)
          >>> bme = bme280.BME280(i2c=i2c)
          >>> print(bme.temperature, bme.pressure, bme.humidity)
          24.07C 967.63hPa 64.16%
          

          I got confused with I2C Quick Reference (https://docs.pycom.io/wipy2/2wipy/quickref.html#i2c-bus) which is the same for both versions of Wipy.

          Thanks a lot for your help!

          Michal

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

            Hi Michal,

            Thanks for the quick feedback, glad that it works now :-)

            I got confused with I2C Quick Reference (https://docs.pycom.io/wipy2/2wipy/quickref.html#i2c-bus) which is the same for both versions of Wipy.

            It's our fault, we need to make the API accept an integer as well. Will be fixed shortly.

            Cheers,
            Daniel

            1 Reply Last reply Reply Quote 0
            • B Offline
              Baruch1966 @michal
              last edited by

              @michal said in Wipy 2.0 and BME280 sensor:

              I can see the device on I2C bus, so the wiring should be OK. I also have a HD44780 display with PCF8574 backpack connected to I2C bus and it works.
              I am using the latest firmware 0.9.4b1.

              Can you share a example code with PCF8574?

              M 1 Reply Last reply Reply Quote 0
              • M Offline
                michal @Baruch1966
                last edited by

                @Baruch1966
                Hi!

                Here is the repository with driver from Dave Hylands:
                https://github.com/dhylands/python_lcd

                Here is the sample code:

                from machine import I2C
                from i2c_lcd import I2cLcd
                
                i2c = I2C(0, I2C.MASTER, baudrate=100000)
                lcd = I2cLcd(i2c, 0x27, 4, 20)
                lcd.putstr("It Works!")
                

                I use this display: http://www.santy.cz/zobrazovace-c7/lcd-2004-blue-i2c-i9/
                and this level converter: http://www.santy.cz/moduly-omezovacu-a-prevodniku-c34/i2c-uart-level-konvertor-3v-5v-4way-i223/

                Michal

                1 Reply Last reply Reply Quote 0
                • J Offline
                  Jiemde Pybytes Beta
                  last edited by

                  Hi michal,

                  Also try to use the bme280 sensor ( working with the wipy1 ok! ) but have the same errors with the wipy 2!
                  Had you resolve this ? If yes could you tell me how ?

                  Best regards

                  Jiemde

                  M 1 Reply Last reply Reply Quote 0
                  • M Offline
                    microman7k @Jiemde
                    last edited by microman7k

                    @Jiemde

                    Hi, It works with my Wipy 2.0, i think the only change i made was:

                    def write8(self, register, value):
                    """Write an 8-bit value to the specified register."""
                    value = value & 0xFF
                    self._i2c.writeto_mem(self._address, register, bytes([value]))

                    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 / 1
                    • First post
                      Last post

                    Pycom on Twitter

                    Pycom