Raspberry pi通过php

时间:2016-05-30 21:48:33

标签: php arduino raspberry-pi3

我有一个Arduino Nano通过usb端口连接到我的Raspberry pi,我正在尝试读取传入的串行数据,这是RFID卡的ID。这是我的php_serial代码

<?php
include 'PhpSerial.php';
$serial = new PhpSerial;

//首先我们必须指定设备。这适用于Linux和Windows(如果 //你的linux串口设备是/ dev / ttyS0用于COM1等)

$serial->deviceSet("/dev/ttyUSB0");

//我们可以改变波特率,奇偶校验,长度,停止位,流量控制

$serial->confBaudRate(9600);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->confFlowControl("none");

//然后我们需要打开它

$serial->deviceOpen();

//读取内容

$message = $serial->readPort();

echo ( "<br>Received: $message<br>" );

$serial->deviceClose();

?>

我在浏览器中打开页面,但没有看到任何数据。它只是空白。

BTW - Arduino代码:

   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
}

//功能

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;
}

编辑:Arduino的数据仍未显示在网页上。

0 个答案:

没有答案