0

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.

Smesh
  • 3
  • 3
  • [Enable error reporting](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php) so you can find out why the script is not running successfully. – Chris May 30 '16 at 21:52
  • @Chris I get this error Fatal error: No stty availible, unable to run. in /var/www/html/PhpSerial.php on line 56 – Smesh May 30 '16 at 21:56
  • Do any of the answers in [this thread](http://stackoverflow.com/questions/23332768/phpserial-no-stty-availible-cant-seem-to-get-it-working) solve your issue? – Chris May 30 '16 at 22:04
  • Ok, so I fixed the error part, and now it is only showing Received: (blank here) so it is still not showing the string I am sending from the Arduino. – Smesh May 30 '16 at 22:08
  • Anybody something? – Smesh May 31 '16 at 09:52
  • Was there ever a solution for this? I am in the same situation, where I can NOT read the RPi serial port for incoming data send back from my connected Arduino (via USB cable)... I can SEND/WRITE... but READ.. Seems to be a tons of these dead posts around here? Is this not possible? – whispers Oct 03 '18 at 14:52

0 Answers0