篇首语:本文由小编为大家整理,主要介绍了arduino_1.0.1的串口监视器应该怎么用?相关的知识,希望对你有一定的参考价值。
关于Arduino开发环境的串口监视原本监视串口通信状态。在使用之前,我们需要设置以下方法。
1、选择编号的Arduino工具= = >串行端口。
2、在工具=>串行监视器中打开串口监视器。
3、你的程序集的工具,在速度选择框的右下角选择你的串行端口的速度,例如,如果你的串口初始化代码编写serial.begin(9600);选择9600波特率的选择。
4、可现在,在发送按钮可将输入的数据在输入框的Arduino串口,和下面的文本框中显示的数据从串口接收。
参考技术A 回答您好,我这边正在为您查询,请稍等片刻,我这边马上回复您~[开心]
亲您好很高兴为您解答,关于Arduino开发环境的串口监视原本监视串口通信状态。在使用之前,我们需要设置以下方法。1、选择编号的Arduino工具= = >串行端口。2、在工具=>串行监视器中打开串口监视器。3、你的程序集的工具,在速度选择框的右下角选择你的串行端口的速度,例如,如果你的串口初始化代码编写serial.begin(9600);选择9600波特率的选择。4、可现在,在发送按钮可将输入的数据在输入框的Arduino串口,和下面的文本框中显示的数据从串口接收。
希望以上回答对您有所帮助~ 如果您对我的回答满意的话,麻烦给个赞哦~[开心]
使用javascript和socket.io从串口显示多个传感器数据
我是Node.JS和Arduino的新手。我有一个带有温度传感器的Arduino设置。我正在用Arduino读取温度值。我的串口监视器输出如下:
串口监视器:
0.050.100.150.200.250.300.34
我使用serialport将数据从Arduino发送到我的终端,然后以图表形式在我的webbrowser上显示数据。我正在使用express和socket.io。这是与index.js的arduino和浏览器的连接。还有一个index.html
index.js:
var express = require("express"); var app = express(); var http = require("http").Server(app); var server = http.listen(4000, "0.0.0.0", () => { //Start the server, listening on port 4000. console.log("Listening to requests on port 4000..."); }) var io = require("socket.io")(server); //Bind socket.io to our express server. app.use(express.static("public")); //Send index.html page on GET / const SerialPort = require("serialport"); const Readline = SerialPort.parsers.Readline; const port = new SerialPort("/dev/ttyUSB0"); //Connect serial port to port COM3. Because my Arduino Board is connected on port COM3. See yours on Arduino IDE -> Tools -> Port const parser = port.pipe(new Readline({delimiter: " "})); //Read the line only when new line comes. parser.on("data", (temp) => { //Read data console.log(temp); var today = new Date(); io.sockets.emit("temp", {date: today.getDate()+"-"+today.getMonth()+1+"-"+today.getFullYear(), time: (today.getHours())+":"+(today.getMinutes()), temp:temp}); //emit the datd i.e. {date, time, temp} to all the connected clients. }); io.on("connection", (socket) => { console.log("Someone connected."); //show a log as a new client connects. })
从串口接收的温度数据Arduino显示在index.html(webbrowser)中。
index.html的:
Temperature Plot Temperature Graph
Date:
如果Arduino上只有1个传感器温度,一切正常,但是当我添加另一个带有串行监视器结果的温度传感器,如下所示,使传感器数据无法以index.html的形式出现在图表中,而控制台浏览器也只能显示与串行监视器相同的数据。
带2个温度传感器的串行监视器(温度传感器之间的读数结果用空格分隔)
0.05 1.000.10 1.000.15 0.990.20 0.980.25 0.970.30 0.960.34 0.94
我已经尝试解决这个问题差不多一个星期了,我已经尝试了很多方法来解决这个问题,但它没有用,我确实需要你的帮助
arduino代码:
double x; //I simulate 2 temperature sensor values void setup() { Serial.begin(115200); x = 0; } void loop() { Serial.print(sin(x)); Serial.print(" "); Serial.println(cos(x)); delay(50); // seting batasan input fungsi sinus x += 0.05; if(x>= 2*3.14){ x = 0; } }
答案
其中基本上有两个问题。
- 如何格式化数据并使用
express
服务器并将其发送到前端 - 如何使用chart.js在图表中显示多个数据集
第一名
代码中的行
...const parser = port.pipe(new Readline({delimiter: "
"}));...
实际上捕获每一行数据。但是由于arduino的输出包含同一行中的数据,我们将不得不在split()
字符处使用space
。因此,要获得多个温度值的array
,您可以使用tempArray = temp.split(" ");
。然后可以将此阵列发送到前端。
第二名
获得温度值数组后,可以使用将该数组本身发送到前端
// Notice I have replaced `temp` with `tempArray`io.sockets.emit("temp", {date:today.getDate()+"-"+today.getMonth()+1+"-"+today.getFullYear(), time: (today.getHours())+":"+(today.getMinutes()), temp:tempArray}); });
在前端,dataset
对象中的Chart
是一个数组。如果要向图表添加多个数据集,只需添加一个数据集对象即可添加它们:
....datasets: [{ label: "Sensor1", borderColor: "#FF5733", data: [], fill: false, pointStyle: "circle", backgroundColor: "#3498DB", pointRadius: 5, pointHoverRadius: 7, lineTension: 0, },........ { label: "Sensor2", borderColor: "#FFFF33", data: [], fill: false, pointStyle: "circle", backgroundColor: "#34FFDB", pointRadius: 5, pointHoverRadius: 7, lineTension: 0, },]....
现在,在socket.on("temp", function(data){...})
内你可以像这样推送数据:
chart.dataset[i].data.push(data.temp[i]) // looping over i
编辑
要将数据输入数据集,可以使用“for”循环,如下所示:
for (var i = 0; i < datasets.length; i++) { chart.datasets[i].data.push(data.temp[i]);}
以上是关于arduino_1.0.1的串口监视器应该怎么用?的主要内容,如果未能解决你的问题,请参考以下文章