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

    Extract data from array

    Scheduled Pinned Locked Moved SiPy
    6 Posts 2 Posters 87 Views 2 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
      ecabanas
      last edited by

      Hi all,

      I'm very newbie with micropython, and I'm using a Bme280 to know the data but it returns a string with all data, how could you extract this 3 values?
      ('23.05C', '1008.45hPa', '70.99%')
      Thanks guys and sorry if the answer is very stupid

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

        @ecabanas That depends. What you get is a tuple with 3 strings. Lets call that v
        v[0] is the first string with the temperature , v[2] the last with the humidity. If you need the values as numbers, you can call the method read_compensated_data(), which returns a tuple the values as numbers. There is a difference about which version of the lib you are using. bme280_float.py returns the properly scaled. With bme280_int.py, when using read_compensated_data(), you have to divide
        the temperature by 100, the pressure by 256 and the humidity by 1024. In any case, read_compensated_data() returns Pascal for the pressure, not hPa. For hPa, you have to divide the Pascal value by 100.

        E 1 Reply Last reply Reply Quote 0
        • E Offline
          ecabanas
          last edited by

          Hi @robert-hh

          Thanks for your explanation, right now I did what you suggest:

          import machine
          import bme280_float as bme280
          
          i2c = machine.I2C()
          bme = bme280.BME280(i2c=i2c)
          print(bme.read_compensated_data([0]))
          #print(bme.values)
          print(bme.dew_point)
          

          The output is

          array('f', [23.50931, 100830.2, 61.67432])
          

          But my question is

          I want to put every value in a variable, is it possible to read directly temp, hum and press? If not, do you know the way how to put every value from this array in every variable? like extract function or something like this.

          Thanks again

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

            @ecabanas You should be able to write:

            temp, press, hum = bme.read_compensated_data()

            Because that's what is used in the values method.

            1 Reply Last reply Reply Quote 1
            • E Offline
              ecabanas @robert-hh
              last edited by

              @robert-hh said in Extract data from array:

              _data(), which returns a tuple the values as numbers. There is a diff

              Hi @robert-hh

              How is the expression to call the different V??

              Thanks'

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

                @ecabanas What?

                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