Yes, I did try that one. And got useful readings but not as precise

hmm that's sad. It would be interesting to compare them side-by-side

    giuliomoro
    I found the same as @tkay: as commented elsewhere, regular pulsing jumps in the Pd patch - introducing a kind of yodelling effect - which I tried to filter out. I experimented with the [delay] object for the output and that improved things a bit, but the combined C++/Pd approach still gives much better results.

    3 years later

    tkay
    Hello!
    I'm back trying to use the HC-SR-04 sensor, this time with a regular full size bela. However I'm getting some errors. I'm not sure if this:

    giuliomoro this one instead.
    was meant to be used with the mini only. I am now using the analog out instead and as instructed i commented out the #define ULTRASONIC_DISTANCE_DIGITAL_OUT I connected the echo in (with resistor divider of course) in digital in 8 (pd 19)
    What am I missing?

    Here's the full error message:

    In file render.cpp: no matching function for call to 'sys_doio' column: 3, line: 656
    In file render.cpp: call to function 'strcmp' that is neither visible in the template definition nor found by argument-dependent lookup column: 11, line: 59
    /root/Bela/projects/FX/render.cpp:656:3: error: no matching function for call to 'sys_doio'
    sys_doio();
    ~~~~
    /usr/local/include/libpd/s_stuff.h:243:12: note: candidate function not viable: requires single argument 'pd_that', but no arguments were provided
    extern int sys_doio(struct _pdinstance* pd_that);
    ^
    /root/Bela/projects/FX/render.cpp:59:11: error: call to function 'strcmp' that is neither visible in the template definition nor found by argument-dependent lookup
    if(0 == strcmp(id, db[n].first.c_str()))
    ^
    /root/Bela/projects/FX/render.cpp:544:13: note: in instantiation of function template specialization 'getIdxFromId<Trill *>' requested here
    int idx = getIdxFromId(sensorId, gTouchSensors);
    ^
    /usr/include/string.h:140:12: note: 'strcmp' should be declared prior to the call site
    extern int strcmp (const char *s1, const char *s2)
    ^
    2 errors generated.
    make: *** [/root/Bela/projects/FX/build/render.o] Error 1

    This has been "canonized" and the 2024 advice is: use the example PureData/custom-render-ultrasonic-distance-sensor that comes with the latest Bela core code. If it's not present on your board, it means you have to update your core code following this procedure.

    Awesome! thanks so much again

    Is it possible to recieve the values in a faster interval? it seems to be coming in pulses of 1 second

    The code seems to indicate it is being sent out every 60 milliseconds, you can check that by adding in render.cpp the following lines:

    static unsigned int last;
    unsigned int current = context->audioFramesElapsed + n;
    rt_printf("%u (%u) HIGH\n", current, current - last);
    last = current;

    at line 1659 (before the state = HIGH; line, within those curly braces).
    Then re run the program and see what gets printed there and how often.