Hello there, just dipping my toe into the fabulous Bela and wiring in general - so I'm a complete beginner. My question is as in the title, whether anyone has a Fritzing diagram for how to hook up a HC-SR04 ultrasonic sensor to the Bela? I'm nervous about getting the voltage divider right as I know I can kill the board otherwise...

I've been reading this in the meantime.

I had already found this for a Raspberry Pi setup, but I guess it shows the level of my competence if I still want to see one for the Bela!

Please help.

I don't use Fritzing, but this done in Preview should help you:

alt text

    Ha!! Giulio this is amazing. Thank you so much! Just to double check on the resistors: I read here that the resistors used should be 2.2k and 4.2k ohms? If so, will R1 be the 2.2k resistor and R2 be the 4.2k resistor, do I have that right? My thanks again.

    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...

    18 days later

    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).

    alt text

      6 days later

      Tractor I have the render file here with the accompanying Pd patch (sorry I'm not on Github just yet).

      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?

          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 ?

                giuliomoro
                Will do, and fear not, I'll most certainly be investing in things Bela... Keep the fire lit...