Code Monkey home page Code Monkey logo

hcsr04's Introduction

Beaglebone Black PRU code to use HC-SR04 proximity sensor.

There are many examples around with Beaglebone PRU code to use an HC-SR04 sonar sensor, but most are outdated, do not work or require older beagles or older kernels. This repository includes everything needed to obtain a working example and can be used as a template for more complex PRU code.

Prerequisites:

* Beaglebone Black with debian 3.8.13 bone47
* HC-SR04 sensor
* Dev tools (gcc, pasm, dtc, etc.) that are already included in BBB latest images.
  (If you miss them, please upgrade from http://beagleboard.org/latest-images/)

Hardware configuration:

* TRIGGER		P8_12 gpio1[12] GPIO44	out	pulldown		Mode: 7 
* ECHO			P8_11 gpio1[13] GPIO45	in	pulldown		Mode: 7 *** with R 1KOhm
* GND			P9_1 or P9_2	GND
* VCC			P9_5 or P9_6	VDD_5V

Make sure there is a 1KOhm resistor between ECHO pin and your beaglebone
as input pins are 3.3V while sensor emits 5V

Schematic:

Schematic

To download the complete package to your Beaglebone Black:

wget --no-check-certificate https://github.com/luigif/hcsr04/archive/master.tar.gz -O - | tar xz

To build:

cd hcsr04-master
make

To install driver:

make install

It will copy device tree driver to /lib/firmware and add it to the cape manager

To run:

./hcsr04

Note: After a first successful "make install", before running the hcsr04 program, 
you can load the driver with the install-driver.sh script.
Depending on your needs, you can configure your operating system to run the 
install-driver.sh script at boot.

Example build output after running "make":

>> Compiling Driver
dtc -O dtb -o hcsr04-00A0.dtbo -b 0 -@ hcsr04.dts

>> Generating PRU binary
pasm -b hcsr04.p
PRU Assembler Version 0.84
Copyright (C) 2005-2013 by Texas Instruments Inc.
Pass 2 : 0 Error(s), 0 Warning(s)
Writing Code Image of 43 word(s)

>> Compiling HC-SR04 example
gcc -Wall -c -o hcsr04.o hcsr04.c
gcc -lpthread -lprussdrv -o hcsr04 hcsr04.o

Example output after running "./hcsr04":

>> Initializing PRU
>> Executing HCSR-04 code
  1: Distance = 181.52 cm
  2: Distance = 181.50 cm
  3: Distance = 181.50 cm
  4: Distance = 181.52 cm
  5: Distance = 181.93 cm
  6: Distance = 181.52 cm
  7: Distance = 180.64 cm
  8: Distance = 181.50 cm
  9: Distance = 181.06 cm
 10: Distance = 181.49 cm
 11: Distance = 181.04 cm
 12: Distance = 181.93 cm
 13: Distance = 181.47 cm
 14: Distance = 181.47 cm
 15: Distance = 181.91 cm
 16: Distance = 181.91 cm
 17: Distance = 181.47 cm
 18: Distance = 182.35 cm
 19: Distance = 181.49 cm
 20: Distance = 181.06 cm
>> PRU Disabled.

Reference material:

hcsr04's People

Contributors

luigif avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

hcsr04's Issues

Incorrect setup graphic?

Hey, I've been trying to get this to work on my BBB. I've setup my circuit like 40 times by now in the same fashion shown on your git but everytime I run the program it executes as the following

  • ./hcsr04

    Initializing PRU
    Executing HCSR-04 code
    1: Distance = 4.16 cm
    2: Distance = 4.16 cm
    3: Distance = 4.16 cm
    4: Distance = 4.16 cm
    5: Distance = 4.16 cm
    6: Distance = 4.16 cm
    7: Distance = 4.16 cm
    8: Distance = 4.16 cm
    9: Distance = 4.16 cm
    10: Distance = 4.16 cm
    11: Distance = 4.16 cm
    12: Distance = 4.16 cm
    13: Distance = 4.16 cm
    14: Distance = 4.16 cm
    15: Distance = 4.16 cm
    16: Distance = 4.16 cm
    17: Distance = 4.16 cm
    18: Distance = 4.16 cm
    19: Distance = 4.16 cm
    20: Distance = 4.16 cm
    PRU Disabled.

Any ideas what I might be doing wrong?

Directory nonexistent

I'm trying to run your code on a BeagleBone Black with Debian 9.5. I am able to successfully run 'make', but when I try to 'make install', I get the following error:
debian@beaglebone:~/hcsr04-master$ make install
cp hcsr04-00A0.dtbo /lib/firmware
echo hcsr04 > /sys/devices/bone_capemgr.9/slots
/bin/sh: 1: cannot create /sys/devices/bone_capemgr.9/slots: Directory nonexistent
Makefile:25: recipe for target 'install' failed
make: *** [install] Error 2

Any pointers would be greatly appreciated

/sys/devices/bone_capemgr.9/slots: Directory nonexistent

Hello,

Please I have the same problem I get the following error when I run make install command
bin/sh: 1: cannot create /sys/devices/bone_capemgr.9/slots: Directory nonexistent
And I tried the change on /boot/uEnv.txt file solution, but the problem is not solved
I tried also to run ./hcsr04 command and I get the following errors

>> Initializing PRU
>> PRU open failed

PLease is there any other solution?

debian@beaglebone:~/hcsr04-master$ make install
cp hcsr04-00A0.dtbo /lib/firmware
echo hcsr04 > /sys/devices/bone_capemgr.9/slots
/bin/sh: 1: cannot create /sys/devices/bone_capemgr.9/slots: Directory nonexistent
Makefile:25: recipe for target 'install' failed
make: *** [install] Error 2

Originally posted by @FMN2021 in #3 (comment)

It's working, but I have questions....

thanks for writing this - at least I know that the HCSR04 will work with my BBB -
but I have a question.

Is it normal that I have to execute a "make install" each time I boot up the BBB?
and is there away to prevent doing this if it's not normal?

This works and seems to work fine (distances are very consentant) - what I really need or want is a python library for the HCSR04 do you know of any?

Thanks again.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.