簡體   English   中英

使用處理連接到Arduino的串行端口的問題

[英]Problems with connecting to the serial port of the arduino using processing

首先,我知道這個問題已經問了很多,但是找不到解決我問題的答案。 因此,當我嘗試使用處理將內容寫入Arduino的串行監視器時,它說該端口(在我的情況下為“ com3”)繁忙。 我不知道它會忙什么,因為我已經設置了讀取串行監視器的延遲。

Arduino代碼:

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
 //  Serial.println("started");
 //  Serial.println();
}

void loop() {
   if(Serial.available()){
      char ch = (char) Serial.read();
      Serial.println(ch);
      ch = "";
      delay(100);
}

處理代碼:

import processing.serial.*;

Serial sPort;
String port;

void setup() {
  port = Serial.list()[0];
  sPort = new Serial(this, port, 9600);
  //port.write("hey, its working");
}

我知道這確實很基本,但是我在使代碼顯示盡可能小的同時使代碼盡可能地小

提前致謝

看來,您嘗試同時從Arduino串行監視器從運行的Processing草圖訪問Serial端口。

需要特別注意的是,Arduino IDE串行監視器本身就是一個與Arduino通信的過程。 Arduino無法同時與串行監視器和其他程序對話。

但是您要監視Arduino必須說的內容。 請改用處理。 您已經將郵件發送回去了。 您要做的就是在處理應用程序中記錄傳入的串行消息。

只需將其添加到您的處理繪制循環中即可:

if (sPort.available() > 0) {
  print(sPort.readSring());
}

關閉Arduino串行監視器,運行Processing Sketch,您應該在Processing Console中看到發送的任何內容(使用Arduino中的Serial.print)。

就像Serial.read一樣,Serial.print是用於在插入USB電纜后與計算機上任何程序進行通信的功能。 串行監視器是其中之一,但還有許多其他功能,其中包括“正在處理”。

暫無
暫無

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

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