I'm trying to connect a potentiometer which returns values of integers between 0 and 1023. I'm trying to get this data over Bluetooth to python.
The data is indeed getting transmitted because I do get values on the screen when rotating the potentiometer. But instead of showing up as integers, it shows up like this: b'\xff'
I know in fact that 0 is b'\x00' and 1023 is b'\xff', I have no idea what that's supposed to mean. Can someone offer a fix so it would print numbers from 0 to 1023?
import bluetooth
print ("Searching for devices...")
print ("")
nearby_devices = bluetooth.discover_devices ()
num = 0
print ("Select your device by entering its coresponding number...")
for i in nearby_devices:
num += 1
print (num, ": ", bluetooth.lookup_name (i))
selection = int (input ("> ")) - 1
print ("You have selected", bluetooth.lookup_name (nearby_devices[selection]))
bd_addr = nearby_devices[selection]
port = 1
sock = bluetooth.BluetoothSocket( bluetooth.RFCOMM )
sock.connect((bd_addr, port))
while True:
data = sock.recv(1)
print (data)
Thanks!!!