I have an Arduino Nano connected to my Raspberry pi via usb port and I am trying to read the incoming serial data which is an ID of an RFID Card. Here is my php_serial code
<?php
include 'PhpSerial.php';
$serial = new PhpSerial;
// First we must specify the device. This works on both linux and windows (if // your linux serial device is /dev/ttyS0 for COM1, etc)
$serial->deviceSet("/dev/ttyUSB0");
// We can change the baud rate, parity, length, stop bits, flow control
$serial->confBaudRate(9600);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->confFlowControl("none");
// Then we need to open it
$serial->deviceOpen();
// read stuff
$message = $serial->readPort();
echo ( "<br>Received: $message<br>" );
$serial->deviceClose();
?>
I open the page in the browser and I do not see any data. It is just blank.
BTW - the Arduino Code :
void setup() {
Serial.begin(9600); // for testing and debugging
SPI.begin(); // run SPI library first; if not, RFID will not work
mfrc522.PCD_Init(); // initializing RFID, start RFID library
pinMode(led_pos, OUTPUT);
pinMode(led_neg, OUTPUT);
}
// MAIN PROGRAM
void loop() {
int succesRead = getID(); // read RFID tag
}
// FUNCTIONS
void redLED(){ // red LED on, green LED off
digitalWrite(led_pos, LOW);
digitalWrite(led_neg, HIGH);
}
void greenLED(){ // red LED off, green LED on
digitalWrite(led_pos, HIGH);
digitalWrite(led_neg, LOW);
}
int getID() { // Read RFID
// Getting ready for Reading PICCs
if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue
return 0;
}
if ( ! mfrc522.PICC_ReadCardSerial()) { //Since a PICC placed get Serial and continue
return 0;
}
readTag = "";
for (int i = 0; i < 4; i++) { //
readCard[i] = mfrc522.uid.uidByte[i];
Serial.print(readCard[i], DEC);
readTag=readTag+String(readCard[i], DEC);
}
Serial.println("");
mfrc522.PICC_HaltA(); // Stop reading
return 1;
}
EDIT: The data from the Arduino is still not shown on the web page.