Giter VIP home page Giter VIP logo

micropython-sht30-nsht30's Introduction

#SHT30 Sensor driver in micropython

Micropython driver for SHT30 Shield for Wemos D1 Mini (and PRO).

The driver has been tested on Wemos D1 mini PRO, but It should work on whatever other micropython board, if anyone find problems in other boards, please open an issue and We'll see.

##Motivation The SHT30 shield for ESP8266 board Wemos D1 Mini has an Arduino driver but not a micropython one.

##References:

##Examples of use:

###How to get the temperature and relative humidity:

The measure() method returns a tuple with the temperature in celsius grades and the relative humidity in percentage. If the measurement cannot be performed then an exception is raised (SHT30Error)

from sht30 import SHT30

sensor = SHT30()

temperature, humidity = sensor.measure()

print('Temperature:', temperature, 'ºC, RH:', humidity, '%')

There is another method, measure_int(), that returns 4 integer values, no floating point operation is done, designed for environments that doesn't support floating point operations, the four values are:

Temperature (integer part), Temperature (decimal part), RH (integer part), RH (decimal part)

For intance, if the measure() method returns (21.5623, 32.0712) the measure_int() method would return: (24, 56, 32, 7) The decimal part is limited to 2 decimal digits.

t_int, t_dec, h_int, h_dec = sensor.measure_int()

print('Temperature: %i.%02i °C, RH: %i.%02i %%' % (t_int, t_dec, h_int, h_dec))

Both methods allow a raw param that when It's True returns the sensor measurement as-is, It's a bytearray(6) with the format defined in the sensor datasheet document.

raw_measure = sensor.measure(raw=True)

print('Sensor measurement', raw_measure)

###Check if shield is connected

from sht30 import SHT30

sensor = SHT30()

print('Is connected:', sensor.is_present())

###Read sensor status

Check the Sensor Datasheet for further info about sensor status register

from sht30 import SHT30

sensor = SHT30()

print('Status register:', bin(sensor.status()))
print('Single bit check, HEATER_MASK:', bool(sensor.status() & SHT30.HEATER_MASK))

#The status register can be cleared with
sensor.clear_status()

###Reset the sensor

The driver allows a soft reset of the sensor

from sht30 import SHT30

sensor = SHT30()
sensor.reset()

###Error management

When the driver cannot access to the measurement an exception SHT30Error is raised

from sht30 import SHT30

sensor = SHT30()

try:
    t, h = sensor.measure()
except SHT30Error as ex:
    print('Error:', ex)

micropython-sht30-nsht30's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.