Hi,
So I'm trying to interact with an ultrasonic sensor from my Bela mini using the ultrasonic-distance example code (adapted to digital out triggering) with the view to integrating this into my main project that requires a larger block size (currently 2048) for some audio analysis.
I've found, however, that this example code only successfully obtains distance values when using a block size of 128 or lower and I'm not sure why this is? Maybe it is a limitation with the PulseIn library? Is there any way to use these sensors with a larger block size?
Thanks!
HC-SR04 ultrasonic sensor with larger block size c++
- Edited
adamg this is most likely because the digital out code does not work correctly with larger blocksizes. @giuliomoro noted that the fix would not be that easy... see here: https://forum.bela.io/d/34-lv2-ladspa-plugins/167
@lokki is right. This is the reason why the larger blocksize has not been rolled out to the master
branch yet . I thought - however - that only the digital out would be compromised, not the digital ins. do you have a Bela or BelaMini? In the former case, can you just test it with analog outs and digital ins (the stock example code, basically) and see if that works?
Another possible fix could be to call
pinMode(context, 0, gEchoDigitalInPin, INPUT);
pinMode(context, 0, gEchoDigitalOutPin, OUTPUT);
once for each call to render()
. Not sure if this helps?
I am using a BelaMini, have added the pinMode calls to render() and this seems to have fixed the issue for me, thanks very much!