主要内容

使用串行块与Arduino服务器通信

这个例子展示了如何使用串行配置,串行接收,串行发送块与一个Arduino®。在本例中,您发送读取命令Arduino Uno使用串行发送块。Arduino发回的信号读取从模拟针串行接收块。

设置

插入一个Arduino Uno电脑使用Arduino IDE和加载下面的程序。配置的代码使用端口设置。

/ /延迟(ms)之间的连续扫描在流模式int interScanDelay = 20;int inputPin1 = A2;int sensorValue1 = 0;int inputPin2 = A3;int sensorValue2 = 0;int inByte = 0;无效的设置(){Serial.begin (9600);}无效循环(){如果(Serial.available () > 0) {inByte = Serial.read ();开关(inByte){案例“2”:/ /读取和发送传感器的值从Arduino电路板sensorValue1 = analogRead (inputPin1);Serial.write (sensorValue1); sensorValue2 = analogRead(inputPin2); Serial.write(sensorValue2); delay(interScanDelay); break; default: break; } } }

进气阀打开文件还包括在这个例子。

按需从服务器读取

这个模型使用串行发送块发送命令Arduino返回一些数据。串行接收块读取返回的数据。

使用以下命令打开模型。

open_system (“demoinstrsl_Serial_read_binary”);

使用以下命令关闭模式。

close_system (“demoinstrsl_Serial_read_binary”);

结果

伊诺程序配置为读取的值从模拟Arduino别针(A2 A3)。你看到的输出模型取决于类型的传感器连接到模拟Arduino的别针。

另请参阅

||