【问题标题】:Serial communication from Raspberry to Arduino with phpSerial not working从 Raspberry 到 Arduino 的串行通信与 phpSerial 不工作
【发布时间】:2016-09-20 08:19:09
【问题描述】:

我开发了一个软件,我需要使用树莓派的串口向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);


       }
    }

感谢您的帮助:)

【问题讨论】:

  • 你是否以相同的波特率打开串口?
  • 是的 115200 波特.. 我找到了这个教程:peopleorientedprogrammer.wordpress.com/2013/05/12/… 但不工作:/
  • 您是否将引脚 2 配置为 Arduino 上的输出?尝试改变它的状态,无论字符到达(所以不要检查 char == '1')
  • 没关系,我已经在本教程中找到了解决方案谢谢:)

标签: php c++ arduino serial-port raspberry-pi


【解决方案1】:

您不必配置硬件握手吗?

你读入了readed_char[i]但检查了readed_char[0],这是正确的吗?

顺便说一句:英语中没有“阅读”。

【讨论】:

  • Oups 大声笑,我找到了.. 在教程中:peopleorientedprogrammer.wordpress.com/2013/05/12/… 在故障排除部分,我打开了 minicom 并将端口名称更改为“ACM0”。在 php_serial_class 中。 php : 改变 : $ret = $this->_exec("stty -F" . $this->_device . " " . (int) $rate, $out); to $ret = $this->_exec("stty -F" . $this->_device . " raw speed " . (int) $rate, $out);
猜你喜欢
  • 1970-01-01
  • 2019-05-27
  • 2018-04-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多