Wednesday, 13 November 2013
live streaming of video using beaglebone black
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="newstyle.css" rel="stylesheet" type="text/css" />
<title>Untitled Document</title>
</head>
<body>
<div id="main"><fieldset><legend><font size="+1" color="#000000">DOOR CONTROLS</font></legend>
<form action="stream_simple.php" method="post" enctype="multipart/form-data" name="form1">
<a href="http://billnitte.in/homewindow/mobile.php"><img src="Untitled.png" /></a>
<label><h3><font color="#000000">STATUS:</font></h3></label>
</br>
</br>
</br><fieldset><center>
<input name="open" type="submit" value="OPEN" />
<input name="closed" type="submit" value="CLOSED" /></center>
</fieldset>
</fieldset>
</form>
</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="newstyle.css" rel="stylesheet" type="text/css" />
<title>Untitled Document</title>
</head>
<body>
<div id="main"><fieldset><legend><font size="+1" color="#000000">DOOR CONTROLS</font></legend>
<form action="stream_simple.php" method="post" enctype="multipart/form-data" name="form1">
<a href="http://billnitte.in/homewindow/mobile.php"><img src="Untitled.png" /></a>
<label><h3><font color="#000000">STATUS:</font></h3></label>
</br>
</br>
</br><fieldset><center>
<input name="open" type="submit" value="OPEN" />
<input name="closed" type="submit" value="CLOSED" /></center>
</fieldset>
</fieldset>
</form>
</div>
</body>
</html>
opening door(a simple program for beaglebone black)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="newstyle.css" rel="stylesheet" type="text/css" />
<title>Untitled Document</title>
</head>
<body>
<div id="main"><fieldset><legend><font size="+1" color="#000000">DOOR CONTROLS</font></legend>
<form action="door.php" method="post" enctype="multipart/form-data" name="form1">
<a href="http://billnitte.in/homewindow/mobile.php"><img src="Untitled.png" /></a>
<label><h3><font color="#000000">STATUS:</font></h3></label>
</br>
</br>
</br><fieldset><center>
<input name="open" type="submit" value="OPEN" />
<input name="closed" type="submit" value="CLOSED" /></center>
</fieldset>
</fieldset>
</form>
</div>
<?php
if (isset($_POST['open']))
{
$result = 'turned off';
exec("echo 0 > /sys/class/gpio/gpio60/value");
// exec("/bin/echo 0 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['closed']))
{
$result = 'turned on';
exec("echo 1 > /sys/class/gpio/gpio60/value");
echo $var1 = exec("cat /sys/devices/ocp.2/helper.14/AIN0");
// exec("/bin/echo 1 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
?>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="newstyle.css" rel="stylesheet" type="text/css" />
<title>Untitled Document</title>
</head>
<body>
<div id="main"><fieldset><legend><font size="+1" color="#000000">DOOR CONTROLS</font></legend>
<form action="door.php" method="post" enctype="multipart/form-data" name="form1">
<a href="http://billnitte.in/homewindow/mobile.php"><img src="Untitled.png" /></a>
<label><h3><font color="#000000">STATUS:</font></h3></label>
</br>
</br>
</br><fieldset><center>
<input name="open" type="submit" value="OPEN" />
<input name="closed" type="submit" value="CLOSED" /></center>
</fieldset>
</fieldset>
</form>
</div>
<?php
if (isset($_POST['open']))
{
$result = 'turned off';
exec("echo 0 > /sys/class/gpio/gpio60/value");
// exec("/bin/echo 0 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['closed']))
{
$result = 'turned on';
exec("echo 1 > /sys/class/gpio/gpio60/value");
echo $var1 = exec("cat /sys/devices/ocp.2/helper.14/AIN0");
// exec("/bin/echo 1 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
?>
</body>
</html>
water tank controlling with beaglebone black
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="newstyle.css" rel="stylesheet" type="text/css" />
<title>Untitled Document</title>
</head>
<body>
<div id="main"><fieldset><legend><font size="+1" color="#000000">TANK CONTROLS</font></legend>
<form action="tank.php" method="post" enctype="multipart/form-data" name="form1">
<a href="http://billnitte.in/homewindow/mobile.php"><img src="Untitled.png" /></a>
<label><h3><font color="#000000">WATER LEVEL STATUS:</font></h3></label>
</br>
</br>
</br><fieldset><center><label><font color="#000000">PUMP</font></label>
<input name="open" type="submit" value="ON" />
<input name="closed" type="submit" value="OFF" /></center>
</fieldset>
</fieldset>
</form>
<?php
if (isset($_POST['open']))
{
$result = 'turned off';
exec("echo 0 > /sys/class/gpio/gpio60/value");
// exec("/bin/echo 0 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['closed']))
{
$result = 'turned on';
exec("echo 1 > /sys/class/gpio/gpio60/value");
echo $var1 = exec("cat /sys/devices/ocp.2/helper.14/AIN0");
// exec("/bin/echo 1 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
?>
</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="newstyle.css" rel="stylesheet" type="text/css" />
<title>Untitled Document</title>
</head>
<body>
<div id="main"><fieldset><legend><font size="+1" color="#000000">TANK CONTROLS</font></legend>
<form action="tank.php" method="post" enctype="multipart/form-data" name="form1">
<a href="http://billnitte.in/homewindow/mobile.php"><img src="Untitled.png" /></a>
<label><h3><font color="#000000">WATER LEVEL STATUS:</font></h3></label>
</br>
</br>
</br><fieldset><center><label><font color="#000000">PUMP</font></label>
<input name="open" type="submit" value="ON" />
<input name="closed" type="submit" value="OFF" /></center>
</fieldset>
</fieldset>
</form>
<?php
if (isset($_POST['open']))
{
$result = 'turned off';
exec("echo 0 > /sys/class/gpio/gpio60/value");
// exec("/bin/echo 0 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['closed']))
{
$result = 'turned on';
exec("echo 1 > /sys/class/gpio/gpio60/value");
echo $var1 = exec("cat /sys/devices/ocp.2/helper.14/AIN0");
// exec("/bin/echo 1 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
?>
</div>
</body>
</html>
style.css for beaglebone black to work with php
@charset "utf-8";
/* CSS Document */
body {
margin: 0;
padding: 0;
line-height: 1.5em;
font-family: Verdana, Arial, san-serif;
font-size: 11px;
color: #dddcdc;
background-color:#063;
}
#main
{
position:absolute;
clear: both;
padding: 10px 20px;
color:#039;
height: 400px;
left: 450px;
top: 170px;
width: 364px;
}
/* CSS Document */
body {
margin: 0;
padding: 0;
line-height: 1.5em;
font-family: Verdana, Arial, san-serif;
font-size: 11px;
color: #dddcdc;
background-color:#063;
}
#main
{
position:absolute;
clear: both;
padding: 10px 20px;
color:#039;
height: 400px;
left: 450px;
top: 170px;
width: 364px;
}
project to control garden using beaglebone black
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="newstyle.css" rel="stylesheet" type="text/css" />
<title>Untitled Document</title>
</head>
<body>
<div id="main"><fieldset><legend><font size="+1" color="#000000">GARDEN CONTROLS</font></legend>
<form action="garden.php" method="post" enctype="multipart/form-data" name="form1">
<a href="http://billnitte.in/homewindow/mobile.php"><img src="Untitled.png" /></a>
<label><h4><font color="#000000">SENSOR1:</font></h4></label>
<label><h4><font color="#000000">SENSOR2:</font></h4></label>
</br><fieldset><center><label><font color="#000000">VALVE 1</font></label>
<input name="open" type="submit" value="ON" />
<input name="closed" type="submit" value="OFF" /></br></br>
<label><font color="#000000">VALVE2</font></label>
<input name="open1" type="submit" value="ON" />
<input name="closed1" type="submit" value="OFF" />
</center>
</fieldset>
</fieldset>
</form>
<?php
if (isset($_POST['open']))
{
$result = 'turned off';
exec("echo 0 > /sys/class/gpio/gpio60/value");
// exec("/bin/echo 0 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['closed']))
{
$result = 'turned on';
exec("echo 1 > /sys/class/gpio/gpio60/value");
echo $var1 = exec("cat /sys/devices/ocp.2/helper.14/AIN0");
// exec("/bin/echo 1 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['open1']))
{
$result = 'turned off';
exec("echo 0 > /sys/class/gpio/gpio60/value");
// exec("/bin/echo 0 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['closed1']))
{
$result = 'turned on';
exec("echo 1 > /sys/class/gpio/gpio60/value");
echo $var1 = exec("cat /sys/devices/ocp.2/helper.14/AIN0");
// exec("/bin/echo 1 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
?>
</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="newstyle.css" rel="stylesheet" type="text/css" />
<title>Untitled Document</title>
</head>
<body>
<div id="main"><fieldset><legend><font size="+1" color="#000000">GARDEN CONTROLS</font></legend>
<form action="garden.php" method="post" enctype="multipart/form-data" name="form1">
<a href="http://billnitte.in/homewindow/mobile.php"><img src="Untitled.png" /></a>
<label><h4><font color="#000000">SENSOR1:</font></h4></label>
<label><h4><font color="#000000">SENSOR2:</font></h4></label>
</br><fieldset><center><label><font color="#000000">VALVE 1</font></label>
<input name="open" type="submit" value="ON" />
<input name="closed" type="submit" value="OFF" /></br></br>
<label><font color="#000000">VALVE2</font></label>
<input name="open1" type="submit" value="ON" />
<input name="closed1" type="submit" value="OFF" />
</center>
</fieldset>
</fieldset>
</form>
<?php
if (isset($_POST['open']))
{
$result = 'turned off';
exec("echo 0 > /sys/class/gpio/gpio60/value");
// exec("/bin/echo 0 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['closed']))
{
$result = 'turned on';
exec("echo 1 > /sys/class/gpio/gpio60/value");
echo $var1 = exec("cat /sys/devices/ocp.2/helper.14/AIN0");
// exec("/bin/echo 1 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['open1']))
{
$result = 'turned off';
exec("echo 0 > /sys/class/gpio/gpio60/value");
// exec("/bin/echo 0 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['closed1']))
{
$result = 'turned on';
exec("echo 1 > /sys/class/gpio/gpio60/value");
echo $var1 = exec("cat /sys/devices/ocp.2/helper.14/AIN0");
// exec("/bin/echo 1 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
?>
</div>
</body>
</html>
controlling gate using beaglebone black
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="newstyle.css" rel="stylesheet" type="text/css" />
<title>Untitled Document</title>
</head>
<body>
<div id="main"><fieldset><legend><font size="+1" color="#000000">GATE CONTROLS</font></legend>
<form action="gate.php" method="post" enctype="multipart/form-data" name="form1">
<a href="http://billnitte.in/homewindow/mobile.php"><img src="Untitled.png" /></a>
<label><h3><font color="#000000">STATUS:</font></h3></label>
</br>
</br>
</br><fieldset><center>
<input name="open" type="submit" value="OPEN" />
<input name="closed" type="submit" value="CLOSED" /></center>
</fieldset>
</fieldset>
</form>
if (isset($_POST['open']))
{
$result = 'turned on';
exec("echo 1 > /sys/class/gpio/gpio60/value");
echo $var1 = exec("cat /sys/devices/ocp.2/helper.14/AIN0");
// exec("/bin/echo 1 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['closed']))
{
$result = 'turned off';
exec("echo 0 > /sys/class/gpio/gpio60/value");
// exec("/bin/echo 0 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="newstyle.css" rel="stylesheet" type="text/css" />
<title>Untitled Document</title>
</head>
<body>
<div id="main"><fieldset><legend><font size="+1" color="#000000">GATE CONTROLS</font></legend>
<form action="gate.php" method="post" enctype="multipart/form-data" name="form1">
<a href="http://billnitte.in/homewindow/mobile.php"><img src="Untitled.png" /></a>
<label><h3><font color="#000000">STATUS:</font></h3></label>
</br>
</br>
</br><fieldset><center>
<input name="open" type="submit" value="OPEN" />
<input name="closed" type="submit" value="CLOSED" /></center>
</fieldset>
</fieldset>
</form>
if (isset($_POST['open']))
{
$result = 'turned on';
exec("echo 1 > /sys/class/gpio/gpio60/value");
echo $var1 = exec("cat /sys/devices/ocp.2/helper.14/AIN0");
// exec("/bin/echo 1 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['closed']))
{
$result = 'turned off';
exec("echo 0 > /sys/class/gpio/gpio60/value");
// exec("/bin/echo 0 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
</div>
</body>
</html>
project for controlling home appliances using beaglebone black
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="newstyle.css" rel="stylesheet" type="text/css" />
<title>Untitled Document</title>
</head>
<body>
<div id="main"><fieldset><legend><font size="+1" color="#000000">HALL CONTROLS</font></legend>
<form action="hall.php" method="post" enctype="multipart/form-data" name="form1">
<a href="http://billnitte.in/homewindow/mobile.php"><img src="Untitled.png" /></a>
<label><h3><font color="#000000">STATUS:</font></h3></label>
</br>
</br>
</br><fieldset><center>
<label>LIGHT 1</label>
<input name="open" type="submit" value="ON" />
<input name="closed" type="submit" value="OFF" /></br>
</br>
<label>LIGHT 2</label>
<input name="open1" type="submit" value="ON" />
<input name="closed1" type="submit" value="OFF" /></br></br>
<label>TUBE 1</label>
<input name="open2" type="submit" value="ON" />
<input name="closed2" type="submit" value="OFF" /></br></br>
<label>TUBE 2</label>
<input name="open3" type="submit" value="ON" />
<input name="closed3" type="submit" value="OFF" /></br></br>
<label>FAN</label>
<input name="open4" type="submit" value="ON" />
<input name="closed4" type="submit" value="OFF" />
</center>
</fieldset>
</fieldset>
</form>
<?php
if (isset($_POST['open']))
{
$result = 'turned on';
exec("echo 1 > /sys/class/gpio/gpio60/value");
echo $var1 = exec("cat /sys/devices/ocp.2/helper.14/AIN0");
// exec("/bin/echo 1 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['closed']))
{
$result = 'turned off';
exec("echo 0 > /sys/class/gpio/gpio60/value");
// exec("/bin/echo 0 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['open1']))
{
$result = 'turned on';
exec("echo 1 > /sys/class/gpio/gpio60/value");
echo $var1 = exec("cat /sys/devices/ocp.2/helper.14/AIN0");
// exec("/bin/echo 1 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['closed1']))
{
$result = 'turned off';
exec("echo 0 > /sys/class/gpio/gpio60/value");
// exec("/bin/echo 0 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['open2']))
{
$result = 'turned on';
exec("echo 1 > /sys/class/gpio/gpio60/value");
echo $var1 = exec("cat /sys/devices/ocp.2/helper.14/AIN0");
// exec("/bin/echo 1 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['closed2']))
{
$result = 'turned off';
exec("echo 0 > /sys/class/gpio/gpio60/value");
// exec("/bin/echo 0 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['open3']))
{
$result = 'turned on';
exec("echo 1 > /sys/class/gpio/gpio60/value");
echo $var1 = exec("cat /sys/devices/ocp.2/helper.14/AIN0");
// exec("/bin/echo 1 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['closed3']))
{
$result = 'turned off';
exec("echo 0 > /sys/class/gpio/gpio60/value");
// exec("/bin/echo 0 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['open4']))
{
$result = 'turned on';
exec("echo 1 > /sys/class/gpio/gpio60/value");
echo $var1 = exec("cat /sys/devices/ocp.2/helper.14/AIN0");
// exec("/bin/echo 1 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['closed4']))
{
$result = 'turned off';
exec("echo 0 > /sys/class/gpio/gpio60/value");
// exec("/bin/echo 0 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
?>
</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="newstyle.css" rel="stylesheet" type="text/css" />
<title>Untitled Document</title>
</head>
<body>
<div id="main"><fieldset><legend><font size="+1" color="#000000">HALL CONTROLS</font></legend>
<form action="hall.php" method="post" enctype="multipart/form-data" name="form1">
<a href="http://billnitte.in/homewindow/mobile.php"><img src="Untitled.png" /></a>
<label><h3><font color="#000000">STATUS:</font></h3></label>
</br>
</br>
</br><fieldset><center>
<label>LIGHT 1</label>
<input name="open" type="submit" value="ON" />
<input name="closed" type="submit" value="OFF" /></br>
</br>
<label>LIGHT 2</label>
<input name="open1" type="submit" value="ON" />
<input name="closed1" type="submit" value="OFF" /></br></br>
<label>TUBE 1</label>
<input name="open2" type="submit" value="ON" />
<input name="closed2" type="submit" value="OFF" /></br></br>
<label>TUBE 2</label>
<input name="open3" type="submit" value="ON" />
<input name="closed3" type="submit" value="OFF" /></br></br>
<label>FAN</label>
<input name="open4" type="submit" value="ON" />
<input name="closed4" type="submit" value="OFF" />
</center>
</fieldset>
</fieldset>
</form>
<?php
if (isset($_POST['open']))
{
$result = 'turned on';
exec("echo 1 > /sys/class/gpio/gpio60/value");
echo $var1 = exec("cat /sys/devices/ocp.2/helper.14/AIN0");
// exec("/bin/echo 1 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['closed']))
{
$result = 'turned off';
exec("echo 0 > /sys/class/gpio/gpio60/value");
// exec("/bin/echo 0 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['open1']))
{
$result = 'turned on';
exec("echo 1 > /sys/class/gpio/gpio60/value");
echo $var1 = exec("cat /sys/devices/ocp.2/helper.14/AIN0");
// exec("/bin/echo 1 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['closed1']))
{
$result = 'turned off';
exec("echo 0 > /sys/class/gpio/gpio60/value");
// exec("/bin/echo 0 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['open2']))
{
$result = 'turned on';
exec("echo 1 > /sys/class/gpio/gpio60/value");
echo $var1 = exec("cat /sys/devices/ocp.2/helper.14/AIN0");
// exec("/bin/echo 1 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['closed2']))
{
$result = 'turned off';
exec("echo 0 > /sys/class/gpio/gpio60/value");
// exec("/bin/echo 0 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['open3']))
{
$result = 'turned on';
exec("echo 1 > /sys/class/gpio/gpio60/value");
echo $var1 = exec("cat /sys/devices/ocp.2/helper.14/AIN0");
// exec("/bin/echo 1 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['closed3']))
{
$result = 'turned off';
exec("echo 0 > /sys/class/gpio/gpio60/value");
// exec("/bin/echo 0 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['open4']))
{
$result = 'turned on';
exec("echo 1 > /sys/class/gpio/gpio60/value");
echo $var1 = exec("cat /sys/devices/ocp.2/helper.14/AIN0");
// exec("/bin/echo 1 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
if (isset($_POST['closed4']))
{
$result = 'turned off';
exec("echo 0 > /sys/class/gpio/gpio60/value");
// exec("/bin/echo 0 > /sys/class/leds/beaglebone:green:usr3/brightness");
}
?>
</div>
</body>
</html>
sensor example with beaglebone black
//build file
echo 60 > /sys/class/gpio/export
echo 30 > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio60/direction
echo "out" > /sys/class/gpio/gpio30/direction
/Program to sense using the sensor
#include <stdio.h> //header files
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <time.h>
int jeet(char *string){ //function to change array to interger
int value = atoi(string);
return value;
}
int main()
{
int x=0;
char c;
int fd = open("/sys/class/gpio/gpio60/value", "r");//open the value directory in read mode
while(1)
{
char buffer[1];
int r = read (fd, buffer,sizeof(buffer));//read the value from the fd and store it in r
//printf("value:%d\n",r);
if(r != '\0' ){ //read the value of r
buffer[r] = '\0';
int vin = jeet(buffer); //stored buffer value will be converted and stored in the int value vin
printf("val:%d\n", vin);//print that value on the screen
if(vin==1){
printf("\"1\"high\n");
system("echo 0 > /sys/class/gpio/gpio30/value"); //if the read value is high then redirect 0 to value file
}
else
{
printf("\"0\"low\n");
system("echo 1 > /sys/class/gpio/gpio30/value");//if it s low then give 1 to value file
}
lseek(fd,0,0);// move the filedescriptor to the starting position of the file
}
sleep(1);//sleep for a time period
}
close(fd);//close the filedescriptor
}
echo 60 > /sys/class/gpio/export
echo 30 > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio60/direction
echo "out" > /sys/class/gpio/gpio30/direction
/Program to sense using the sensor
#include <stdio.h> //header files
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <time.h>
int jeet(char *string){ //function to change array to interger
int value = atoi(string);
return value;
}
int main()
{
int x=0;
char c;
int fd = open("/sys/class/gpio/gpio60/value", "r");//open the value directory in read mode
while(1)
{
char buffer[1];
int r = read (fd, buffer,sizeof(buffer));//read the value from the fd and store it in r
//printf("value:%d\n",r);
if(r != '\0' ){ //read the value of r
buffer[r] = '\0';
int vin = jeet(buffer); //stored buffer value will be converted and stored in the int value vin
printf("val:%d\n", vin);//print that value on the screen
if(vin==1){
printf("\"1\"high\n");
system("echo 0 > /sys/class/gpio/gpio30/value"); //if the read value is high then redirect 0 to value file
}
else
{
printf("\"0\"low\n");
system("echo 1 > /sys/class/gpio/gpio30/value");//if it s low then give 1 to value file
}
lseek(fd,0,0);// move the filedescriptor to the starting position of the file
}
sleep(1);//sleep for a time period
}
close(fd);//close the filedescriptor
}
beagle_gpio.c file to interface the lcd to beaglebone black
#include "beagle_gpio.h"
/**
* @brief Writes a value to a particular GPIO, logic-HIGH or logic-LOW.
* @param GPIONUMBER The GPIO number (e.g. 38 for gpio1[6])
* @param value The logic value we want to write to the GPIO (0 or 1)
**/
void write_GPIO_value(int GPIONUMBER, int value)
{
char export_filename[50];
FILE *f = NULL;
sprintf(export_filename, "/sys/class/gpio/gpio%d/value",GPIONUMBER);
f = fopen(export_filename,"w");
assert(f!=NULL);
fprintf(f , "%d",value);
pclose(f);
}
/**
* @brief Tells the OS that we are done with using GPIOs
* @param selected_GPIOs[] initialized array of gpioID.
* @param selectedPins[] Array with the user specified pins
* @param nbr_selectedPins Number of pins that were specified by the user
**/
void cleanup_GPIO(struct gpioID selected_GPIOs[],int selectedPins[], int nbr_selectedPins)
{
FILE *f = NULL;
int i;
for (i=0; i<nbr_selectedPins;i++)
{
//unexport the pin
f = fopen("/sys/class/gpio/unexport","w");
assert(f!=NULL);
fprintf(f, "%d",selected_GPIOs[i].GPIONUMBER);
pclose(f);
}
}
/**
* @brief Initializes all the user specified pins
* @param selected_GPIOs[] Un-initialized array of gpioID. At the end of this
* function, the selected_GPIOs[] array will be initialized.
* @param selectedPins[] Array with the user specified pins
* @param nbr_selectedPins Number of pins that were specified by the user
**/
void initialize_each_enabled_gpio(struct gpioID selected_GPIOs[],int selectedPins[], int nbr_selectedPins)
{
int i;
//this variable will contain the location of the file that we need to
//set to mode 7
char export_filename[50];
FILE *f = NULL;
//You are not allowed to use more than 32 active pins. This is not a
//beagleboard limitation, but a limitation of this code.
assert (nbr_selectedPins<=32);
//cycles every userdefined pin, and inializes its contents in the
//selected_GPIOs[] array.
for (i=0; i<nbr_selectedPins;i++)
{
switch (selectedPins[i])
{
case P9_12:
strcpy(selected_GPIOs[i].PINNAME, "P9_12");
strcpy(selected_GPIOs[i].GPIOID, "gpio1[28]");
strcpy(selected_GPIOs[i].GPIOMUX, "gpmc_be1n");
selected_GPIOs[i].GPIONUMBER=60;
break;
case P9_13:
strcpy(selected_GPIOs[i].PINNAME, "P9_13");
strcpy(selected_GPIOs[i].GPIOID, "gpio0[31]");
strcpy(selected_GPIOs[i].GPIOMUX, "gpmc_wpn");
selected_GPIOs[i].GPIONUMBER=31;
break;
case P9_15:
strcpy(selected_GPIOs[i].PINNAME, "P9_15");
strcpy(selected_GPIOs[i].GPIOID, "gpio1[16]");
strcpy(selected_GPIOs[i].GPIOMUX, "gpmc_a0");
selected_GPIOs[i].GPIONUMBER=48;
break;
case P8_11:
strcpy(selected_GPIOs[i].PINNAME, "P8_11");
strcpy(selected_GPIOs[i].GPIOID, "gpio1[13]");
strcpy(selected_GPIOs[i].GPIOMUX, "gpmc_ad13");
selected_GPIOs[i].GPIONUMBER=45;
break;
case P8_12:
strcpy(selected_GPIOs[i].PINNAME, "P8_12");
strcpy(selected_GPIOs[i].GPIOID, "gpio1[12]");
strcpy(selected_GPIOs[i].GPIOMUX, "gpmc_ad12");
selected_GPIOs[i].GPIONUMBER=44;
break;
case P8_14:
strcpy(selected_GPIOs[i].PINNAME, "P8_14");
strcpy(selected_GPIOs[i].GPIOID, "gpio0[26]");
strcpy(selected_GPIOs[i].GPIOMUX, "gpmc_ad10");
selected_GPIOs[i].GPIONUMBER=26;
break;
case P8_15:
strcpy(selected_GPIOs[i].PINNAME, "P8_15");
strcpy(selected_GPIOs[i].GPIOID, "gpio1[15]");
strcpy(selected_GPIOs[i].GPIOMUX, "gpmc_ad15");
selected_GPIOs[i].GPIONUMBER=47;
break;
case P8_16:
strcpy(selected_GPIOs[i].PINNAME, "P8_16");
strcpy(selected_GPIOs[i].GPIOID, "gpio1[14]");
strcpy(selected_GPIOs[i].GPIOMUX, "gpmc_ad14");
selected_GPIOs[i].GPIONUMBER=46;
break;
case P8_17:
strcpy(selected_GPIOs[i].PINNAME, "P8_17");
strcpy(selected_GPIOs[i].GPIOID, "gpio0[27]");
strcpy(selected_GPIOs[i].GPIOMUX, "gpmc_ad11");
selected_GPIOs[i].GPIONUMBER=27;
break;
case P8_20:
strcpy(selected_GPIOs[i].PINNAME, "P8_20");
strcpy(selected_GPIOs[i].GPIOID, "gpio1[31]");
strcpy(selected_GPIOs[i].GPIOMUX, "gpmc_csn2");
selected_GPIOs[i].GPIONUMBER=63;
break;
case P8_21:
strcpy(selected_GPIOs[i].PINNAME, "P8_21");
strcpy(selected_GPIOs[i].GPIOID, "gpio1[30]");
strcpy(selected_GPIOs[i].GPIOMUX, "gpmc_csn1");
selected_GPIOs[i].GPIONUMBER=62;
break;
default:
//This statement should never be reached... since
//the program won't even compile if the user
//specified a bad pin specification.
break;
}
}
//set the each mux pin to mode 7
for (i=0; i<nbr_selectedPins;i++)
{
/*
//set mux to mode 7
sprintf(export_filename, "/sys/kernel/debug/pinctrl/44e10800.pinmux/pins/%s", selected_GPIOs[i].GPIOMUX);
f = fopen(export_filename,"w");
if (f == NULL)
{
printf( "\nERROR: There was a problem opening /sys/kernel/debug/omap_mux/%s\n", selected_GPIOs[i].GPIOMUX);
printf("\n%s\t%s\t%s\t%d\n\n", selected_GPIOs[i].PINNAME, selected_GPIOs[i].GPIOID, selected_GPIOs[i].GPIOMUX, selected_GPIOs[i].GPIONUMBER);
assert(f!=NULL);
}
fprintf(f, "7");
pclose(f);
//export the pin
f = fopen("/sys/class/gpio/export","w");
if (f == NULL)
{
printf( "\nERROR: There was a problem opening /sys/kernel/debug/omap_mux/%s\n", selected_GPIOs[i].GPIOMUX);
printf("\n%s\t%s\t%s\t%d\n\n", selected_GPIOs[i].PINNAME,selected_GPIOs[i].GPIOID,selected_GPIOs[i].GPIOMUX,selected_GPIOs[i].GPIONUMBER);
assert(f!=NULL);
}
fprintf(f, "%d",selected_GPIOs[i].GPIONUMBER);
pclose(f);
*/
//set the appropriate io direction (out)
sprintf(export_filename, "/sys/class/gpio/gpio%d/direction", selected_GPIOs[i].GPIONUMBER);
f = fopen(export_filename,"w");
if (f == NULL)
{
printf( "\nERROR: There was a problem opening /sys/class/gpio/gpio%d/direction\n", selected_GPIOs[i].GPIONUMBER);
printf("\n%s\t%s\t%s\t%d\n\n",selected_GPIOs[i].PINNAME,selected_GPIOs[i].GPIOID,selected_GPIOs[i].GPIOMUX,selected_GPIOs[i].GPIONUMBER);
assert(f!=NULL);
}
fprintf(f , "out" );
pclose(f);
write_GPIO_value(selected_GPIOs[i].GPIONUMBER,0);
}
}
/**
* @brief Displays all information for each of the user specified pins.
* This function has no purpose besides live debugging.
* @param selected_GPIOs[] An valid (initialized) array of gpioID
* @param nbr_selectedPins Number of pins that were specified by the user
* @param pinDescription[] A constant array containing the description of each pin
**/
void display_each_enabled_gpio(struct gpioID selected_GPIOs[],int nbr_selectedPins,const char *pinDescription[])
{
int i;
printf("\n");
printf("PINNAME\tGPIOID\t\tGPIOMUX\t\tGPIONBR\tDESCRIPTION\n");
printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
for (i=0; i< nbr_selectedPins; i++)
{
printf("%s\t%s\t%s\t%d\t%s\n",selected_GPIOs[i].PINNAME,selected_GPIOs[i].GPIOID,selected_GPIOs[i].GPIOMUX,selected_GPIOs[i].GPIONUMBER,pinDescription[i]);
}
printf("\n");
}
/**
* @brief Cycles through the entire array of selected_GPIOs[] and turns ON/OFF
* each associated GPIO.
* @param selected_GPIOs[] An valid (initialized) array of gpioID
* @param data_to_write An unsigned integer (32 bits), where each bit contains the
* information regarding the status of each pin: 1=turn pin ON, 0=turn pin OFF
* @param nbr_selectedPins Number of pins that were specified by the user
* @param print_to_screen This specifies if some extra information is to be displayed in the
* user screen. It has no other purpose than debugging your code. If print_to_screen == 1, data will
* be displayed on the terminal window; otherwise it will not.
* @param pinDescription[] A constant array containing the description of each pin
**/
void turn_ON_OFF_pins(struct gpioID selected_GPIOs[],unsigned int data_to_write,int nbr_selectedPins, int print_to_screen, const char *pinDescription[])
{
int i;
for (i=0;i<nbr_selectedPins;i++)
{
//code that turns ON/OFF a pin
write_GPIO_value(selected_GPIOs[i].GPIONUMBER,bitRead(data_to_write,i));
//this is just for debugging purposes
if (print_to_screen)
{
if (bitRead(data_to_write,i) == 1) printf("turning ON");
else printf("turning OFF");
printf( "\t%s (%s %d %s) - %s\n",selected_GPIOs[i].PINNAME,selected_GPIOs[i].GPIOID,selected_GPIOs[i].GPIONUMBER,selected_GPIOs[i].GPIOMUX,pinDescription[i]);
}
}
if (print_to_screen) printf("\n");
}
/**
* @brief Writes a bit into a particular location in an unsigned int variable (32 bits)
* @param groupOfBits Some data resides in these 32 bits
* @param bitVal The bitVal is wither a 1 or a 0
* @param bitLoc Where in the groupOfBits, the value of bitVal will be written.
* Keep in mind that the bitLoc values ranges 0 to 31
* @return Returns the updated groupOfBits
**/
unsigned int bitWrite(unsigned int groupOfBits, int bitVal, int bitLoc)
{
if (bitVal==1) groupOfBits |= 1 << bitLoc;
else groupOfBits &= ~(1 << bitLoc);
return(groupOfBits);
}
/**
* @brief Returns the bit value of a particular location in an unsigned int variable (32 bits)
* @param groupOfBits Some data resides in these 32 bits
* @param bitLoc Where in the groupOfBits, the value of bitVal will be written
* @return Retuns an integer with the bit value (1 or 0) that resides in bitLoc
**/
int bitRead(unsigned int groupOfBits, int bitLoc)
{
unsigned int bit = groupOfBits & (1 << bitLoc);
if (bit!=0) bit=1;
return(bit);
}
/**
* @brief Pulses a particular bit (goes HIGH then LOW) with a specify delay
* @param selected_GPIOs[] An valid (initialized) array of gpioID
* @param data_to_write An unsigned integer (32 bits), where each bit contains the
* information regarding the status of each pin: 1=turn pin ON, 0=turn pin OFF
* @param nbr_selectedPins Number of pins that were specified by the user
* @param print_to_screen This specifies if some extra information is to be displayed in the
* user screen. It has no other purpose than debugging your code. If print_to_screen == 1, data will
* be displayed on the terminal window; otherwise it will not.
* @param pinDescription[] A constant array containing the description of each pin
* @param pinID ID of pin we want to pulse
* @param delay Delay in seconds that will define the interval between signal states
**/
void pulsePin(struct gpioID enabled_gpio[],unsigned int data_to_write,int nbr_selectedPins, int print_to_screen, const char *pinDescription[], int pinID, int delay)
{
if (print_to_screen) printf("========== START: PULSING PIN %d ==========\n",pinID);
data_to_write=bitWrite(data_to_write,1,pinID);
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,print_to_screen,pinDescription);
sleep(delay);
data_to_write=bitWrite(data_to_write,0,pinID);
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,print_to_screen,pinDescription);
sleep(delay);
if (print_to_screen) printf("========== END: PULSING PIN %d ==========\n",pinID);
}
/**
* @brief Writes a value to a particular GPIO, logic-HIGH or logic-LOW.
* @param GPIONUMBER The GPIO number (e.g. 38 for gpio1[6])
* @param value The logic value we want to write to the GPIO (0 or 1)
**/
void write_GPIO_value(int GPIONUMBER, int value)
{
char export_filename[50];
FILE *f = NULL;
sprintf(export_filename, "/sys/class/gpio/gpio%d/value",GPIONUMBER);
f = fopen(export_filename,"w");
assert(f!=NULL);
fprintf(f , "%d",value);
pclose(f);
}
/**
* @brief Tells the OS that we are done with using GPIOs
* @param selected_GPIOs[] initialized array of gpioID.
* @param selectedPins[] Array with the user specified pins
* @param nbr_selectedPins Number of pins that were specified by the user
**/
void cleanup_GPIO(struct gpioID selected_GPIOs[],int selectedPins[], int nbr_selectedPins)
{
FILE *f = NULL;
int i;
for (i=0; i<nbr_selectedPins;i++)
{
//unexport the pin
f = fopen("/sys/class/gpio/unexport","w");
assert(f!=NULL);
fprintf(f, "%d",selected_GPIOs[i].GPIONUMBER);
pclose(f);
}
}
/**
* @brief Initializes all the user specified pins
* @param selected_GPIOs[] Un-initialized array of gpioID. At the end of this
* function, the selected_GPIOs[] array will be initialized.
* @param selectedPins[] Array with the user specified pins
* @param nbr_selectedPins Number of pins that were specified by the user
**/
void initialize_each_enabled_gpio(struct gpioID selected_GPIOs[],int selectedPins[], int nbr_selectedPins)
{
int i;
//this variable will contain the location of the file that we need to
//set to mode 7
char export_filename[50];
FILE *f = NULL;
//You are not allowed to use more than 32 active pins. This is not a
//beagleboard limitation, but a limitation of this code.
assert (nbr_selectedPins<=32);
//cycles every userdefined pin, and inializes its contents in the
//selected_GPIOs[] array.
for (i=0; i<nbr_selectedPins;i++)
{
switch (selectedPins[i])
{
case P9_12:
strcpy(selected_GPIOs[i].PINNAME, "P9_12");
strcpy(selected_GPIOs[i].GPIOID, "gpio1[28]");
strcpy(selected_GPIOs[i].GPIOMUX, "gpmc_be1n");
selected_GPIOs[i].GPIONUMBER=60;
break;
case P9_13:
strcpy(selected_GPIOs[i].PINNAME, "P9_13");
strcpy(selected_GPIOs[i].GPIOID, "gpio0[31]");
strcpy(selected_GPIOs[i].GPIOMUX, "gpmc_wpn");
selected_GPIOs[i].GPIONUMBER=31;
break;
case P9_15:
strcpy(selected_GPIOs[i].PINNAME, "P9_15");
strcpy(selected_GPIOs[i].GPIOID, "gpio1[16]");
strcpy(selected_GPIOs[i].GPIOMUX, "gpmc_a0");
selected_GPIOs[i].GPIONUMBER=48;
break;
case P8_11:
strcpy(selected_GPIOs[i].PINNAME, "P8_11");
strcpy(selected_GPIOs[i].GPIOID, "gpio1[13]");
strcpy(selected_GPIOs[i].GPIOMUX, "gpmc_ad13");
selected_GPIOs[i].GPIONUMBER=45;
break;
case P8_12:
strcpy(selected_GPIOs[i].PINNAME, "P8_12");
strcpy(selected_GPIOs[i].GPIOID, "gpio1[12]");
strcpy(selected_GPIOs[i].GPIOMUX, "gpmc_ad12");
selected_GPIOs[i].GPIONUMBER=44;
break;
case P8_14:
strcpy(selected_GPIOs[i].PINNAME, "P8_14");
strcpy(selected_GPIOs[i].GPIOID, "gpio0[26]");
strcpy(selected_GPIOs[i].GPIOMUX, "gpmc_ad10");
selected_GPIOs[i].GPIONUMBER=26;
break;
case P8_15:
strcpy(selected_GPIOs[i].PINNAME, "P8_15");
strcpy(selected_GPIOs[i].GPIOID, "gpio1[15]");
strcpy(selected_GPIOs[i].GPIOMUX, "gpmc_ad15");
selected_GPIOs[i].GPIONUMBER=47;
break;
case P8_16:
strcpy(selected_GPIOs[i].PINNAME, "P8_16");
strcpy(selected_GPIOs[i].GPIOID, "gpio1[14]");
strcpy(selected_GPIOs[i].GPIOMUX, "gpmc_ad14");
selected_GPIOs[i].GPIONUMBER=46;
break;
case P8_17:
strcpy(selected_GPIOs[i].PINNAME, "P8_17");
strcpy(selected_GPIOs[i].GPIOID, "gpio0[27]");
strcpy(selected_GPIOs[i].GPIOMUX, "gpmc_ad11");
selected_GPIOs[i].GPIONUMBER=27;
break;
case P8_20:
strcpy(selected_GPIOs[i].PINNAME, "P8_20");
strcpy(selected_GPIOs[i].GPIOID, "gpio1[31]");
strcpy(selected_GPIOs[i].GPIOMUX, "gpmc_csn2");
selected_GPIOs[i].GPIONUMBER=63;
break;
case P8_21:
strcpy(selected_GPIOs[i].PINNAME, "P8_21");
strcpy(selected_GPIOs[i].GPIOID, "gpio1[30]");
strcpy(selected_GPIOs[i].GPIOMUX, "gpmc_csn1");
selected_GPIOs[i].GPIONUMBER=62;
break;
default:
//This statement should never be reached... since
//the program won't even compile if the user
//specified a bad pin specification.
break;
}
}
//set the each mux pin to mode 7
for (i=0; i<nbr_selectedPins;i++)
{
/*
//set mux to mode 7
sprintf(export_filename, "/sys/kernel/debug/pinctrl/44e10800.pinmux/pins/%s", selected_GPIOs[i].GPIOMUX);
f = fopen(export_filename,"w");
if (f == NULL)
{
printf( "\nERROR: There was a problem opening /sys/kernel/debug/omap_mux/%s\n", selected_GPIOs[i].GPIOMUX);
printf("\n%s\t%s\t%s\t%d\n\n", selected_GPIOs[i].PINNAME, selected_GPIOs[i].GPIOID, selected_GPIOs[i].GPIOMUX, selected_GPIOs[i].GPIONUMBER);
assert(f!=NULL);
}
fprintf(f, "7");
pclose(f);
//export the pin
f = fopen("/sys/class/gpio/export","w");
if (f == NULL)
{
printf( "\nERROR: There was a problem opening /sys/kernel/debug/omap_mux/%s\n", selected_GPIOs[i].GPIOMUX);
printf("\n%s\t%s\t%s\t%d\n\n", selected_GPIOs[i].PINNAME,selected_GPIOs[i].GPIOID,selected_GPIOs[i].GPIOMUX,selected_GPIOs[i].GPIONUMBER);
assert(f!=NULL);
}
fprintf(f, "%d",selected_GPIOs[i].GPIONUMBER);
pclose(f);
*/
//set the appropriate io direction (out)
sprintf(export_filename, "/sys/class/gpio/gpio%d/direction", selected_GPIOs[i].GPIONUMBER);
f = fopen(export_filename,"w");
if (f == NULL)
{
printf( "\nERROR: There was a problem opening /sys/class/gpio/gpio%d/direction\n", selected_GPIOs[i].GPIONUMBER);
printf("\n%s\t%s\t%s\t%d\n\n",selected_GPIOs[i].PINNAME,selected_GPIOs[i].GPIOID,selected_GPIOs[i].GPIOMUX,selected_GPIOs[i].GPIONUMBER);
assert(f!=NULL);
}
fprintf(f , "out" );
pclose(f);
write_GPIO_value(selected_GPIOs[i].GPIONUMBER,0);
}
}
/**
* @brief Displays all information for each of the user specified pins.
* This function has no purpose besides live debugging.
* @param selected_GPIOs[] An valid (initialized) array of gpioID
* @param nbr_selectedPins Number of pins that were specified by the user
* @param pinDescription[] A constant array containing the description of each pin
**/
void display_each_enabled_gpio(struct gpioID selected_GPIOs[],int nbr_selectedPins,const char *pinDescription[])
{
int i;
printf("\n");
printf("PINNAME\tGPIOID\t\tGPIOMUX\t\tGPIONBR\tDESCRIPTION\n");
printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
for (i=0; i< nbr_selectedPins; i++)
{
printf("%s\t%s\t%s\t%d\t%s\n",selected_GPIOs[i].PINNAME,selected_GPIOs[i].GPIOID,selected_GPIOs[i].GPIOMUX,selected_GPIOs[i].GPIONUMBER,pinDescription[i]);
}
printf("\n");
}
/**
* @brief Cycles through the entire array of selected_GPIOs[] and turns ON/OFF
* each associated GPIO.
* @param selected_GPIOs[] An valid (initialized) array of gpioID
* @param data_to_write An unsigned integer (32 bits), where each bit contains the
* information regarding the status of each pin: 1=turn pin ON, 0=turn pin OFF
* @param nbr_selectedPins Number of pins that were specified by the user
* @param print_to_screen This specifies if some extra information is to be displayed in the
* user screen. It has no other purpose than debugging your code. If print_to_screen == 1, data will
* be displayed on the terminal window; otherwise it will not.
* @param pinDescription[] A constant array containing the description of each pin
**/
void turn_ON_OFF_pins(struct gpioID selected_GPIOs[],unsigned int data_to_write,int nbr_selectedPins, int print_to_screen, const char *pinDescription[])
{
int i;
for (i=0;i<nbr_selectedPins;i++)
{
//code that turns ON/OFF a pin
write_GPIO_value(selected_GPIOs[i].GPIONUMBER,bitRead(data_to_write,i));
//this is just for debugging purposes
if (print_to_screen)
{
if (bitRead(data_to_write,i) == 1) printf("turning ON");
else printf("turning OFF");
printf( "\t%s (%s %d %s) - %s\n",selected_GPIOs[i].PINNAME,selected_GPIOs[i].GPIOID,selected_GPIOs[i].GPIONUMBER,selected_GPIOs[i].GPIOMUX,pinDescription[i]);
}
}
if (print_to_screen) printf("\n");
}
/**
* @brief Writes a bit into a particular location in an unsigned int variable (32 bits)
* @param groupOfBits Some data resides in these 32 bits
* @param bitVal The bitVal is wither a 1 or a 0
* @param bitLoc Where in the groupOfBits, the value of bitVal will be written.
* Keep in mind that the bitLoc values ranges 0 to 31
* @return Returns the updated groupOfBits
**/
unsigned int bitWrite(unsigned int groupOfBits, int bitVal, int bitLoc)
{
if (bitVal==1) groupOfBits |= 1 << bitLoc;
else groupOfBits &= ~(1 << bitLoc);
return(groupOfBits);
}
/**
* @brief Returns the bit value of a particular location in an unsigned int variable (32 bits)
* @param groupOfBits Some data resides in these 32 bits
* @param bitLoc Where in the groupOfBits, the value of bitVal will be written
* @return Retuns an integer with the bit value (1 or 0) that resides in bitLoc
**/
int bitRead(unsigned int groupOfBits, int bitLoc)
{
unsigned int bit = groupOfBits & (1 << bitLoc);
if (bit!=0) bit=1;
return(bit);
}
/**
* @brief Pulses a particular bit (goes HIGH then LOW) with a specify delay
* @param selected_GPIOs[] An valid (initialized) array of gpioID
* @param data_to_write An unsigned integer (32 bits), where each bit contains the
* information regarding the status of each pin: 1=turn pin ON, 0=turn pin OFF
* @param nbr_selectedPins Number of pins that were specified by the user
* @param print_to_screen This specifies if some extra information is to be displayed in the
* user screen. It has no other purpose than debugging your code. If print_to_screen == 1, data will
* be displayed on the terminal window; otherwise it will not.
* @param pinDescription[] A constant array containing the description of each pin
* @param pinID ID of pin we want to pulse
* @param delay Delay in seconds that will define the interval between signal states
**/
void pulsePin(struct gpioID enabled_gpio[],unsigned int data_to_write,int nbr_selectedPins, int print_to_screen, const char *pinDescription[], int pinID, int delay)
{
if (print_to_screen) printf("========== START: PULSING PIN %d ==========\n",pinID);
data_to_write=bitWrite(data_to_write,1,pinID);
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,print_to_screen,pinDescription);
sleep(delay);
data_to_write=bitWrite(data_to_write,0,pinID);
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,print_to_screen,pinDescription);
sleep(delay);
if (print_to_screen) printf("========== END: PULSING PIN %d ==========\n",pinID);
}
Tuesday, 12 November 2013
lcd example with beaglebone black
In many projects which we do we need to interface lcd to c the results,here we will c how to interface lcd to beagle bone
code which require are given below.
beagle_gpio.c
beagle_gpio.h
beagle_hd44780.c
beagle_hd44780.h
build.sh
lcd.dts
main.c
code which require are given below.
beagle_gpio.c
beagle_gpio.h
beagle_hd44780.c
beagle_hd44780.h
build.sh
lcd.dts
main.c
beagle_gpio.h header file to include to interface lcd into beaglebone black
#ifndef BEAGLE_GPIO_H_GUARD
#define BEAGLE_GPIO_H_GUARD
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <time.h>
//The following #defines make it easier for the user to add differnt pins
#define P9_12 0
#define P9_13 1
#define P9_15 2
#define P8_11 3
#define P8_12 4
#define P8_14 5
#define P8_15 6
#define P8_16 7
#define P8_17 8
#define P8_20 9
#define P8_21 10
/** @brief Contains all elements which we need to pass into the beagleboard
* to specify which GPIO pin we want to turn ON/OFF **/
struct gpioID
{
char PINNAME[10]; //eg. P8_3
char GPIOID[10]; //e.g: gpio1[6]
int GPIONUMBER; //e.g: 38
char GPIOMUX[10]; //e.g: gpmc_ad6;
};
void pulsePin(struct gpioID enabled_gpio[],unsigned int data_to_write,int nbr_selectedPins, int print_to_screen, const char *pinDescription[], int pinID, int delay);
void write_GPIO_value(int GPIONUMBER, int value);
void cleanup_GPIO(struct gpioID selected_GPIOs[],int selectedPins[], int nbr_selectedPins);
void initialize_each_enabled_gpio(struct gpioID selected_GPIOs[],int selectedPins[], int nbr_selectedPins);
void display_each_enabled_gpio(struct gpioID selected_GPIOs[],int nbr_selectedPins,const char *pinDescription[]);
void turn_ON_OFF_pins(struct gpioID selected_GPIOs[],unsigned int data_to_write,int nbr_selectedPins, int print_to_screen, const char *pinDescription[]);
//void turn_ON_OFF_pins(struct gpioID selected_GPIOs[],unsigned int data_to_write,int nbr_selectedPins, int print_to_screen);
unsigned int bitWrite(unsigned int groupOfBits, int bitVal, int bitLoc);
int bitRead(unsigned int groupOfBits, int bitLoc);
#endif
#define BEAGLE_GPIO_H_GUARD
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <time.h>
//The following #defines make it easier for the user to add differnt pins
#define P9_12 0
#define P9_13 1
#define P9_15 2
#define P8_11 3
#define P8_12 4
#define P8_14 5
#define P8_15 6
#define P8_16 7
#define P8_17 8
#define P8_20 9
#define P8_21 10
/** @brief Contains all elements which we need to pass into the beagleboard
* to specify which GPIO pin we want to turn ON/OFF **/
struct gpioID
{
char PINNAME[10]; //eg. P8_3
char GPIOID[10]; //e.g: gpio1[6]
int GPIONUMBER; //e.g: 38
char GPIOMUX[10]; //e.g: gpmc_ad6;
};
void pulsePin(struct gpioID enabled_gpio[],unsigned int data_to_write,int nbr_selectedPins, int print_to_screen, const char *pinDescription[], int pinID, int delay);
void write_GPIO_value(int GPIONUMBER, int value);
void cleanup_GPIO(struct gpioID selected_GPIOs[],int selectedPins[], int nbr_selectedPins);
void initialize_each_enabled_gpio(struct gpioID selected_GPIOs[],int selectedPins[], int nbr_selectedPins);
void display_each_enabled_gpio(struct gpioID selected_GPIOs[],int nbr_selectedPins,const char *pinDescription[]);
void turn_ON_OFF_pins(struct gpioID selected_GPIOs[],unsigned int data_to_write,int nbr_selectedPins, int print_to_screen, const char *pinDescription[]);
//void turn_ON_OFF_pins(struct gpioID selected_GPIOs[],unsigned int data_to_write,int nbr_selectedPins, int print_to_screen);
unsigned int bitWrite(unsigned int groupOfBits, int bitVal, int bitLoc);
int bitRead(unsigned int groupOfBits, int bitLoc);
#endif
beagle_hd44780.c file to include to interface lcd into beaglebone black
#include "beagle_hd44780.h"
/**
* @brief Converts a character in two bitstreams the LCD can understand.
* @param character The character we want to write.
* @param part This can be either 0 or 1. Part 0 correspond to DB7..DB4,
* while part 1 corresponds to DB3..DB0 on 8 bit mode. Since we are doing
* 4 bit mode, we need to split the bitstream in two parts.
**/
unsigned int write_character (char character, int part)
{
assert(part==0 || part==1);
char acB[2];
sprintf(acB, "%x", character);
unsigned int return_value = 0;
switch (acB[part])
{
case '0': return_value = 16; break;
case '1': return_value = 24; break;
case '2': return_value = 20; break;
case '3': return_value = 28; break;
case '4': return_value = 18; break;
case '5': return_value = 26; break;
case '6': return_value = 22; break;
case '7': return_value = 30; break;
case '8': return_value = 17; break;
case '9': return_value = 25; break;
case 'a': return_value = 21; break;
case 'b': return_value = 29; break;
case 'c': return_value = 19; break;
case 'd': return_value = 27; break;
case 'e': return_value = 23; break;
case 'f': return_value = 31; break;
}
return(return_value);
}
/**
* @brief Puts a single character onto the screen.
* @param characterToWrite The character we want to write.
* @param selected_GPIOs[] initialized array of gpioID.
**/
void charToScreen(char characterToWrite, struct gpioID enabled_gpio[])
{
unsigned int data_to_write=0;
const char *pinDescription[] = {"","","","","",""};
data_to_write=write_character (characterToWrite,0);
turn_ON_OFF_pins(enabled_gpio,data_to_write,6,0.10,pinDescription);
pulsePin(enabled_gpio,data_to_write,6,0, pinDescription, 5, 0.10);
sleep(0.10);
data_to_write=write_character (characterToWrite,1);
turn_ON_OFF_pins(enabled_gpio,data_to_write,6,0.10,pinDescription);
pulsePin(enabled_gpio,data_to_write,6,0, pinDescription, 5, 0.10);
sleep(0.10);
}
/**
* @brief Initializes the screen so we can use it.
* @param selected_GPIOs[] An initialized array of gpioID.
* @param selectedPins[] The user defined pins.
**/
void initialize_Screen(struct gpioID enabled_gpio[],int selectedPins[])
{
int nbr_selectedPins=6;
const char *pinDescription[] = {"","","","","",""};
unsigned int data_to_write;
initialize_each_enabled_gpio(enabled_gpio,selectedPins,nbr_selectedPins);
if (DISPLAY_DATA_ON_SCREEN) display_each_enabled_gpio(enabled_gpio,nbr_selectedPins,pinDescription);
//E RS DB4 DB5 DB6 DB7
//0 0 1 1 0 0 (base 2) which equals 12 (base 10)
data_to_write=12;
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
//E RS DB4 DB5 DB6 DB7
//0 0 0 1 0 0 (base 2) which equals 4 (base 10) : 4 bit mode
data_to_write=4;
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
//enable display part 1 - Display ON/OFF & Cursor
//E RS DB4 DB5 DB6 DB7 = 000000 (2) == 0 (10)
data_to_write=0;
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
//enable display part 2 - Display ON/OFF & Cursor
//E RS DB4 DB5 DB6 DB7 = 000011 (2) == 3 (10)
data_to_write=3;
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
//two line mode 5x7 part 1
//E RS DB4 DB5 DB6 DB7 = 000100 (2) == 4 (10)
data_to_write=4;
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
//two line mode 5x7 part 2 (the 0 next to the 1 specifies the 5x7)
//E RS DB4 DB5 DB6 DB7 = 000001 (2) == 1 (10)
data_to_write=1;
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
}
/**
* @brief Enables the blinking cursor with an underline.
* @param selected_GPIOs[] initialized array of gpioID.
**/
void enableBlinkingCursor(struct gpioID enabled_gpio[])
{
int nbr_selectedPins=6;
const char *pinDescription[] = {"","","","","",""};
unsigned int data_to_write;
//enable cursor part 1
//E RS DB4 DB5 DB6 DB7 = 000000 (2) == 0 (10)
data_to_write=0;
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
//enable cursor part 2
//E RS DB4 DB5 DB6 DB7 = 001111 (2) == 15 (10)
data_to_write=15;
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
}
/**
* @brief Disables the blinking cursor with an underline.
* @param selected_GPIOs[] initialized array of gpioID.
**/
void disableBlinkingCursor(struct gpioID enabled_gpio[])
{
int nbr_selectedPins=6;
const char *pinDescription[] = {"","","","","",""};
unsigned int data_to_write;
//enable cursor part 1
//E RS DB4 DB5 DB6 DB7 = 000000 (2) == 0 (10)
data_to_write=0;
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
//enable display part 2 - Display ON/OFF & Cursor
//E RS DB4 DB5 DB6 DB7 = 000011 (2) == 3 (10)
data_to_write=3;
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
}
/**
* @brief Clears the LCD from anything thats in there.
* @param selected_GPIOs[] initialized array of gpioID.
**/
void clear_Screen(struct gpioID enabled_gpio[])
{
int nbr_selectedPins=6;
const char *pinDescription[] = {"","","","","",""};
unsigned int data_to_write;
//E RS DB4 DB5 DB6 DB7 = 000000 (2) == 0 (10)
data_to_write=0;
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
//E RS DB4 DB5 DB6 DB7 = 001000 (2) == 8 (10)
data_to_write=8;
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
}
/**
* @brief After you are done using the LCD you should terminate it properly.
* Failure to do so will guarantee that next time you use LCD it will be on 8 bit
* mode... and you will must turn ON/OFF the screen.
* @param selected_GPIOs[] initialized array of gpioID.
**/
void terminate_Screen(struct gpioID enabled_gpio[],int selectedPins[])
{
int nbr_selectedPins=6;
const char *pinDescription[] = {"","","","","",""};
unsigned int data_to_write;
//put the display back in 8 bit mode to allow to re-run program
//E RS DB4 DB5 DB6 DB7 = 001100 (2) == 12 (10)
data_to_write=12;
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
//we should now tell the OS that we are done with the GPIOs
cleanup_GPIO(enabled_gpio,selectedPins,nbr_selectedPins);
}
/**
* @brief Prints a string to the screen.
* @param full_string String that needs to be printed on the LCD
* @param selected_GPIOs[] Initialized array of gpioID.
**/
void stringToScreen(const char *full_string, struct gpioID enabled_gpio[])
{
int i;
int length = strlen(full_string);
for (i=0; i<length; i++)
{
charToScreen(full_string[i],enabled_gpio);
//printf("%c\n",full_string[i]);
}
}
/**
* @brief Sets the cursor to either the first or second line.
* @param line If line==0, cursor will be placed on top line. If line==1, the
* the cursor will be placed on the bottom line.
* @param selected_GPIOs[] initialized array of gpioID.
**/
void goto_ScreenLine(int line, struct gpioID enabled_gpio[])
{
assert(line==0 || line==1);
goto_ScreenLocation(line,0,enabled_gpio);
}
/**
* @brief This function is still not working correctly. Technically the
* function should set the cursor to a well defined position in the LCD, but
* it is not doing so for the second line. I think my LCD is broken. Until, I
* fix this function (or at least test it with different LCDs) do not use it.
* @param line Line number; where 0 is the top line and 1 is the bottom line.
* @param position Position; where the initial position is 0.
* @param selected_GPIOs[] Initialized array of gpioID.
**/
void goto_ScreenLocation(int line, int position,struct gpioID enabled_gpio[])
{
int nbr_selectedPins=6;
const char *pinDescription[] = {"","","","","",""};
unsigned int data_to_write;
//printf("position: %d\n",position);
//printf("line: %d\n\n",line);
if (line==1) position=position+40;
data_to_write=return_address_in_bitform(position,0);
//printf("data_to_write: %d\n",data_to_write);
data_to_write=bitWrite(data_to_write,1,0);
//printf("<%d>\n",data_to_write);
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
data_to_write=return_address_in_bitform(position,1);
//printf("data_to_write: %d\n",data_to_write);
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
}
/**
* @brief Returns the address in a split format such that we can send it to
the screen position functions.
* @param address This is the position we want to set the cursor to.
* @param part This can be either 0 or 1. Part 0 correspond to DB7..DB4,
* @param selected_GPIOs[] Initialized array of gpioID.
**/
unsigned int return_address_in_bitform (unsigned int address, int part)
{
assert(part==0 || part==1);
unsigned int return_value=0;
if (part==1)
{
return_value=bitWrite(return_value,bitRead(address,3),0);
return_value=bitWrite(return_value,bitRead(address,2),1);
return_value=bitWrite(return_value,bitRead(address,1),2);
return_value=bitWrite(return_value,bitRead(address,0),3);
}
if (part==0)
{
return_value=bitWrite(return_value,bitRead(address,4),3);
return_value=bitWrite(return_value,bitRead(address,5),2);
return_value=bitWrite(return_value,bitRead(address,6),1);
return_value=bitWrite(return_value,bitRead(address,7),0);
}
return(return_value);
}
/**
* @brief Converts a character in two bitstreams the LCD can understand.
* @param character The character we want to write.
* @param part This can be either 0 or 1. Part 0 correspond to DB7..DB4,
* while part 1 corresponds to DB3..DB0 on 8 bit mode. Since we are doing
* 4 bit mode, we need to split the bitstream in two parts.
**/
unsigned int write_character (char character, int part)
{
assert(part==0 || part==1);
char acB[2];
sprintf(acB, "%x", character);
unsigned int return_value = 0;
switch (acB[part])
{
case '0': return_value = 16; break;
case '1': return_value = 24; break;
case '2': return_value = 20; break;
case '3': return_value = 28; break;
case '4': return_value = 18; break;
case '5': return_value = 26; break;
case '6': return_value = 22; break;
case '7': return_value = 30; break;
case '8': return_value = 17; break;
case '9': return_value = 25; break;
case 'a': return_value = 21; break;
case 'b': return_value = 29; break;
case 'c': return_value = 19; break;
case 'd': return_value = 27; break;
case 'e': return_value = 23; break;
case 'f': return_value = 31; break;
}
return(return_value);
}
/**
* @brief Puts a single character onto the screen.
* @param characterToWrite The character we want to write.
* @param selected_GPIOs[] initialized array of gpioID.
**/
void charToScreen(char characterToWrite, struct gpioID enabled_gpio[])
{
unsigned int data_to_write=0;
const char *pinDescription[] = {"","","","","",""};
data_to_write=write_character (characterToWrite,0);
turn_ON_OFF_pins(enabled_gpio,data_to_write,6,0.10,pinDescription);
pulsePin(enabled_gpio,data_to_write,6,0, pinDescription, 5, 0.10);
sleep(0.10);
data_to_write=write_character (characterToWrite,1);
turn_ON_OFF_pins(enabled_gpio,data_to_write,6,0.10,pinDescription);
pulsePin(enabled_gpio,data_to_write,6,0, pinDescription, 5, 0.10);
sleep(0.10);
}
/**
* @brief Initializes the screen so we can use it.
* @param selected_GPIOs[] An initialized array of gpioID.
* @param selectedPins[] The user defined pins.
**/
void initialize_Screen(struct gpioID enabled_gpio[],int selectedPins[])
{
int nbr_selectedPins=6;
const char *pinDescription[] = {"","","","","",""};
unsigned int data_to_write;
initialize_each_enabled_gpio(enabled_gpio,selectedPins,nbr_selectedPins);
if (DISPLAY_DATA_ON_SCREEN) display_each_enabled_gpio(enabled_gpio,nbr_selectedPins,pinDescription);
//E RS DB4 DB5 DB6 DB7
//0 0 1 1 0 0 (base 2) which equals 12 (base 10)
data_to_write=12;
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
//E RS DB4 DB5 DB6 DB7
//0 0 0 1 0 0 (base 2) which equals 4 (base 10) : 4 bit mode
data_to_write=4;
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
//enable display part 1 - Display ON/OFF & Cursor
//E RS DB4 DB5 DB6 DB7 = 000000 (2) == 0 (10)
data_to_write=0;
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
//enable display part 2 - Display ON/OFF & Cursor
//E RS DB4 DB5 DB6 DB7 = 000011 (2) == 3 (10)
data_to_write=3;
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
//two line mode 5x7 part 1
//E RS DB4 DB5 DB6 DB7 = 000100 (2) == 4 (10)
data_to_write=4;
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
//two line mode 5x7 part 2 (the 0 next to the 1 specifies the 5x7)
//E RS DB4 DB5 DB6 DB7 = 000001 (2) == 1 (10)
data_to_write=1;
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
}
/**
* @brief Enables the blinking cursor with an underline.
* @param selected_GPIOs[] initialized array of gpioID.
**/
void enableBlinkingCursor(struct gpioID enabled_gpio[])
{
int nbr_selectedPins=6;
const char *pinDescription[] = {"","","","","",""};
unsigned int data_to_write;
//enable cursor part 1
//E RS DB4 DB5 DB6 DB7 = 000000 (2) == 0 (10)
data_to_write=0;
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
//enable cursor part 2
//E RS DB4 DB5 DB6 DB7 = 001111 (2) == 15 (10)
data_to_write=15;
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
}
/**
* @brief Disables the blinking cursor with an underline.
* @param selected_GPIOs[] initialized array of gpioID.
**/
void disableBlinkingCursor(struct gpioID enabled_gpio[])
{
int nbr_selectedPins=6;
const char *pinDescription[] = {"","","","","",""};
unsigned int data_to_write;
//enable cursor part 1
//E RS DB4 DB5 DB6 DB7 = 000000 (2) == 0 (10)
data_to_write=0;
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
//enable display part 2 - Display ON/OFF & Cursor
//E RS DB4 DB5 DB6 DB7 = 000011 (2) == 3 (10)
data_to_write=3;
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
}
/**
* @brief Clears the LCD from anything thats in there.
* @param selected_GPIOs[] initialized array of gpioID.
**/
void clear_Screen(struct gpioID enabled_gpio[])
{
int nbr_selectedPins=6;
const char *pinDescription[] = {"","","","","",""};
unsigned int data_to_write;
//E RS DB4 DB5 DB6 DB7 = 000000 (2) == 0 (10)
data_to_write=0;
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
//E RS DB4 DB5 DB6 DB7 = 001000 (2) == 8 (10)
data_to_write=8;
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
}
/**
* @brief After you are done using the LCD you should terminate it properly.
* Failure to do so will guarantee that next time you use LCD it will be on 8 bit
* mode... and you will must turn ON/OFF the screen.
* @param selected_GPIOs[] initialized array of gpioID.
**/
void terminate_Screen(struct gpioID enabled_gpio[],int selectedPins[])
{
int nbr_selectedPins=6;
const char *pinDescription[] = {"","","","","",""};
unsigned int data_to_write;
//put the display back in 8 bit mode to allow to re-run program
//E RS DB4 DB5 DB6 DB7 = 001100 (2) == 12 (10)
data_to_write=12;
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
//we should now tell the OS that we are done with the GPIOs
cleanup_GPIO(enabled_gpio,selectedPins,nbr_selectedPins);
}
/**
* @brief Prints a string to the screen.
* @param full_string String that needs to be printed on the LCD
* @param selected_GPIOs[] Initialized array of gpioID.
**/
void stringToScreen(const char *full_string, struct gpioID enabled_gpio[])
{
int i;
int length = strlen(full_string);
for (i=0; i<length; i++)
{
charToScreen(full_string[i],enabled_gpio);
//printf("%c\n",full_string[i]);
}
}
/**
* @brief Sets the cursor to either the first or second line.
* @param line If line==0, cursor will be placed on top line. If line==1, the
* the cursor will be placed on the bottom line.
* @param selected_GPIOs[] initialized array of gpioID.
**/
void goto_ScreenLine(int line, struct gpioID enabled_gpio[])
{
assert(line==0 || line==1);
goto_ScreenLocation(line,0,enabled_gpio);
}
/**
* @brief This function is still not working correctly. Technically the
* function should set the cursor to a well defined position in the LCD, but
* it is not doing so for the second line. I think my LCD is broken. Until, I
* fix this function (or at least test it with different LCDs) do not use it.
* @param line Line number; where 0 is the top line and 1 is the bottom line.
* @param position Position; where the initial position is 0.
* @param selected_GPIOs[] Initialized array of gpioID.
**/
void goto_ScreenLocation(int line, int position,struct gpioID enabled_gpio[])
{
int nbr_selectedPins=6;
const char *pinDescription[] = {"","","","","",""};
unsigned int data_to_write;
//printf("position: %d\n",position);
//printf("line: %d\n\n",line);
if (line==1) position=position+40;
data_to_write=return_address_in_bitform(position,0);
//printf("data_to_write: %d\n",data_to_write);
data_to_write=bitWrite(data_to_write,1,0);
//printf("<%d>\n",data_to_write);
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
data_to_write=return_address_in_bitform(position,1);
//printf("data_to_write: %d\n",data_to_write);
turn_ON_OFF_pins(enabled_gpio,data_to_write,nbr_selectedPins,MAX_DELAY,pinDescription);
pulsePin(enabled_gpio,data_to_write,nbr_selectedPins,DISPLAY_DATA_ON_SCREEN, pinDescription, 5, MAX_DELAY);
sleep(MAX_DELAY);
}
/**
* @brief Returns the address in a split format such that we can send it to
the screen position functions.
* @param address This is the position we want to set the cursor to.
* @param part This can be either 0 or 1. Part 0 correspond to DB7..DB4,
* @param selected_GPIOs[] Initialized array of gpioID.
**/
unsigned int return_address_in_bitform (unsigned int address, int part)
{
assert(part==0 || part==1);
unsigned int return_value=0;
if (part==1)
{
return_value=bitWrite(return_value,bitRead(address,3),0);
return_value=bitWrite(return_value,bitRead(address,2),1);
return_value=bitWrite(return_value,bitRead(address,1),2);
return_value=bitWrite(return_value,bitRead(address,0),3);
}
if (part==0)
{
return_value=bitWrite(return_value,bitRead(address,4),3);
return_value=bitWrite(return_value,bitRead(address,5),2);
return_value=bitWrite(return_value,bitRead(address,6),1);
return_value=bitWrite(return_value,bitRead(address,7),0);
}
return(return_value);
}
beagle_hd44780.h header file to include to interface lcd to beaglebone black
#ifndef BEAGLE_HD44780_H_GUARD
#define BEAGLE_HD44780_H_GUARD
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#include "beagle_gpio.h"
#define DISPLAY_DATA_ON_SCREEN 0
#define MAX_DELAY 0.10
void goto_ScreenLine(int line, struct gpioID enabled_gpio[]);
void goto_ScreenLocation(int line, int position,struct gpioID enabled_gpio[]);
unsigned int return_address_in_bitform (unsigned int address, int part);
unsigned int write_character (char character, int part);
void charToScreen(char characterToWrite, struct gpioID enabled_gpio[]);
void initialize_Screen(struct gpioID enabled_gpio[],int selectedPins[]);
void terminate_Screen(struct gpioID enabled_gpio[],int selectedPins[]);
void clear_Screen(struct gpioID enabled_gpio[]);
void enableBlinkingCursor(struct gpioID enabled_gpio[]);
void disableBlinkingCursor(struct gpioID enabled_gpio[]);
void stringToScreen(const char *full_string, struct gpioID enabled_gpio[]);
#endif
#define BEAGLE_HD44780_H_GUARD
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#include "beagle_gpio.h"
#define DISPLAY_DATA_ON_SCREEN 0
#define MAX_DELAY 0.10
void goto_ScreenLine(int line, struct gpioID enabled_gpio[]);
void goto_ScreenLocation(int line, int position,struct gpioID enabled_gpio[]);
unsigned int return_address_in_bitform (unsigned int address, int part);
unsigned int write_character (char character, int part);
void charToScreen(char characterToWrite, struct gpioID enabled_gpio[]);
void initialize_Screen(struct gpioID enabled_gpio[],int selectedPins[]);
void terminate_Screen(struct gpioID enabled_gpio[],int selectedPins[]);
void clear_Screen(struct gpioID enabled_gpio[]);
void enableBlinkingCursor(struct gpioID enabled_gpio[]);
void disableBlinkingCursor(struct gpioID enabled_gpio[]);
void stringToScreen(const char *full_string, struct gpioID enabled_gpio[]);
#endif
build file for lcd program with beaglebone black
#!/bin/bash
echo "export slots"
export SLOTS=/sys/devices/bone_cap` `
emgr.9/slots
echo "export pins"
export PINS=/sys/kernel/debug/pinctrl/44e10800.pinmux/pins
echo "Compiling the overlay from .dts to .dtbo"
dtc -O dtb -o DM-GPIO-Test-00A0.dtbo -b 0 -@ DM-GPIO-Test.dts
echo "copy the file"
cp DM-GPIO-Test-00A0.dtbo /lib/firmware/
echo "echo the file to slots"
echo DM-GPIO-Test > $SLOTS
echo 60 > /sys/class/gpio/export
echo 31 > /sys/class/gpio/export
echo 48 > /sys/class/gpio/export
echo 45 > /sys/class/gpio/export
echo 44 > /sys/class/gpio/export
echo 26 > /sys/class/gpio/export
echo "finished"
echo "export slots"
export SLOTS=/sys/devices/bone_cap` `
emgr.9/slots
echo "export pins"
export PINS=/sys/kernel/debug/pinctrl/44e10800.pinmux/pins
echo "Compiling the overlay from .dts to .dtbo"
dtc -O dtb -o DM-GPIO-Test-00A0.dtbo -b 0 -@ DM-GPIO-Test.dts
echo "copy the file"
cp DM-GPIO-Test-00A0.dtbo /lib/firmware/
echo "echo the file to slots"
echo DM-GPIO-Test > $SLOTS
echo 60 > /sys/class/gpio/export
echo 31 > /sys/class/gpio/export
echo 48 > /sys/class/gpio/export
echo 45 > /sys/class/gpio/export
echo 44 > /sys/class/gpio/export
echo 26 > /sys/class/gpio/export
echo "finished"
devise tree source file for lcd program with beaglebone black
/*
* Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Purpose License Version 2 as
* published by the Free Software Foundation
*
* Original from: github.com/jadonk/validation-scripts/blob/master/test-capemgr/
*
* Modified by abhishek for the example on researchdesignlab.com
* that maps GPIO pins for the example
*/
/dts-v1/;
/plugin/;
/{
compatible = "ti,beaglebone", "ti,beaglebone-black";
part-number = "DM-GPIO-Test";
version = "00A0";
fragment@0 {
target = <&am33xx_pinmux>;
__overlay__ {
pinctrl_test: DM_GPIO_Test_Pins {
pinctrl-single,pins = <
0x078 0x07 /* P9_12 60 OUTPUT MODE7 - The LED Output */
0x074 0x07 /* P9_13 31 INPUT MODE7 none - The Button Input */
0x040 0x07 /* P9_15 48 */
0x034 0x07 /* P8_11 45 INPUT MODE7 (37)pullup - Yellow Wire */
0x030 0x07 /* P8_12 44 INPUT MODE7 (27)pulldown - Green Wire */
0x028 0x07 /* P8_14 26 INPUT MODE7 (2f)none - White Wire */
/* OUTPUT GPIO(mode7) 0x07 pulldown, 0x17 pullup, 0x?f no pullup/down */
/* INPUT GPIO(mode7) 0x27 pulldown, 0x37 pullup, 0x?f no pullup/down */
>;
};
};
};
fragment@1 {
target = <&ocp>;
__overlay__ {
test_helper: helper {
compatible = "bone-pinmux-helper";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_test>;
status = "okay";
};
};
};
};
* Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Purpose License Version 2 as
* published by the Free Software Foundation
*
* Original from: github.com/jadonk/validation-scripts/blob/master/test-capemgr/
*
* Modified by abhishek for the example on researchdesignlab.com
* that maps GPIO pins for the example
*/
/dts-v1/;
/plugin/;
/{
compatible = "ti,beaglebone", "ti,beaglebone-black";
part-number = "DM-GPIO-Test";
version = "00A0";
fragment@0 {
target = <&am33xx_pinmux>;
__overlay__ {
pinctrl_test: DM_GPIO_Test_Pins {
pinctrl-single,pins = <
0x078 0x07 /* P9_12 60 OUTPUT MODE7 - The LED Output */
0x074 0x07 /* P9_13 31 INPUT MODE7 none - The Button Input */
0x040 0x07 /* P9_15 48 */
0x034 0x07 /* P8_11 45 INPUT MODE7 (37)pullup - Yellow Wire */
0x030 0x07 /* P8_12 44 INPUT MODE7 (27)pulldown - Green Wire */
0x028 0x07 /* P8_14 26 INPUT MODE7 (2f)none - White Wire */
/* OUTPUT GPIO(mode7) 0x07 pulldown, 0x17 pullup, 0x?f no pullup/down */
/* INPUT GPIO(mode7) 0x27 pulldown, 0x37 pullup, 0x?f no pullup/down */
>;
};
};
};
fragment@1 {
target = <&ocp>;
__overlay__ {
test_helper: helper {
compatible = "bone-pinmux-helper";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_test>;
status = "okay";
};
};
};
};
lcd main fuction for beaglebone black
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#include "beagle_gpio.h"
#include "beagle_hd44780.h"
/**
* @brief This program (example_04.c) describes how to interface with a
* HD44780 display in a BeagleBone
* @details Compile, and run, this code on the beagleBone terminal with the
* commands:
* rm -f a.out ; gcc -c beagle_gpio.c ; gcc -c beagle_hd44780.c ; gcc beagle_gpio.o beagle_hd44780.o example_04.c ; ./a.out
modified by abhishek gowda
* @return Returns a 1 upon succesful program termination
**/
int main()
{
int i=0;
//specifies the pins that will be used
int selectedPins[]={P8_14,P8_12,P8_11,P9_15,P9_13,P9_12};
system("./build.sh");
printf("done\n");
//adding a simple description for each pin
const char *pinDescription[] = {"DB7","DB6","DB5","DB4","RS","E"};
struct gpioID enabled_gpio[6];
initialize_Screen(enabled_gpio,selectedPins);
//enableBlinkingCursor(enabled_gpio);
//clear screen
clear_Screen(enabled_gpio);
//printf("hello\n");
for(i=0; i<=4;i++)
{
//types "hi!" to the screen
stringToScreen("hi BBB",enabled_gpio);
sleep(1);
clear_Screen(enabled_gpio);
}
//go to the bottom line and write something else
//note: goto_ScreenLine(0,enabled_gpio) will go to the top line.
//goto_ScreenLine(1,enabled_gpio);
//stringToScreen("there!",enabled_gpio);
//really... don't forget to terminate the screen
clear_Screen(enabled_gpio);
terminate_Screen(enabled_gpio,selectedPins);
return 1;
}
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#include "beagle_gpio.h"
#include "beagle_hd44780.h"
/**
* @brief This program (example_04.c) describes how to interface with a
* HD44780 display in a BeagleBone
* @details Compile, and run, this code on the beagleBone terminal with the
* commands:
* rm -f a.out ; gcc -c beagle_gpio.c ; gcc -c beagle_hd44780.c ; gcc beagle_gpio.o beagle_hd44780.o example_04.c ; ./a.out
modified by abhishek gowda
* @return Returns a 1 upon succesful program termination
**/
int main()
{
int i=0;
//specifies the pins that will be used
int selectedPins[]={P8_14,P8_12,P8_11,P9_15,P9_13,P9_12};
system("./build.sh");
printf("done\n");
//adding a simple description for each pin
const char *pinDescription[] = {"DB7","DB6","DB5","DB4","RS","E"};
struct gpioID enabled_gpio[6];
initialize_Screen(enabled_gpio,selectedPins);
//enableBlinkingCursor(enabled_gpio);
//clear screen
clear_Screen(enabled_gpio);
//printf("hello\n");
for(i=0; i<=4;i++)
{
//types "hi!" to the screen
stringToScreen("hi BBB",enabled_gpio);
sleep(1);
clear_Screen(enabled_gpio);
}
//go to the bottom line and write something else
//note: goto_ScreenLine(0,enabled_gpio) will go to the top line.
//goto_ScreenLine(1,enabled_gpio);
//stringToScreen("there!",enabled_gpio);
//really... don't forget to terminate the screen
clear_Screen(enabled_gpio);
terminate_Screen(enabled_gpio,selectedPins);
return 1;
}
beagelebone program for receiving the message from gsm module
#include <stdio.h> // standard input / output functions
#include <string.h> // string function definitions
#include <unistd.h> // UNIX standard function definitions
#include <fcntl.h> // File control definitions
#include <errno.h> // Error number definitions
#include <termios.h> // POSIX terminal control definitionss
#include <time.h> // time calls
int open_port(void)
{
int fd; /* File descriptor for the port */
// fd = ((open("/dev/ttyO1", O_RDWR | O_NOCTTY )) < 0);
fd = open("/dev/ttyO1", O_RDWR | O_NOCTTY );
printf("text openport\n");
if (fd == -1)
{
/* Could not open the port. */
perror("open_port: Unable to open /dev/ttyO1");
}
else
{
fcntl(fd, F_SETFL, 0);
printf("Port1 has been succesfully opened.\n");
}
return(fd);
} //open_port
int configure_port(int fd) // configure the port
{
struct termios port_settings; // structure to store the port settings in
cfsetispeed(&port_settings, B9600); // set baud rates
cfsetospeed(&port_settings, B9600);
port_settings.c_cflag &= ~PARENB; // set no parity, stop bits, data bits
port_settings.c_cflag &= ~CSTOPB;
port_settings.c_cflag &= ~CSIZE;
port_settings.c_cflag |= CS8;
tcsetattr(fd, TCSANOW, &port_settings); // apply the settings to the port
printf("text configport\n");
return(fd);
}
int query_modem(int fd) // query modem with an AT command
{
int m,n,d,e,f,x;
char buff[100];
unsigned char rx_buffer[1];
unsigned char test[5];
unsigned char data1[10];
n=read(fd,buff,100);
//printf("Result %i\n",n);
printf("Buf = %s\n\n\n", buff);
sleep(1);
memset(buff, 0, 100);
printf("AT+CMGF=1\r\n");
d = write(fd, "AT+CMGF=1\r\n", 11);
if (d < 0)
fputs("write() of 4 bytes failed!\n", stderr);
else
printf("write succeed n0 %i\n",d);
sleep(2);
d=read(fd, buff, 100);
printf("Buf = %s\n\n\n", buff);
memset(buff, 0, 100);
/*
printf("AT+CMGS=\"9964129460\"\r\n"); // \r and \n CR n LF
e = write(fd, "AT+CMGS=\"9964129460\"\rhello\n\x1A", 30);
if (e < 0)
fputs("write() of 4 bytes failed!\n", stderr);
else
printf("write succeed n0 %i\n",e);
sleep(8);
e=read(fd, buff, 100);
printf("Buf = %s\n\n\n", buff);
*/
/*
printf("AT+CMGD=1\r\n"); // \r and \n CR n LF
e = write(fd, "AT+CMGD=1\r\n", 11);
if (e < 0)
fputs("write() of 4 bytes failed!\n", stderr);
else
printf("write succeed n0 %i\n",e);
sleep(8);
e=read(fd, buff, 100);
printf("Buf = %s\n\n\n", buff);
*/
//sleep(15);
printf("AT+CMGR=1\r\n"); // \r and \n CR n LF
f = write(fd, "AT+CMGR=1\r\n", 11);
while(1)
{
sleep(1);
for(int i=0;i<=3;i++)
{
read(fd, rx_buffer, (1)); //Filestream, buffer to store in, number of bytes to read (max)
test[i]=rx_buffer[0];
printf("%s\n", rx_buffer);
}
printf("end for data\n");
printf("%s\n", test);
}
/*
for ( x=0;x < 30;x++){
data[x]='\0';
}
x=0;
printf("hello\n");
for(x=0;x<30;x++)
{
data[x]=read(fd, rx_buffer, (30));
//x++;
if(data[x-1]==0x0D&&data[x-2]=='"'){
x=0;
}
}while(!(data[x-1]=='K'&&data[x-2]=='O'));
data[x-3]='\0'; //finish the string before the OK
*/
/*
if (f < 0)
fputs("write() of 4 bytes failed!\n", stderr);
else
printf("write succeed n0 %i\n",f);
sleep(8);
f=read(fd, buff, 100);
printf("Buf = %s\n\n\n", buff);
*/
return (fd);
}
int close_port(int fd)
{
close(fd);
printf("text close port\n");
}
int main(void) //main function
{
int fd = open_port();
sleep(5);
configure_port(fd);
query_modem(fd);
close_port(fd);
return(0);
} //main
device tree source file
/* Copyright (C) 2013 Texas Instruments
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Genral Public License version 2 as
* published by the Free Software Foundation.
Modified by ABHISHEK GOWDA
*/
/dts-v1/;
/plugin/;
/ {
compatible = "ti,beaglebone", "ti,beaglebone-black";
/* identification */
part-number = "uart1";
version = "00A0";
fragment@0 {
target = <&am33xx_pinmux>;
__overlay__ {
pinmux_serial1: pinmux_serial1_pins {
pinctrl-single,pins = <
0x184 0x20 /*P9_24(ZCZ ball D15) RX-enabled MODE 0*/
0x180 0x20 /*P9_26(ZCZ ball D16) RX-enabled MODE 0*/
>;
};
};
};
fragment@1 {
target = <&ocp>;
__overlay__ {
serial1_pinmux_helper {
compatible = "bone-pinmux-helper";
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&pinmux_serial1>;
};
};
};
fragment@2 {
target = <&uart2>; /* really uart1 */
__overlay__ {
status = "okay";
};
};
};
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Genral Public License version 2 as
* published by the Free Software Foundation.
Modified by ABHISHEK GOWDA
*/
/dts-v1/;
/plugin/;
/ {
compatible = "ti,beaglebone", "ti,beaglebone-black";
/* identification */
part-number = "uart1";
version = "00A0";
fragment@0 {
target = <&am33xx_pinmux>;
__overlay__ {
pinmux_serial1: pinmux_serial1_pins {
pinctrl-single,pins = <
0x184 0x20 /*P9_24(ZCZ ball D15) RX-enabled MODE 0*/
0x180 0x20 /*P9_26(ZCZ ball D16) RX-enabled MODE 0*/
>;
};
};
};
fragment@1 {
target = <&ocp>;
__overlay__ {
serial1_pinmux_helper {
compatible = "bone-pinmux-helper";
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&pinmux_serial1>;
};
};
};
fragment@2 {
target = <&uart2>; /* really uart1 */
__overlay__ {
status = "okay";
};
};
};
Subscribe to:
Posts (Atom)