怎样使用PySerial接口Python和Arduino

网友投稿 247 2022-11-15

怎样使用PySerial接口Python和Arduino

步骤1:安装

cd pyserial-2.6

为确保所有安装正确的设备都打开空闲并输入在“导入序列号”中。如果没有错误出现,则一切正常。

您可以通过

ls /dev/tty.*

现在进行测试,将以下草图上传到Arduino。我不知道这在Arduino克隆上将如何工作。

void setup() {

Serial.println(“Ready”); // print “Ready” once

}

void loop() {

char inByte = ‘ ’;

char inByte = Serial.read(); // read the incoming data

Serial.println(inByte); // send the data back in a new line so that it is not all one long line

}

delay(100); // delay for 1/10 of a second

}

步骤3:程序空闲

下一步在Idle中创建一个新窗口并创建以下程序。

import serial

counter = 32 # Below 32 everything in ASCII is gibberish

while True:

counter +=1

ser.write(str(chr(counter))) # Convert the decimal number to ASCII then send it to the Arduino

print ser.readline() # Read the newest output from the Arduino

sleep(.1) # Delay for one tenth of a second

if counter == 255:

counter = 32

请记住两点。要确定您的Arduino连接了哪个串行端口,请查看Arduino草图的右下角。不管是什么,都应该是Python程序第3行中的引号。

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:SpringBoot不读取bootstrap.yml/properties文件问题
下一篇:PLC和PAC,你该如何选择?
相关文章

 发表评论

暂时没有评论,来抢沙发吧~