Extract data from array
-
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
-
@ecabanas What?
-
@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'
-
@ecabanas You should be able to write:
temp, press, hum = bme.read_compensated_data()
Because that's what is used in the values method.
-
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
-
@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.