I don't use Fritzing, but this done in Preview should help you:
Fritzing diagram for HC-SR04 to Bela?
the ones in the diagram are also fine. The important things are that:
R1 + R2
is large enough (e.g.: larger than 1k)R2 / (R1 + R2)
is about 0.66, to ensure 5V gets divided down to 3.3V
Good, I'll go with that. Off I go to study my basics... I'll let you know how I get on. Thanks again, what a great piece of kit! congratulations to all on the Bela team...
- Edited
giuliomoro
So Bela and the HC-SR04 hooked up and spoke very politely to each other, and neither killed the other thanks to your much-appreciated guidance . The Pd-only solutions - your own one in there - for the HC also work nicely (these are here and here for anyone hunting like me), but I'm also interested in the C++/Pd approach, to see how the distance readings from that are. My setup is as above, using analog out and digital in, and I attempted to integrate the default render file for Bela projects running Pd patches using libpd code from here with the render file written for the HC-SR04 here. It's running on Bela without errors, but I'm getting nothing on the scope - just the two lines doing nothing - or in print. I've been back and forth checking, but can't seem to find what's missing. Suggestions extremely welcome...
I have the render file here with the accompanying Pd patch (sorry I'm not on Github just yet).
- Edited
Uh that's an old starting point!
Tractor using analog out
It seems that you have renamed gTriggerDigitalOutChannel
to gTriggerAnalogOutChannel
but you still have
digitalWriteOnce(context, n, gTriggerDigitalOutChannel, HIGH);
and
digitalWriteOnce(context, n, gTriggerAnalogOutChannel, LOW);
these should become analogWriteOnce()
instead.
giuliomoro
Thanks for having a look! No joy unfortunately; I made the changes you suggested, with the code now as follows:
analogWriteOnce(context, n, gTriggerAnalogOutChannel, HIGH); //write the status to the trig pin
} else {
analogWriteOnce(context, n, gTriggerAnalogOutChannel, LOW); //write the status to the trig pin
however the result is the same: no errors, but no data either in the scope or in print. I poked around a bit and experimented, with more checking back and forth. I can't seem to find what's amiss...
could you go back to the original file (except for the init()
->setup()
change, try it with a digital out and verify it works?
giuliomoro
Sorry which original file do you mean?
- Edited
nevermind.
Use this one instead.
Follow instructions to enable analog out instead of digital out
(also note the receiver name is now distance
(not distance1
))
giuliomoro
Hats off to you my friend, not least for your patience with learners. Thank you indeed, this is so much appreciated. I got it up and running and began prodding and tweaking to see what I could learn.
Question 1: to increase the rate at which readings are generated/arrive - and the responsivity of the HC - I've been adjusting
unsigned int gPulseTriggerIntervalMs = 60;
and 10ms gets me to where I want - is this the best way to go about it? Should I be tweaking anywhere else?
Question 2: Is there anywhere I can donate to you guys?
Tractor and 10ms gets me to where I want - is this the best way to go about it? Should I be tweaking anywhere else?
the datasheet (https://cdn.sparkfun.com/datasheets/Sensors/Proximity/HCSR04.pdf) says
we suggest to use over 60ms measurement cycle, in order to prevent trigger signal to the echo signal.
Not sure what the exact reason is, as the wording of the datasheet is pretty creative ... I guess if 10ms works for you, it's good! Note that that will reduce the maximum distance you can sense to (10000 / 58) = 172cm
(or probably a bit less).
Tractor Question 2: Is there anywhere I can donate to you guys?
thanks for the offer, we don't have anything set up at the moment, may look into that if it's not too complicated and will let you know if it happens. Until then, the best way to support us is by spreading the word and buying more of our stuff! Maybe you or some of your friends need a Trill capacitive sensor ?
- Edited
giuliomoro
Will do, and fear not, I'll most certainly be investing in things Bela... Keep the fire lit...