#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    1
    Rep Power
    0

    Newbie! "simple" question on Pyserial


    This is very basic

    I'm using Pyserial to read and write to a motor controller

    #select I2C device
    ser.write( "\x55\xB0\x05" )
    #n = ser.read(1)
    #print "selected encoder register" , n
    # set I2C device to read and read a byte from register 5
    ser.write( "\x55\xB1\x05\x01" )
    time.sleep(.1)
    n = ser.read(1)
    time.sleep(.1)
    print "ENCODER motor 1 low byte ", n

    This code works but n is printed out as an ASCII character.
    I want to change this so that I can print out or save as a numeric value the value of the byte(s) returned by n

    Thanks, Keith
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    show

    ord(n)

    instead of n.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo