RE: [beagleboard] interfacing HC-SR04 ultrasonic Sensor

Looks fairly simple, from the datasheet.

You generate an “initiate” signal using an IO pin and then measure the received pulse width with a timer input pin.

There is probably all kinds of open source code available, if this isn’t a school term project J

Hi!

BeagleBoard has GPIO pins rated only for 1.8V voltage level, however
HC-SR04 requires 5V operation. Therefore you need to enable 5V
translation of signals to and from the transducer. How you do it -
it's up to you. If you need help with HW - don't hesitate to ask me or
the community.
http://www.youtube.com/watch?feature=player_embedded&v=VQmElqlIKVg#!

Second, software:
there are open source libs for the Arduino platform but they are not
good for a not-RTOS like Linux. You need to add a driver for this
sensor to a kernel.
http://robocraft.ru/files/sensors/Ultrasonic/HC-SR04/ultrasonic-HC-SR04.zip

probably the best solution would be to connect this transducer to a
controller like AVR and interface the latter to a BeagleBoard by UART.
Of course you will have to support two sets of SW for two devices but
in this case all SW is already written and you need only to load it to
devices.

Ok i Got the initiate signal trick.
but (told u i am a newbie to linux embedded systems) how do i use the timer input pin … are these the GPTs ??
thank u :slight_smile:

Hi!

hey thanks for your response.

BeagleBoard has GPIO pins rated only for 1.8V voltage level, however
HC-SR04 requires 5V operation. Therefore you need to enable 5V
translation of signals to and from the transducer. How you do it -
it’s up to you. If you need help with HW - don’t hesitate to ask me or
the community.
http://www.youtube.com/watch?feature=player_embedded&v=VQmElqlIKVg#!

Ok, but i thin the sensors trigger doesn’t need a full 5 volts … it is just the Vcc or maybe i am wrong … i will try that and reply back.

Second, software:
there are open source libs for the Arduino platform but they are not
good for a not-RTOS like Linux. You need to add a driver for this
sensor to a kernel.
http://robocraft.ru/files/sensors/Ultrasonic/HC-SR04/ultrasonic-HC-SR04.zip

i saw that Arduino Library … i have been using Arduino for quite a while, it will be wonderful if i could know how to implement this line with my beagle (duration = pulseIn(Echo_pin,HIGH):wink: … it is the most concern i have now.

probably the best solution would be to connect this transducer to a
controller like AVR and interface the latter to a BeagleBoard by UART.
Of course you will have to support two sets of SW for two devices but
in this case all SW is already written and you need only to load it to
devices.

no please don’t say so :frowning: i want to be using the beagle board only it will be more powerful than other modules so that will slow down my work and as obvious i am working with a real time system.

it depends on what type of OS you use. Only hardware unit can measure
the time accurately, or it can also depend on a task you want to
solve. For example if you need just to know if there is an obstacle
near of the transducer or not then using general Linux is OK. Anyway
you need to work with registers of a CPU.

but i thin the sensors trigger doesn't need a full 5 volts

ok, assume so but the Echo output of the transducer is definitely 5V
and I'm 90% sure that driving a 5V input pin by 1.8V output does not
work. TTL requires 2.4V, CMOS needs VCC/2=2.5V

I played with a sonar sensor on the BeagleBone.

Made a blog post a while ago summarizing the results:

http://fleshandmachines.wordpress.com/2012/09/25/sonar-sensor-on-the-beaglebone-part-1-direct-approach/

Bence,

BeagleBoard != BeagleBone

There is not ADC at BeagleBoard

Do you have any C programming experience?

There is a female who has been asking the same questions on this list.

Does she have any C experience?

There are a number of people on the list that are into robotics, which sounds like your application.

As for measuring the pulse width. You wait for an input to go high, start a timer when it does and then wait for the pin to go low.

When it does, you stop the timer and read the value.

I’m sure if you look around you will find some robotics sample code that does this.

Good Luck !

Do you have any C programming experience?

There is a female who has been asking the same questions on this list.

Does she have any C experience?

biensur … have been coding c for a long time now … but it is my first time to code for a DSP.

There are a number of people on the list that are into robotics, which sounds like your application.

As for measuring the pulse width. You wait for an input to go high, start a timer when it does and then wait for the pin to go low.

When it does, you stop the timer and read the value.

well i have done the first part eventually … i am now able to know when the pin goes high and when it goes low.
been struggling for hours now to calculate the time.
please if you can give me any code snippet for the timer.
thanks

I’m sure if you look around you will find some robotics sample code that does this.

nothing available !!

Good Luck !

Thank You !

Here is what I would do:

Take a look at www.hackaday.com

They have a search feature and I have seen several robotics/autonomous vehicle designs there.

Also www.Sparkfun.com sells devices like you are using and they also have a robotics forum.