OpenWrt Forum Archive

Topic: Reading SR04 ultrasonic sensor connected to GPIO pins

The content of this topic has been archived on 14 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I'm looking for a low power, inexpensive system to read an SR04 ultrasonic sensor and have the output available on a built-in web server on a WIFI connection.    I am hoping to do this using a system running OpenWRT.

I've come across a GL-AR150 board (based on the Atheros 9331) which claims to have 5 GPIO pins, and I'm hoping I can wire an SR04 compatible sensor up to these, although if there are other more suitable boards I'm certainly happy to use a different one if it meets my needs.

The issue I have is that timing is quite critical - the SR04 sends a pulse and measures how many microseconds it takes to return, from which distance can be calculated.  I would thus assume that scripting something in BASH is not a viable option.   Does anyone know of a library or way I can send a trigger and then read the output of one of these sensors? 

I've found a couple of hints how this could be achieved on a Raspberry Pi - http://ananddrs.com/2014/03/11/raspberry-pi-ultrasonic/ and https://github.com/wdalmut/libultrasoni … /hc_sr04.c but both of these seem to call or relate to "bcm" - is there an equivalent way I can do this with on a basic OpenWRT based board with built in WIFI ?

Thanks,
David

For board, perhaps this Orange Pi PC will be a better buy than an RPi.

mazilo wrote:

For board, perhaps this Orange Pi PC will be a better buy than an RPi.

Thanks for the suggestion and question. 

I am planning on using a sensor like this one - its pin-for-pin compatible with the SR04 (I've used them before an an Arduino board) and, of-course, its waterproof.

The Orange PI PC certainly looks interesting and cheap, however I'm looking for something as low power as I can manage (bearing in mind my  limited programming skills and lack of IoT knowledge).   I was looking at  a GL-AR150  because its  power requirement is 1 watt (as opposed to 3 watts for an RPi Orange), and because it has WIFI with decent antenna  - which the RPi's don't seem to have -  I need to keep the power consumption low because the unit needs to be solar powered.   (And having a decent size antenna for < $1 is a valuable bonus)


The reason I posted in this forum is because the board runs OpenWRT.

davidgo wrote:

I'm looking for a low power, inexpensive system to read an SR04 ultrasonic sensor and have the output available on a built-in web server on a WIFI connection.

Not sure about this: ESP8266
Inexpensive, low power, Wifi, webserver.

Thanks for this.  From what I've researched the ESP8266 is not powerful enough to use directly as it does not expose 2 GPIO pins and (as far as I can see) does not provide the required functionality (particularly timer) for an SR04.   It is pretty cool though.

mazilo wrote:

For board, perhaps this Orange Pi PC will be a better buy than an RPi.

Orange Pi's hardware is good spec but software is bad, almost no official support, closed source, rarely official update and unusable for Openwrt. It's a piece of junk.

tomrev wrote:
mazilo wrote:

For board, perhaps this Orange Pi PC will be a better buy than an RPi.

Orange Pi's hardware is good spec but software is bad, almost no official support, closed source, rarely official update and unusable for Openwrt. It's a piece of junk.

Please kindly provide any link to support what you said above for posterity shake.

Sorry, davidgo for off topic.

mazilo wrote:
tomrev wrote:
mazilo wrote:

For board, perhaps this Orange Pi PC will be a better buy than an RPi.

Orange Pi's hardware is good spec but software is bad, almost no official support, closed source, rarely official update and unusable for Openwrt. It's a piece of junk.

Please kindly provide any link to support what you said above for posterity shake.



- "almost no official support" -

Because Orange Pi use Allwinner CPU, closed source and violated GPL - http://linux-sunxi.org/GPL_Violations , full of blob, code modification for developer is a bad dream. It is only usable level because of video hardware acceleration on Android but Linux is almost a garbage because no HW accel code FOSS or blob.  It is very limit to modify code for any platforms, so it a kind of dead board.

- "unusable for Openwrt" -
Some people still hopelessly wait for openwrt - http://www.orangepi.org/orangepibbsen/f … amp;page=2 .

I almost bought Orange Pi because of price and spec but after studied it a bad choice compare to competitors.

(Last edited by tomrev on 13 Jan 2016, 10:22)

Hello,

if your sensor works well on arduino, maybe you can plug it to a router like TL-WR703N
and read datas over serial connection ?

I am working with college students on a project to be able to send datas from a beehive to the web.

I have just managed to make the process working, maybe the sources can help you https://github.com/Jodaille/LyceeDesAnd … inoToLinux

(Last edited by Jodaille on 21 Apr 2016, 23:16)

The discussion might have continued from here.