Hi all,
For testing project, I would like to if it’s possible to connect a hc-sr04 (Ultrasonic Range Sensor) on fezhat ?
If yes how ?
Ragrds
Hi all,
For testing project, I would like to if it’s possible to connect a hc-sr04 (Ultrasonic Range Sensor) on fezhat ?
If yes how ?
Ragrds
@ sebillen - Would be helpful to know what kind of interface the sensor uses (Analog, SPI, I2C, etc.). That would help answer the question of how to use it with FEZ HAT.
Alternatively, you could include a link to info on the sensor, so that the folks you are hoping for an answer from don’t have to go search for the info.
Hi,
a link to connect hc-sr04 to Raspberry HC-SR04 Ultrasonic Range Sensor on the Raspberry Pi | The Pi Hut
I see that hc-sr04 use GPIO 23 and GPIO 24.
Thanks for your help,
Nicolas
You should be able to wire up the sensor similarly with the FEZ HAT. I would assume that the need for a voltage divider remains, so don’t forget that part.
In terms of the GPIO, I don’t think all of the RPi2’s GPIO are directly accessible, and GPIO 24 (labeled as DIO 24 on the HAT) is used for an LED, so you will likely need to use DIO 16 and DIO 26, which are exposed via the green terminal blocks (see the image here: [url]https://www.ghielectronics.com/catalog/product/500[/url]).
Take a look at the FEZ HAT developer guide ([url]https://www.ghielectronics.com/docs/329/fez-hat-developers-guide[/url]) for info on reading and writing from the DIO pins). There are WriteDigital and ReadDigital functions that take the pin number as an argument. So when you want to send a pulse, you would set the TRIG pin on the sensor to true (aka HIGH) using DigitalWrite, and then set it to false (aka LOW). Reading the ECHO pin would use DigitalRead.
The main differences in code are that you’d want to use DateTime.Now to get the time between the ECHO pin going high, and the pin going low. The rest should be quite similar.
Hope that helps.
Thanks a lot,
That’s work, just need to optimize Echo time measure.
Awesome. Glad it helped!