2

I'm using the python serial module to try to read a rotary encoder. I am receiving something but I am not sure what it is?

When not turning the encoder I get the following bytes:

b'y\xf6\xf6\xf6\xf6\x16\xd6\x16\xb6\xd6\x06\x00'

When I turn the encoder I get a much longer sequence of bytes:

b'y\xf6\xf6\xf6\xf6\x16\x96\x16\xb6\xb6\x06\x00y\xf6\xf6\xf6\xf6\x16\x96\x16\xb66\x06\x00y\xf6\xf6\xf6\xf6\x16\x96\x16v\xd6\x06\x00y\xf6\xf6\xf6\xf6\x16\x96\x16Vv\x06\x00y\xf6\xf6\xf6\xf6\x16\x96\x16V\x16\x06\x00y\xf6\xf6\xf6\xf6\x16\x96\x166V\x06\x00y\xf6\xf6\xf6\xf6\x16\x96\x16\xf6\x96\x06\x00y\xf6\xf6\xf6\xf6\x16\x96\xf6\xd6\xd6\x06\x00y\xf6\xf6\xf6\xf6\x16\x96\xf6\x966\x06\x00y\xf6\xf6\xf6\xf6\x16\x96\xf6V\xf6\x06\x00y\xf6\xf6\xf6\xf6\x16\x96\xd6\xd6\xd6\x06\x00y\xf6\xf6\xf6\xf6\x16v\xf6\xd6\xf6\x06\x00y\xf6\xf6\xf6\xf6\x16v\xd6\xd6v\x06\x00y\xf6\xf6\xf6\xf6\x16v\xb6\xb6\x16\x06\x00y\xf6\xf6\xf6\xf6\x16v\x96\xb6\xf6\x06\x00y\xf6\xf6\xf6\xf6\x16vv\xd66\x06\x00y\xf6\xf6\xf6\xf6\x16vV\x96\xd6\x06\x00y\xf6\xf6\xf6\xf6\x16v6v6\x06\x00y\xf6\xf6\xf6\xf6\x16v\x16\x96\x16\x06\x00y\xf6\xf6\xf6\xf6\x16v\xf6\xd6V\x06\x00y\xf6\xf6\xf6\xf6\x16v\xf6v\x96\x06\x00y\xf6\xf6\xf6\xf6\x16v\xf6\xf6\xb6\x06\x00y\xf6\xf6\xf6\xf6\x16v\xd6vV\x06\x00y\xf6\xf6\xf6\xf6\x16V\xf6\xd6v\x06\x00y\xf6\xf6\xf6\xf6\x16V\xf6\xd6V\x06\x00y\xf6\xf6\xf6\xf6\x16V\xb6\xd6V\x06\x00y\xf6\xf6\xf6\xf6\x16V\x96v\xb6\x06\x00y\xf6\xf6\xf6\xf6\x16Vvvv\x06\x00y\xf6\xf6\xf6\xf6\x16VV\x966\x06\x00y\xf6\xf6\xf6\xf6\x16V6v\x16\x06\x00y\xf6\xf6\xf6\xf6\x16V\x16vv\x06\x00y\xf6\xf6\xf6\xf6\x16V\xf6\xf66\x06\x00y\xf6\xf6\xf6\xf6\x16V\xf6\x16\xb6\x06\x00y\xf6\xf6\xf6\xf6\x166\xf6\xd66\x06\x00y\xf6\xf6\xf6\xf6\x166\xd6\x96v\x06\x00y\xf6\xf6\xf6\xf6\x166\xb6\xf6\xd6\x06\x00y\xf6\xf6\xf6\xf6\x166\xb6\xf6\xf6\x06\x00y\xf6\xf6\xf6\xf6\x166\xb6\xf6\xf6\x06\x00y\xf6\xf6\xf6\xf6\x166\xb6\xf6\xf6\x06\x00'

The python code that I use is:

import serial

ser = serial.Serial(
        port='/dev/ttyAMA0',
        baudrate = 9600,
        #parity=serial.PARITY_NONE,
        #stopbits=serial.STOPBITS_ONE,
        #bytesize=serial.EIGHTBITS,
        timeout=1
)
cnt = 0
while 1:
    try:
        x=ser.readline()
        print(x)
        cnt += 1
    except Exception as e:
        print(e)

I have tried x.decode() x.decode("utf8") x.decode("utf16") also 32 and latin1. Honestly I just don't understand what I am looking at. Any help would be appreciated.

Mike C.
  • 1,761
  • 2
  • 22
  • 46
  • What is sending that serial data? There's something in between your computer and the rotary encoder, right? It's impossible to answer this question without knowing what exactly you are trying to read, and how the data is sent. – Opifex Oct 05 '20 at 19:48
  • @Opifex Yes i am should be receiving a pulse count only. It is a wireless so I am receiving the serial data from a receiver module. The encoder was made by Hohner. I hope this helps. I didn't receive docs with the device and I am trying to get my hands on some now. – Mike C. Oct 05 '20 at 20:24
  • 1
    It will be hard to give a good answer without knowing what you hooked it up to, and without knowing what it is sending. However... a good guess of what might be wrong, is the baudrate. You can try experimenting with it a bit try different values. I suggest trying 115200 first, since it is starting to take the place of 9600 as de facto standard in a lot of newer devices. – Opifex Oct 05 '20 at 20:27
  • Does the rotary encoder have some API documentation or something? That should be available, and it's much easier to use that instead of reverse-engineer. – user202729 Oct 06 '20 at 03:38

0 Answers0