A place users can post their projects. If you have a small project and would like your own dedicated place to post and have others chat about it then this is your spot.

User avatar
By EadF
#8960 Hi

I've made an esp8266 driver for the HC-SR04 ultrasonic sensor: https://github.com/eadf/esp8266_ping

It uses two, user defined, pins for the sensor. As such it seems to work fine (at least under sdk 0.9.4)

I've seen that the arduino libraries are able to use just one pin for this sensor - basically trigger and echo are wired together. And that's where i got a problem. The HC-SR04 is a 5V device, so i use a level shifter to protect the esp.
It seems like level shifter prevents the HC-SR04 from working in single pin mode. When i wire the pins together the 5V side (HC-SR04) is a flat line (low). - Yes: the esp has disabled output after the inital pulse.

Arduino one pin:
Image

Esp two pins (i need to merge these pins to one)
Image

Could anyone of you help me with this small (electrical?) problem?

I jut got an idea.. maybe i instead should wire the pins together at the 3V3 side..

http://elinux.org/RPi_GPIO_Interface_Circuits#Level_Shifters
User avatar
By alonewolfx2
#8976 i didnt see onewire hc-sr04 on your github where is it :)
User avatar
By EadF
#8986 Hi there Alonewolf!

Maybe the API is a bit cryptic, but you simply set trigger pin == echo pin. Like this:

Code: Select allint triggerPin = 0;
int echoPin = 0;
ping_init(triggerPin,echoPin); // sets one-pin mode on GPIO0


I could make a separate ping_initOnePinMode(int) function if anyone needs it.