{"id":16516615,"url":"https://github.com/eadf/esp8266_ping","last_synced_at":"2025-03-21T08:31:48.190Z","repository":{"id":26661326,"uuid":"30117691","full_name":"eadf/esp8266_ping","owner":"eadf","description":"Ultrasonic sensor driver for the esp8266","archived":false,"fork":false,"pushed_at":"2016-03-07T19:30:50.000Z","size":209,"stargazers_count":45,"open_issues_count":1,"forks_count":11,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-01T04:32:19.957Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eadf.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}},"created_at":"2015-01-31T16:17:32.000Z","updated_at":"2024-06-06T07:48:00.000Z","dependencies_parsed_at":"2022-07-25T16:00:05.645Z","dependency_job_id":null,"html_url":"https://github.com/eadf/esp8266_ping","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/eadf%2Fesp8266_ping","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eadf%2Fesp8266_ping/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eadf%2Fesp8266_ping/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eadf%2Fesp8266_ping/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eadf","download_url":"https://codeload.github.com/eadf/esp8266_ping/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244124198,"owners_count":20401685,"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-10-11T16:25:47.476Z","updated_at":"2025-03-21T08:31:47.533Z","avatar_url":"https://github.com/eadf.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# esp8266_ping\nA HC-SR04, HY-SRF05 driver and example for the esp8266.\n```\n#include \"ping/ping.h\"\n....\nstatic Ping_Data pingA;\n....\n// setup\nint triggerPin = 0;\nint echoPin = 2;\nping_init(\u0026pingA, triggerPin, echoPin, PING_MM); // set the trigger and echo pin to the same number for one-pin mode\n\n....\n// loop:\nfloat distance = 0;\nfloat maxDistance = 500;\nif (ping_pingDistance(\u0026pingA, maxDistance, \u0026distance) ) {\n  os_printf(\"Response ~ %d mm \\n\", (int)distance);\n} else {\n  os_printf(\"Failed to get any response.\\n\");\n}\n```\n\nMakefile:\n```\nMODULES         = driver/stdout driver/easygpio driver/ping user\n```\n\n##Circuit\nThe HC-SR04 is a 5V device, so you will (at the very least) need a [voltage divider](http://elinux.org/RPi_GPIO_Interface_Circuits#Voltage_divider) on the echo pin.\nOr even better: [a logic level shifter.](http://elinux.org/RPi_GPIO_Interface_Circuits#Level_Shifters) \n\n![Two pins](/doc/esp_circuit_twopins.png)\n### single pin mode\n\n![Single pin mode - level shifter](/doc/esp_circuit_onepin.png)\n\nIf you want to run this in 'single pin mode' behind a logic level shifter you can connect the echo pin on the 3V3 side to the trigger GPIO via a 4KΩ:ish resistor. This works for a [a classic MOSFET level shifter](http://elinux.org/RPi_GPIO_Interface_Circuits#Classic_MOSFET_level_shifter) built out of two BSS138 and four 10KΩ resistors. Make sure that the esp GPIO reads low (input mode) when HC-SR04 echo pin is driven low. If it reads high the R2 resistor needs lower resistance. \n\nWiring echo \u0026 trigger together on the 5V side does *not* work with a classic mosfet level shifter.\n\n![Single pin mode - voltage divider](/doc/esp_circuit_onepin_voltage_divider.png)\n\nAnother working solution is a voltage divider (5V to 3.3V) between HC-SR04 echo and ground. Connect HC-SR04 trigger and esp GPIO to the middle of the divider.\n\n\n### other sensors\nThe arduino library [newping](https://code.google.com/p/arduino-new-ping/) supports a whole range of ultrasonic sensors: SR04, SRF05, SRF06, DYP-ME007 \u0026 Parallax PING™. This without making any special hardware considerations in the code. So this library should work with those sensors as well.   \n\n## TODO\n\n* ~~inches~~\n* ~~single pin mode~~\n* ~~multiple sensors~~\n* ~~sdk v0.9.5 compability~~ \n* ~~check compability SRF05~~ SRF05 works w/o any modifications\n* check compability SRF06\n* check compability DYP-ME007\n* check compability Parallax PING™\n\n## License\n\nGPL V3\n\nThe makefile is copied from [esp_mqtt.](https://github.com/tuanpmt/esp_mqtt)\n\n###Building and installing:\n\nFirst you need to install the sdk and the easy way of doing that is to use [esp_open_sdk.](https://github.com/pfalcon/esp-open-sdk)\n\nYou can put that anywhere you like (/opt/local/esp-open-sdk, /esptools etc etc)\n\nThen you could create a small ```setenv.sh``` file, containing the location of your newly compiled sdk and other platform specific info;\n```\nexport SDK_BASE=/opt/local/esp-open-sdk/sdk\nexport PATH=${SDK_BASE}/../xtensa-lx106-elf/bin:${PATH}\nexport ESPPORT=/dev/ttyO0  \n```\n(or setup your IDE to do the same)\n\nTo make a clean build, flash and connect to the esp console you just do this in a shell:\n```\nsource setenv.sh # This is only needed once per session\nmake clean \u0026\u0026 make test\n```\n\nYou won't be needing esptool, the makefile only uses esptool.py (provided by [esp_open_sdk](https://github.com/pfalcon/esp-open-sdk))\n\nI have tested this with sdk v1.5.2, v0.9.4 and v0.9.5 (linux \u0026 mac)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feadf%2Fesp8266_ping","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feadf%2Fesp8266_ping","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feadf%2Fesp8266_ping/lists"}