Closed orangecms closed 10 months ago
WIth this
from pslab import ScienceLab
from pslab.external.BMP180 import BMP180
from time import sleep
psl = ScienceLab() # This initializes the I2C bus.
sensor = BMP180()
data = sensor.readTemperature()
print(data)
sleep(2)
data = sensor.readPressure()
print(data)
I get
calib: 1.2451171875 0.001999969482421875 0.006079673767089844 0.012499809265136719 65535.0 20.400000000000002 1.59375 255 4.98046875 0.194549560546875 65.535 0.0024901963770389557 2.364375 0.9929838180541992 4.42087184637785e-06
12.8
996.8078400249741
As of now. 12.8
looks quite odd for the temperature, and I always get that same value across multiple reads, using a BME280. It's definitely not 12.8 Celsius here. Almost 1000
(hPa) for the pressure is reasonable, but I also get the same value across multiple reads. Something is :fish:y.
As of now.
12.8
looks quite odd for the temperature, and I always get that same value across multiple reads, using a BME280. It's definitely not 12.8 Celsius here. Almost1000
(hPa) for the pressure is reasonable, but I also get the same value across multiple reads. Something is 🐟y.
From a brief look at the code, it looks like in order to tell the sensor to actually measure anything you need call initTemperature
/initPressure
. readTemperature
/readPressure
just fetches a register value which is static until a measurement command is sent.
However, both initTemperature
and initPressure
are broken because the signature of I2CSlave.write
changed.
From a brief look at the code, it looks like in order to tell the sensor to actually measure anything you need call
initTemperature
/initPressure
.readTemperature
/readPressure
just fetches a register value which is static until a measurement command is sent.
Isn't that happening in the init?
However, both
initTemperature
andinitPressure
are broken because the signature ofI2CSlave.write
changed.
Oh then I did something wrong with that part; what's the correct way to use it now?
Isn't that happening in the init?
It is, but only once, and since both temperature and pressure data is stored in the same register (_REG_RESULT
) the temperature is immediately overwritten.
what's the correct way to use it now?
Same as I2CSlave.read
, i.e. first argument is a list of bytes to write into the register specified by the optional second argument (which defaults to 0x0). So instead of:
def initTemperature(self):
self.write([self._REG_CONTROL, self._CMD_TEMP])
it should be
def initTemperature(self):
self.write([self._CMD_TEMP], self._REG_CONTROL)
I am a bit unsure regarding the "extra" API in the I2C sensors. It looks like it was quite tightly coupled to the old Python desktop app. Let's discuss that in the next meeting.