Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/khoulihan/micropython-mpl115a2
Support for the MPL115A2 barometric pressure sensor from a pyboard.
https://github.com/khoulihan/micropython-mpl115a2
Last synced: about 16 hours ago
JSON representation
Support for the MPL115A2 barometric pressure sensor from a pyboard.
- Host: GitHub
- URL: https://github.com/khoulihan/micropython-mpl115a2
- Owner: khoulihan
- License: mit
- Created: 2014-06-15T11:34:36.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-06-15T11:38:17.000Z (over 10 years ago)
- Last Synced: 2024-08-02T20:45:03.077Z (3 months ago)
- Size: 141 KB
- Stars: 2
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-micropython - micropython-mpl115a2 - Pyboard driver for the MPL115A2 barometric pressure sensor. (Libraries / Sensors)
- awesome-mpython - micropython-mpl115a2 - Pyboard driver for the MPL115A2 barometric pressure sensor. (精选驱动库 / 传感器)
README
micropython-mpl115a2
====================Implements support for the Freescale MPL115A2 barometric pressure sensor.
Copyright (c) 2014 by Kevin Houlihan
License: MIT, see LICENSE for more details.Usage
=====The main functionality of this module is contained in the Mpl115A2 class, which
wraps an I2C object from the pyb module to control an MPL115A2 device. The RST
and SHDN pins can also optionally be controlled via Pin objects.The device must be instructed to convert its sensor data by calling the
initiate_conversion method. The readings should be ready after about 3ms.bus = I2C(1, I2C.MASTER)
sensor = Mpl115A2(bus)
sensor.initiate_conversion()
pyb.delay(3)
print(sensor.temperature)
print(sensor.pressure)Shutdown and Reset
==================The device can be shut down when not required to save power. This is not done
via I2C, but is controlled by a GPIO pin. A Pin object or name can be passed to
the constructor to allow this state to be managed.sensor = Mpl115A2(bus, shutdown_pin='X9')
sensor.shutdown = TrueAnother pin can be used to "reset" the device. That is Freescale's term, not mine,
and it is poorly documented, but apparently it shuts down the I2C interface.sensor = Mpl115A2(bus, reset_pin='X10')
sensor.reset = TrueWhen the device is awoken from a shutdown or reset state, it takes up to 5ms before
it is ready to respond to commands.sensor.shutdown = False
pyb.delay(5)
sensor.initiate_conversion()Temperature and Pressure Scales/Units
=====================================By default, the temperature is in celsius and the pressure is in kilopascals.
If other scales/units are preferred, convertors can be provided to the constructor.
Fahrenheit and Kelvin convertor classes are included in this module for temperature.
The pressure convertors also allow an adjustment to be specified, which is intended
for adjusting the pressure to sea-level. As such, there is a convertor for
AdjustedKiloPascals, HectoPascals, Atmospheres, PSI and Bars.sensor = Mpl115A2(
bus,
temperature_convertor=Fahrenheit(),
pressure_convertor=HectoPascals(0.9)
)Custom convertors can be provided as objects with these signatures:
class TemperatureScaleUnit(object):
def convert_to(self, temperature):
'''
Convert TO the custom unit FROM celsius.
'''
...
return new_tempclass PressureScaleUnit(object):
def convert_to(self, pressure):
'''
Convert TO the custom unit FROM kPa.
'''
...
return new_pressure