Hardware Reference
In-Depth Information
When the window is first loaded, we need to first set the relay pin as an output. This is
done using a get command inside the JavaScript file:
window.onload = function() {
$.get( "command.php", {target: target, type: type,
command: "/mode/7/o"} );
}
The buttons call a function called buttonClick and pass their ID as an argument to
this function. For example, this is the code for the ON button:
if (clicked_id == "1"){
$.get( "command.php", {target: target, type: type,
command: "/digital/7/1"} );
}
You can see that all these commands call a PHP file. This file is responsible for interfa-
cing with the Arduino board. The file starts by receiving the different arguments coming
from the interface:
$type = $_GET['type'];
$target = $_GET['target'];
$command = $_GET['command'];
Since we'll always use serial communications via the USB port in this project, I will only
provide details for the part responsible for serial communications. We assign the target to
the serial_port variable:
$serial_port = $target;
Now, we can define the different parameters of the serial connection with the Arduino
board:
$serial = new phpSerial;
$serial->deviceSet($serial_port);
$serial->confBaudRate(9600);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
Search WWH ::




Custom Search