Hello! I am working with PySerial for the first time, and attempting to follow this tutorial\ to send and receive data from an ESP32 in Python. Here is the code from the tutorial that I am running:
Arduino
void setup() {
Serial.begin(115200);
pinMode(pin, OUTPUT);
}
void loop() {
while(Serial.available()){
Serial.write(Serial.read());
x = Serial.read();
}
delay(10);
}
Python
import serial
import time
ser = serial.Serial()
ser.baudrate = 115200
ser.port = 'COM4'
ser.open()
values = bytearray([4, 9, 62, 144, 56, 30, 147, 3, 210, 89, 111, 78, 184, 151, 17, 129])
ser.write(values)
total = 0
while total < len(values):
print(ord(ser.read(1)))
total=total+1
ser.close()
When I run this code, the data has the right length but is just a random series of numbers, like in this screenshot:
As far as I can tell I am ser.read correctly, so I'm not sure if this is a decoding error. I have tried just sending a single number, with the same result, the output is different than what I sent. I have also tried using a different ESP, a different USB port on my computer, and a different USB cable, the result is the same. What is going on here?
Thank you!
