{"id":27813927,"url":"https://github.com/stsquad/mp-depth","last_synced_at":"2025-05-01T12:07:06.698Z","repository":{"id":253451711,"uuid":"843547716","full_name":"stsquad/mp-depth","owner":"stsquad","description":"A simple micropython depth sensor that broadcasts BTHome BLE advertising packets","archived":false,"fork":false,"pushed_at":"2024-09-01T15:45:36.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-01T12:07:00.743Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stsquad.png","metadata":{"files":{"readme":"README.org","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-16T18:57:48.000Z","updated_at":"2024-09-01T15:45:39.000Z","dependencies_parsed_at":"2024-08-21T11:51:59.524Z","dependency_job_id":null,"html_url":"https://github.com/stsquad/mp-depth","commit_stats":null,"previous_names":["stsquad/mp-depth"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stsquad%2Fmp-depth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stsquad%2Fmp-depth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stsquad%2Fmp-depth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stsquad%2Fmp-depth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stsquad","download_url":"https://codeload.github.com/stsquad/mp-depth/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251871583,"owners_count":21657473,"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":"2025-05-01T12:07:06.044Z","updated_at":"2025-05-01T12:07:06.684Z","avatar_url":"https://github.com/stsquad.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"* Introduction\n\nThis is a piece of Pico-W Micropython to build a depth sensor which in\ntheory should broadcast over Bluetooth Low Energy (BLE) Advertising\nPackets. The device should not be pairable.\n\n* Hardware\n\nSee the pin definitions at the top. I'm using a HCS-04 ultrasound\ndepth sensor which has separate trigger and echo pins. You wave the\ntrigger pin about, see how long it takes for the pulse to come back,\ndo some basic maths and you have a number.\n\nThe LEDs are really just useful for debugging on my Pico breakout\nboard. It shouldn't matter if they are not connected.\n\nThe button is a hacky way to boost the scanning rate for some cycles.\nIt is imperfect as you still need to wait for the existing sleep to\nwake up.\n\n* Bluetooth\n\nIn theory this is broadcasting [[https://bthome.io/][BTHome]] packets. I chose this as it\nseemed simpler than using the BLE advertising services directly. As\nneither has an attribute which maps nicely to the raw pulse counter or\na depth sensor I just report two raw 16bit integers.\n\n* Using\n\nPlug your Pico-W into your computer and copy main.py using a tool like\nampy:\n\n#+name: copy to PicoW\n#+begin_example\n$ ampy -p /dev/ttyACM0 put main.py\n#+end_example\n\nyou can then connect to the device, issue a *Ctrl-D* and the Pico will\nsoft reboot and start running the code:\n\n#+name: connect to PicoW\n#+begin_example\n$ tio /dev/ttyACM0\n[19:52:41.722] tio v2.5\n[19:52:41.722] Press ctrl-t q to quit\n[19:52:41.723] Connected\n\u003e\u003e\u003e \nMPY: soft reboot\nPulse usecs: 974\nSurface at 16.7041 cms\ntype: 1, data: bytearray(b'\\x06')/1\ntype: 9, data: b'depth'/5\nbthome: b'd2fc405302ce0353021000'/11\ntype: 22, data: bytearray(b'\\xd2\\xfc@S\\x02\\xce\\x03S\\x02\\x10\\x00')/11\npayload: b'020106060964657074680c16d2fc405302ce0353021000'/23\nPulse usecs: 974\nSurface at 16.7041 cms\ntype: 1, data: bytearray(b'\\x06')/1\ntype: 9, data: b'depth'/5\nbthome: b'd2fc405302ce0353021000'/11\ntype: 22, data: bytearray(b'\\xd2\\xfc@S\\x02\\xce\\x03S\\x02\\x10\\x00')/11\npayload: b'020106060964657074680c16d2fc405302ce0353021000'/23\n#+end_example\n\n* Interfacing with Home Assistant\n\n[[https://www.home-assistant.io/][Home Assistant]] already has built in support for Bluetooth and has native\nsupport BTHome packets. We send a raw count which is actually usecs of\nthe pulse width and then we send a distance (mm or 0.1 m).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstsquad%2Fmp-depth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstsquad%2Fmp-depth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstsquad%2Fmp-depth/lists"}