簡體   English   中英

使用phpSerial從Raspberry到Arduino的串行通信不起作用

[英]Serial communication from Raspberry to Arduino with phpSerial not working

我開發了一個軟件,我需要使用樹莓派的串行端口將數據發送到arduino。

我使用phpSerial,但是不可能知道使用此代碼在Arduino上接收了什么數據。 我在端口2上測試了led,但是當我發送此數據時,led不會點亮。

在樹莓上

    $serial = new phpSerial;
    $serial->deviceSet("/dev/ttyACM0");
    $serial->confBaudRate(115200);
    $serial->confParity("none");
    $serial->confCharacterLength(8);
    $serial->confStopBits(1);
    $serial->deviceOpen();
    sleep(1);
    $serial->sendMessage("1");
    echo $serial->readPort();
    $serial->deviceClose();

在ARDUINO

  if (Serial.available() > 0)  {

      readed_char[i] = (char)Serial.read();
      Serial.print(readed_char[i]);

      if (readed_char[0] == '1'){

         digitalWrite(2,HIGH);


       }
    }

感謝幫助 :)

您是否不必配置硬件握手?

您讀了readed_char [i],但檢查了readed_char [0],這是正確的嗎?

順便說一句:沒有英語的“已讀”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM