项目作者: luigif

项目描述 :
Beaglebone Black PRU code for HC-SR04 sonar
高级语言: OpenEdge ABL
项目地址: git://github.com/luigif/hcsr04.git
创建时间: 2014-05-02T10:46:59Z
项目社区:https://github.com/luigif/hcsr04

开源协议:

下载


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:

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

Hardware configuration:

  1. * TRIGGER P8_12 gpio1[12] GPIO44 out pulldown Mode: 7
  2. * ECHO P8_11 gpio1[13] GPIO45 in pulldown Mode: 7 *** with R 1KOhm
  3. * GND P9_1 or P9_2 GND
  4. * VCC P9_5 or P9_6 VDD_5V
  5. Make sure there is a 1KOhm resistor between ECHO pin and your beaglebone
  6. as input pins are 3.3V while sensor emits 5V

Schematic:

Schematic

To download the complete package to your Beaglebone Black:

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

To build:

  1. cd hcsr04-master
  2. make

To install driver:

  1. make install
  2. It will copy device tree driver to /lib/firmware and add it to the cape manager

To run:

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

Example build output after running “make”:

  1. >> Compiling Driver
  2. dtc -O dtb -o hcsr04-00A0.dtbo -b 0 -@ hcsr04.dts
  3. >> Generating PRU binary
  4. pasm -b hcsr04.p
  5. PRU Assembler Version 0.84
  6. Copyright (C) 2005-2013 by Texas Instruments Inc.
  7. Pass 2 : 0 Error(s), 0 Warning(s)
  8. Writing Code Image of 43 word(s)
  9. >> Compiling HC-SR04 example
  10. gcc -Wall -c -o hcsr04.o hcsr04.c
  11. gcc -lpthread -lprussdrv -o hcsr04 hcsr04.o

Example output after running “./hcsr04”:

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

Reference material: