0
Hello, People
I have the following code on Arduino
if((digitalRead(4) != 1)||(digitalRead(5) != 1))
{
Serial.print("\t");
Serial.print(analogRead(A0));
Serial.print(",");
Serial.print(millis());
Serial.print("\n");
}
And with it, I read in Python with the following code:
def leituraSerial():
tempo_leitura = time.time() + (TIMER + 1.6) # Contador de TIMER segundos
k = 0
while(time.time() <= tempo_leitura):
print("\n Leitura Iniciada!")
aux = entrada.readline()
str(aux)
print(aux.decode('ascii'))
I tried several encodings of cp1252, windows-1250, utf-8, latin_1 and so on. some return x00 with the value I wanted, others give error, the way the code is above, it runs, but if I add, for example:
ts, tp = aux.split(",")
Already returns me the following error:
'ascii' codec can't decode byte 0xfe in position 8: ordinal not in range(128)
If you use utf-8:
'utf-8' codec can't decode byte 0xfd in position 6: invalid start byte
So what the hell is going on???
The
str(aux)
is doing nothing;str()
returns the value of a string, and does not modify it. What happens if you doprint(str(aux))
without thedecode
?– Pedro von Hertwig Batista
If I remember correctly, comes a byte-Object, b' t0,4998 n', for example.
– FourZeroFive