{"id":13613077,"url":"https://github.com/khoulihan/micropython-tmp102","last_synced_at":"2025-12-30T17:20:16.391Z","repository":{"id":81913521,"uuid":"20766399","full_name":"khoulihan/micropython-tmp102","owner":"khoulihan","description":"Support for the TI tmp102 I2C temperature sensor.","archived":false,"fork":false,"pushed_at":"2018-12-31T17:56:03.000Z","size":13,"stargazers_count":8,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-22T13:30:44.861Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/khoulihan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2014-06-12T12:24:15.000Z","updated_at":"2024-04-04T21:34:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"94608b09-a10d-4933-934c-f8fada6dc888","html_url":"https://github.com/khoulihan/micropython-tmp102","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khoulihan%2Fmicropython-tmp102","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khoulihan%2Fmicropython-tmp102/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khoulihan%2Fmicropython-tmp102/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khoulihan%2Fmicropython-tmp102/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/khoulihan","download_url":"https://codeload.github.com/khoulihan/micropython-tmp102/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248735916,"owners_count":21153501,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T20:00:39.251Z","updated_at":"2025-12-30T17:20:16.378Z","avatar_url":"https://github.com/khoulihan.png","language":"Python","funding_links":[],"categories":["Libraries","精选驱动库"],"sub_categories":["Sensors","传感器"],"readme":"micropython-tmp102\n==================\n\nImplements support for the Texas Instruments tmp102 temperature sensor.\n\nCopyright (c) 2014 by Kevin Houlihan\n\nLicense: MIT, see LICENSE for more details.\n\n\nUsage\n=====\n\nThe main functionality of this package is contained in the Tmp102 class, which\nwraps an I2C object from the pyb or machine modules to configure and read from a\ntmp102 device at a specific address.\n\nAt it's most basic, the class can be can be initialized with an I2C bus object and\nan address, and then the temperature can be read periodically from the temperature\nproperty:\n\n    from pyb import I2C\n    from tmp102 import Tmp102\n    bus = I2C(1, I2C.MASTER)\n    sensor = Tmp102(bus, 0x48)\n    print(sensor.temperature)\n\nOr for the I2C class in the machine module:\n\n    from machine import I2C\n    from tmp102 import Tmp102\n    bus = I2C(1)\n    sensor = Tmp102(bus, 0x48)\n    print(sensor.temperature)\n\nThe temperature will be in celsius by default.\n\n\nConversion Rate\n===============\n\nBy default, the temperature will be updated at 4Hz. The rate of updates can be\nset to one of four frequencies by setting the conversion_rate property, or by\npassing a conversion_rate named argument to the constructor. The *conversionrate*\nmodule must be imported to enable this functionality:\n    \n    from tmp102 import Tmp102\n    import tmp102.conversionrate\n    sensor = Tmp102(\n        bus,\n        0x48,\n        conversion_rate=Tmp102.CONVERSION_RATE_1HZ\n    )\n    sensor.conversion_rate = Tmp102.CONVERSION_RATE_QUARTER_HZ  # 0.25Hz\n\nThe available rates are:\n\n    Tmp102.CONVERSION_RATE_QUARTER_HZ\n    Tmp102.CONVERSION_RATE_1HZ\n    Tmp102.CONVERSION_RATE_4HZ\n    Tmp102.CONVERSION_RATE_8HZ\n\n\nExtended Mode\n=============\n\nBy default, the temperature value is stored as 12 bits, for a maximum reading of\n128C. Extended mode uses 13 bits instead, allowing a reading up to 150C. Extended\nmode can be enabled by setting the extended_mode property or passing an extended_mode\nnamed argument to the constructor. The *extendedmode* module must be imported to enable\nthis functionality.\n\n    from tmp102 import Tmp102\n    import tmp102.extendedmode\n    sensor = Tmp102(\n        bus,\n        0x48,\n        extended_mode=True\n    )\n    sensor.extended_mode = True\n\n\nShutdown and One-Shot Conversions\n=================================\n\nWhen temperature readings are not required for an extended period, the device can\nbe shut down to save power. Only the serial interface is kept awake to allow the\ndevice to be woken up again. The device can be shut down and awoken by setting the\nshutdown property appropriately. The *shutdown* module must be imported to enable\nthis functionality.\n\n    sensor.shutdown = True\n    # sensor.temperature will not be updated again until the device is awoken.\n    pyb.delay(60000)\n    sensor.shutdown = False\n    # sensor.temperature will again be updated at the previously configured frequency.\n\nNote that there is a delay between when the device receives the instruction to wake\nup and when the first reading becomes available.\n\nIf the device is shut down and only a single reading is required, it is not\nnecessary to toggle the shutdown and make the device fully active again in order\nto get a reading. A \"one-shot\" conversion can be initiated by calling the\ninitiate_conversion method. The progress of the conversion can be monitored through\nthe conversion_ready property. The *oneshot* module must be imported to enable this\nfunctionality.\n\n    sensor.initiate_conversion()\n    while not sensor.conversion_ready:\n        pyb.delay(10)\n    temp = sensor.temperature\n\nThe device remains shutdown after this process.\n\nOne-shot conversions allow the temperature to be polled at frequencies much\nlonger than the four pre-set conversion rates without wasting power. To facilitate\nthis mode of operation, the device can be intitialized in shutdown mode by passing\na shutdown named argument to the constructor:\n\n    sensor = Tmp102(bus, 0x48, shutdown=True)\n\n\nThermostat Mode and Alerts\n==========================\n\nThe sensor has a feature to set and unset a flag based on high and low temperatures\nbeing reached. It can also generate an SMBus interrupt when operating in a\ncertain mode. I'm not sure if this interrupt could be handled by the hardware,\nbut it is definitely not supported by this module.\n\nThe alert flag can be read on the alert property, and can take the values\nTmp102.ALERT_HIGH or Tmp102.ALERT_LOW. The various configuration flags and values\nsupported by the device can all be set through properties of the object or\narguments to the constructor, but their semantics are best described by the\ndatasheet of the sensor: http://www.ti.com/lit/ds/symlink/tmp102.pdf\n\nThe alert module must be imported to use any of these features.\n\n    from tmp102 import Tmp102\n    import tmp102.alert\n    sensor = Tmp102(\n        bus,\n        0x48,\n        alert_polarity=Tmp102.ALERT_HIGH,\n        thermostat_mode=Tmp102.COMPARATOR_MODE,\n        fault_queue_length=Tmp102.FAULT_QUEUE_4,\n        thermostat_high_temperature=35.0,\n        thermostat_low_temperature=34.0\n    )\n\n    sensor.alert_polarity = Tmp102.ALERT_LOW  #Default\n    sensor.alert_polarity = Tmp102.ALERT_HIGH\n\n    sensor.thermostat_mode = Tmp102.COMPARATOR_MODE  # Default\n    sensor.thermostat_mode = Tmp102.INTERRUPT_MODE\n\n    sensor.fault_queue_length = Tmp102.FAULT_QUEUE_1  # Default\n    sensor.fault_queue_length = Tmp102.FAULT_QUEUE_2\n    sensor.fault_queue_length = Tmp102.FAULT_QUEUE_4\n    sensor.fault_queue_length = Tmp102.FAULT_QUEUE_6\n\n\nTemperature Scales/Units\n========================\n\nBy default, all temperatures are in celsius. If another scale/unit is preferred,\na convertor can be provided to the constructor. Fahrenheit and Kelvin convertor\nclasses are included in the *convertors* module.\n\n    sensor = Tmp102(\n        bus, \n        0x48, \n        temperature_convertor=Fahrenheit()\n    )\n\nA custom convertor can be provided as an object with this signature:\n\n    class ScaleUnit(object):\n        def convert_from(self, temperature):\n            '''\n            Convert FROM the custom unit TO celsius.\n            '''\n            ...\n            return new_temp\n\n        def convert_to(self, temperature):\n            '''\n            Convert TO the custom unit FROM celsius.\n            '''\n            ...\n            return new_temp\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhoulihan%2Fmicropython-tmp102","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkhoulihan%2Fmicropython-tmp102","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhoulihan%2Fmicropython-tmp102/lists"}