We have upgraded the community system as part of the upgrade a password reset is required for all users before login in.

connect Ultrasonic Sensor HC-SR04 using r-pi-usonic package

  • Hi,

    I'm new to Onion omega product, recently bought the omega2+ and trying to connect with ultrasonic sensor(HC-SR04) to get the distance in Nodejs with GPIO. Noticed there is no implementation on this topic or no sample project. I just want to check is there anyone used r-pi-usonic package to get the distance in the Omega2+ device?

  • @Hemakumar-ellini Though I haven't got one of those sensors, there are plenty of implementations online with Arduino so I think it's gonna be a piece of cake for you to port that code to python (or leave it in C, as you like) and make a few changes to use onion's GPIO library. If I were you, I'd write the code to communicate with the sensor in C or Python and send the readings to my NodeJS code.

    Docs for Omega GPIO : Python
    Docs for using Omega GPIOs

    Anyways, sorry I can't be of more help. Hope this gives you some ideas to start off with!

  • @Allison-K Unfortunately Arduino and similar microcontroller approaches really aren't portable to a multitasking platform like the Omega, Pi, C.H.I.P or similar.

    This is because the task scheduler introduces substantially latency in the running of ordinary programs, often up to 20 ms or so.

    Sound moves at approximately 344 meters per second, so it covers 344 mm in one millisecond. Given the roundtrip timing, a 1 ms timing error woud be half that: 172 mm or about 6 3/4 inches, and the timing uncertainty may well be more than this.

    Viable approaches would need to do one of

    • Use a hardware timer
    • Use kernel mode code
    • Use an interrupt (GPIO interrupts to userspace are not currently enabled)
    • Use some continous streaming data interface, for example the I2S audio which can capture at a regular rate and have it capture both the trigger and echo, then measure the elapsed time as the number of samples recorded between these events
    • Use a helper MCU like an ATtiny or a full Arduino to take the measurement and report the result

Log in to reply

Looks like your connection to Community was lost, please wait while we try to reconnect.