I have a problem where when I use a HC-SR04 ultrasonic sensor with my Explorer HAT Pro it works fine when my HDMI screen is plugged into my pi and I get distance values ok. But when I take my HDMI cable out, I no longer get distance values. After calling eh.output.one.on() it gets stuck in the loop ‘while eh.input.one.read() == 0: pass’ never getting anything other than zero. But this is only if the HDMI cable is taken out otherwise it works. I have tried all sorts of combinations such as instead of using Input 1 and Output 1 instead use Input 3 and Output 3. Wondering if anyone has any ideas. I’m using code similar to that in the following thread:
http://forums.pimoroni.com/t/unreliable-hc-sr04-with-explorer-hat-pro/641
The issue I experienced with the Explorer HAT Pro was that there was enough going on in the board and the code that drives it to introduce unpredictable delays to the measurements taken from the HC-SR04, ie: the distance calculation would be plus or minus a lot and essentially useless. We worked out two different fixes for this:
- Swap to an analogue IR sensor (this is what I did) as the calculation is done in a different way.
or
- Use RPi.GPIO to directly work with the HC-SR04.
I have no idea why HDMI would cause a problem but option 2 may well be the way to go as it removes the eh. code from the mix. I think one of the respondents to my original post talked about how to do this.
Just a thought though: could this be a case of mixing up causation and correlation, ie: that the HDMI cable correlates to the issue but is not really the cause? For example, when you remove the HDMI cable you are likely to nudge the Pi a bit so are you accidentally nudging a wire to the sensor / breadboard and hence it stops working? Plugging the HDMI back in nudges it back. Worth checking just in case.
1 Like
I just tried RPi.GPIO but with TX and RX as GPIO 14 and 15 and resistors set up like:
and it worked when I took out the HDMI cable. I tried RPi.GPIO with Input 1 and Output 1 but it didn’t work.
Regarding nudging the HDMI, its definitely not from that since when I plug it back in it works, take it out it stops, plug it in it works. I might try to get another Raspberry Pi and see if thats the problem. I have an explorer hat and explorer hat pro and both behave the same way when I take out the HDMI cable so its not the hat.
Also regarding useless results, I will probably try an analog IR sensor if the results are too bad or I might try to work out how to connect an arduino that has HCSR04 on it and connect it to a raspberry pi via analogue.
My best guess is that it’s altering the ground potential of the Pi when plugged in/removed, but that seems far fetched. Does the HDMI cable have to be connected to anything at the other end?
1 Like
Seems it works if I plug my Pi into the monitor with monitors power off at the power point so maybe its a grounding problem. I did previously try just with a HDMI cable but with nothing attached to the other end and had the same problem where the HC-SR04 wouldn’t work.
Is it possible you’ve got the HC-SR04 wired up incorrectly?
Also is anything from the underside of the Explorer HAT contacting the metal of the HDMI shield?