- Joined
- Jul 13, 2016
- Posts
- 1,233
- Solutions
- 13
- Reaction
- 583
- Points
- 557
Hello mga idol baka po pwede makahingi ng tulong kase nagawa ako project, web based siya PHP, hindi ko mapalabas yung ouput nung load cell sa sa webpage.
Python Script:
PHP Webpage:
Python Script:
Python:
from hx711 import HX711
hx = HX711(dout_pin=5, pd_sck_pin=6)
hx.set_reading_format("MSB", "MSB")
hx.set_reference_unit(1)
hx.reset()
hx.tare()
def read_weight():
return hx.get_weight()
while True:
weight = read_weight()
print("Current weight:", weight)
PHP Webpage:
PHP:
<!DOCTYPE html>
<html>
<head>
<title>Load Cell Weight</title>
</head>
<body>
<h1>Current Weight:</h1>
<div id="weight"></div>
<script>
function updateWeight() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("weight").innerHTML = this.responseText;
}
};
xhttp.open("GET", "get_weight.php", true);
xhttp.send();
}
setInterval(updateWeight, 1000);
updateWeight();
</script>
</body>
</html>
PHP:
PHP Script:
<?php
$weight = exec("python3 read_weight.py");
echo $weight;
?>