英文:
Python not printing same as Arduino Serial Monitor
问题
我试图从ESP32的闪存内存中读取一些浮点数值。它们以每行一个的方式存储。我想在Python中绘制这些值,但从其串行监视器与Arduino的读数都不同。
Arduino示例代码:
while (file.available()) {
num = file.parseFloat();
str = String(num, 3);
Serial.println(str);
//Serial.println(num);
}
Serial.println("Done");
Python代码:
while True:
line = ser.readline() # 读取一个字节字符串
if line:
string = line.decode() # 将字节字符串转换为Unicode字符串
if "Done" in string:
break
# num = float(string) # 将Unicode字符串转换为浮点数
print(string)
# print(num)
我尝试在Arduino中直接打印浮点数,也尝试将其转换为字符串,两者都在Arduino的串行监视器中正常工作,但对于Python读取都不起作用。
在照片中,您可以看到一些值只是垃圾(例如-0.50.000)。有没有修复的想法?谢谢!
英文:
I am trying to read some float values from the flash memory of an ESP32. They are stored one per line. I want to plot these values in Python, but the readings from its serial monitor vs Arduino's are all different.
Arduino sample code:
while(file.available()){
num = file.parseFloat();
str = String(num, 3);
Serial.println(str);
//Serial.println(num);
}
Serial.println("\nDone");
Python code:
while(1):
line = ser.readline() # read a byte string
if line:
string = line.decode() # convert the byte string to a unicode string
if ("Done" in string):
break
#num = float(string) # convert the unicode string to a float
print(string)
#print(num)
I tried both printing the float directly in Arduino as well as converting it to string, both work well in Arduino's Serial Monitor, neither works for the Python reading.
In the photo you can see some values are just thrash (ex -0.50.000). Any ideas for a fix? Thank you!
答案1
得分: 0
最后,我通过将波特率从115200降低到9600来解决了这个问题。
英文:
In the end I solved this by changing the baudrate down from 115200 to 9600.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论