[HTML/IMAGE] Using an ultrasonic ranger

[HTML/IMAGE] Using an ultrasonic ranger

Postby admin » Wed Nov 04, 2015 5:04 pm

We will go through an example to print input signal of an ultrasonic ranger via a hyperlink embedded image by using a PHPoC Blue.

Image

PHPoC Blue diagram
Image

Source Codes
1. index.php
Code: Select all

<?php
 
include_once 
"/lib/sd_340.php";
 
// setup trigger pulse timer
ht_ioctl(0, "set mode output pulse");
ht_ioctl(0, "set div us");
ht_ioctl(0, "set repc 1");
ht_ioctl(0, "set count 5 10"); // 10us pulse width
 
// setup echo capture timer
ht_ioctl(1, "reset");
ht_ioctl(1, "set div us");
ht_ioctl(1, "set mode capture toggle");
ht_ioctl(1, "set trigger from pin rise");
ht_ioctl(1, "set repc 4");
 
ht_ioctl
(1, "start"); // we should start capture timer first
ht_ioctl(0, "start"); // start trigger pulse
 
usleep
(100000); // sleep 100ms
 
// 1st capture value ("get count 0") is always zero.
// we should get 2nd capture value;
$us = ht_ioctl(1, "get count 1");
 
$dist 
= $us * 340.0 / 2; // us to meter conversion
$dist = $dist / 10000; // meter to centimeter conversion
 
?>
<html>
<head>
<title>PHPoC / <?echo system("uname -i")?></title>
<meta name="viewport" content="width=device-width, initial-scale=0.5">
<style> body { text-align: center; }</style>
</head>
<body>
 
<h2>
 
HT / HC-SR04 Ultrasonic Module<br>
 
<img src="ht_ultrasonic.jpg"><br>
 
<?php
printf
("Pulse Width : %d us<br>\r\n", $us);
printf("Distance : %.1f cm<br>\r\n", $dist);
?>
 
<br><a href="index.php">reload</a><br>
 
</h2>
 
</body>
</html>


Please download a PSP (PHPoC Support Package) of libraries and examples from PHPoC, and upload it in the PHPoC Blue.



Video
phpBB [video]
admin
Site Admin
 
Posts: 166
Joined: Mon Jan 20, 2014 4:40 pm

Return to Example

Who is online

Users browsing this forum: No registered users and 1 guest