Determining status of individual sensors.
I'd like to be able to determine the status of individual sensors on the PySense. This is part of a longer strategy to incorporate additional sensors but determine which ones are active on each board as part of an initialisation.
I've tried using the _read_status(self) function of the barometer but I can't get it to work, e.g.
barometer_ready = MPL3115A2._read_status()
I don't know what to pass as the parameter because self is part of the class and has no meaning outside of it.
The simplest solutions are the best. I'll give that a go. Many thanks @seb.
You could use the scan method of the I2C class to detect what sensors are present on the bus. Then based on what addresses you can find you can run/not run the code relating to that sensor.
@seb Yes, I would like to have multiple boards with a selection of sensors on each but I don't want to change the code according to which specific sensors I have attached. I want the initialisation procedure to determine which of those sensors are present and the main code therefore only read from those that are attached. Kind of like a plug and play but without hot-plugging.
It should be straightforward but I wanted to at least demonstrate the process without having to modify libraries. At least for the time being. I think as the PyCom eco-system develops and libraries are added, it should be a pre-requisite to have a function like this for any external hardware.
Can you explain in more detail what you are attempting to achieve? Are you just looking for which sensors are present?
alidaf last edited by alidaf
@seb That works fine. I already had an instance in order for the readings to work but for some reason....idiot mode active. I need some sleep!
There doesn't appear to be anything equivalent in the LTR329ALS01 or SI7006A20 ibraries though.
rather that calling the method of the class directly you should first create an instance of the class and call the method of the instance:
from pysense import Pysense from MPL3115A2 import MPL3115A2 py = Pysense() baro = MPL3115A2(py) barometer_ready = baro._read_status()
You may also need to pass mode when instantiating the barometer depending on if you want to measure pressure or altitude. Please refer to our documentation for more details: https://docs.pycom.io/chapter/pytrackpysense/apireference/pysense.html