【发布时间】:2014-03-02 14:51:59
【问题描述】:
我正在尝试使用 Processing 通过(伪)串行连接从 Arduino 读取 100 个传感器数据条目。我正在使用的处理草图如下:
// import the serial library for Processing
import processing.serial.*;
// define a new port object
Serial port;
PrintWriter outputFile;
int i = 0;
// setup a port
void setup()
{
outputFile = createWriter("data.txt");
port = new Serial(this, "COM3", 9600);
port.bufferUntil('n');
}
void draw()
{
delay(100); //must be the same delay as used in the arduino sketch
// create a string to store the read-in values
String serialBuffer = port.readString();
if(serialBuffer != null)
{
i++;
outputFile.println(serialBuffer);
outputFile.flush();
}
if(i==99)
{
outputFile.close();
exit();
}
}
不幸的是,我的 data.txt 文件中存储的条目通常少于 100 个,并且其中一些条目(大约 3-5 个)显示了换行符。我究竟做错了什么? Arduino IDE的串口监视器没有打开!
【问题讨论】:
标签: java serial-port arduino processing