【发布时间】:2021-06-04 16:59:30
【问题描述】:
我有一个问题,我正在尝试通过 ESP32 读取在 Arduino IDE 上制作的代码,但打印的数据显示为 b'' ESP32,它工作得很好。这是代码:
# -*- coding: utf-8 -*-
"""
Created on Fri Mar 5 20:28:19 2021
@author: Andres
"""
import serial
arduino = serial.Serial('COM8', baudrate=115200, timeout=1.0)
while(True):
line = arduino.readline().decode('utf-8')
print(line)
这是ESP32代码(只是通过串口发送数字):
int16_t x=33;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(x);
delay(100);
x=x+1;
if(x==97)
{
x=32;
}
}
我必须说我已经尝试过波特率 9600 和 115200。 我在其他电脑上试过,改了端口的名字,还是不行。
【问题讨论】:
-
你已经三遍检查了它是COM8,串口波特率是9600?
-
这是PC端运行的代码?您还需要添加 ESP32 代码,否则我们无法帮助您。请查看如何创建Minimal, Reproducible Example
-
@TimRoberts,是的,我已经尝试过不同的波特率,并在其他电脑上尝试过其他 COM。但它不起作用。
-
@Tarmo 是的,它在 PC 端运行,我在 ESP32 代码中尝试了不同的想法,如下所示:(我将使用 ESP32 代码编辑问题)
-
在arduino串口监视器上,你能看到日志吗?,试试
Serial.println("hello string");