ARDUINO SIDE
Connect Arduino to Raspberry through USB.Load on Arduino this simple sketch that sends back everything on serial port.
byte input;Test the Arduino connection using screen. Probably Arduino interface is /dev/ttyACM0
void setup() {
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
input = Serial.read();
Serial.write((char)input);
}
}
sudo screen /dev/ttyACM0 9600
RASPBERRY SIDE
To use serial port within PHP I suggest this library PhpSerial.php
Load on the WebServer this php page
Load on the WebServer this php page
<?phpThat's all!
include 'include/PhpSerial.php';
$serial = new phpSerial;
$serial->deviceSet("/dev/ttyACM0");
$serial->confBaudRate(9600);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->confFlowControl("none");
$serial->deviceOpen();
$serial->sendMessage("Hello World!");
$read = $serial->readPort();
echo $read;
$serial->deviceClose();
?>
Nessun commento:
Posta un commento