{ "info": { "author": "tangliufeng@LabPlus", "author_email": "137513285@qq.com", "bugtrack_url": null, "classifiers": [], "description": "\n\n\n# HC-SR04 Sensor driver in micropython\n\nMicropython driver for the well-known untrasonic sensor [HC-SR04](https://www.mpja.com/download/hc-sr04_ultrasonic_module_user_guidejohn.pdf)\n\nThe driver has been tested on Wemos D1 mini PRO, but It should work on whatever other micropython board, \nif anyone find problems in other boards, please open an issue and we'll see.\n\n## Motivation\n\nThe existing drivers in micropython are a bit old and they don't use the relatively new method `machine.time_pulse_us()` which\nIs more accurate that whatever other method using pure python, besides the code is compliant with \"standard\" micropython,\nthere is no code for specific boards.\n\nFinally I've added a method, `distance_mm()` that don't use floating point operations, for environments where there is no\nfloating point capabilities.\n\n## Examples of use:\n\n### How to get the distance\n\nThe `distance_cm()` method returns a `float` with the distance measured by the sensor.\n\n```python\nfrom hcsr04 import HCSR04\n\nsensor = HCSR04(trigger_pin=Pin.P0, echo_pin=Pin.P1)\n\ndistance = sensor.distance_cm()\n\nprint('Distance:', distance, 'cm')\n```\n\nThere is another method, `distance_mm()`, that returns the distance in milimeters (`int` type) and **no floating point is used**, designed \nfor environments that doesn't support floating point operations.\n\n```python\ndistance = sensor.distance_mm()\n\nprint('Distance:', distance, 'mm')\n```\nThe default timeout is based on the sensor limit (4m), but we can also define a different timeout, \npassing the new value in microseconds to the constructor.\n\n```python\nfrom hcsr04 import HCSR04\n\nsensor = HCSR04(trigger_pin=16, echo_pin=0, echo_timeout_us=1000000)\n\ndistance = sensor.distance_cm()\n\nprint('Distance:', distance, 'cm')\n```\n\n### Error management\n\nWhen the driver reaches the timeout while is listening the echo pin the error is converted to `OSError('Out of range')`\n\n```python\nfrom hcsr04 import HCSR04\n\nsensor = HCSR04(trigger_pin=16, echo_pin=0, echo_timeout_us=10000)\n\ntry:\n distance = sensor.distance_cm()\n print('Distance:', distance, 'cm')\nexcept OSError as ex:\n print('ERROR getting distance:', ex)\n\n```", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/labplus-cn/mPython-lib", "keywords": "", "license": "MIT", "maintainer": "LabPlus Developers", "maintainer_email": "", "name": "mPython-hcsr04", "package_url": "https://pypi.org/project/mPython-hcsr04/", "platform": "", "project_url": "https://pypi.org/project/mPython-hcsr04/", "project_urls": { "Homepage": "https://github.com/labplus-cn/mPython-lib" }, "release_url": "https://pypi.org/project/mPython-hcsr04/0.0.1/", "requires_dist": null, "requires_python": "", "summary": "hcsr04 ultrasonic senser for mPython library", "version": "0.0.1" }, "last_serial": 5096126, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "a273b0efd3ab9f0e270fa12477a6b685", "sha256": "6341540828220f8284cc0c95364467ea9fd3707a92e852d0aed1209d4937f1e4" }, "downloads": -1, "filename": "mPython-hcsr04-0.0.1.tar.gz", "has_sig": false, "md5_digest": "a273b0efd3ab9f0e270fa12477a6b685", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2344, "upload_time": "2019-04-04T09:40:47", "url": "https://files.pythonhosted.org/packages/f3/8c/8d6adb488e04f1630df3c985696e429bd4db61246720b234a1e03946d9c5/mPython-hcsr04-0.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a273b0efd3ab9f0e270fa12477a6b685", "sha256": "6341540828220f8284cc0c95364467ea9fd3707a92e852d0aed1209d4937f1e4" }, "downloads": -1, "filename": "mPython-hcsr04-0.0.1.tar.gz", "has_sig": false, "md5_digest": "a273b0efd3ab9f0e270fa12477a6b685", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2344, "upload_time": "2019-04-04T09:40:47", "url": "https://files.pythonhosted.org/packages/f3/8c/8d6adb488e04f1630df3c985696e429bd4db61246720b234a1e03946d9c5/mPython-hcsr04-0.0.1.tar.gz" } ] }