Converting Data From Serial Port to Display as Decimal in Python
Question: I am starting a program that reads data from a radio receiver. The data is 6
bytes long and updates every 1 second. The program reads the serial port USB
data, but the data is in some format that does not display correctly. What I
do know is that it should be in an unsigned integer.

Each data string comes in as 6 bytes and each byte represents a number
corresponds to the data the receiver has logged.

    
    
    import serial
    t = 0
    while t == 0:
    ser = serial.Serial('/dev/tty.SLAB_USBtoUART', 9600, bytesize=8, stopbits=1,      timeout=None, xonxoff=0, rtscts=0, dsrdtr=0)
    s=ser.readline(6)
    #s=ser.read(6)
    print("Streams received during interval: ")
    print (s)
    
    print("__________")
    end
    

I am expecting an output that looks like:

> 0 101 0 0 91 145

but what I am getting is:

> eV�

I think there is something off in the data coming in and how it prints in the
print statement. I just need to make sure the data is coming in correctly
before I move on.


Answer: That's because you are converting bytes to a string with your `'%s' % s`
statement. It's showing up as whatever random ASCII character corresponds to
your bytes.

Instead, try printing the bytes as integers:

    
    
    print ' '.join([ord(ss) for ss in s])
    

