Hi,
I've been working with the rotary encoder V1 with wrapping disabled. This works great.
We have recently switched to rotary encoder V2. We are using the same code to disable the wrapping (adapted from the ibl code):
def connect(self):
if self.RE_PORT == "COM#":
return
self.rotary_encoder = RotaryEncoderModule(self.RE_PORT)
# Reading the current position doesn't work unless you do this
self.rotary_encoder.disable_stream()
self.rotary_encoder.set_zero_position()
self.set_thresholds()
self.rotary_encoder.enable_evt_transmission()
# Disable wrapping so we don't need to count the number of turns
self.rotary_encoder.set_wrappoint(0)
self.connected = True
def set_wrappoint(self, wrap_point):
"""
Sets wrap point (number of tics in a half-rotation)
:ivar int wrap_point: number of tics in a half-rotation.
"""
ticks = self.__degrees_2_pos(wrap_point)
data = ArduinoTypes.get_uint8_array([self.COM_SETWRAPPOINT, ticks])
self.arcom.write_array(data)
return self.arcom.read_uint8() == 1
Where COM_SETWRAPPOINT = ord("W")
I printed the ticks from the rotary encoder and it seems to wrap at around 20300 (seems like quite a random number)
We are reading the position (the ticks then converted to degrees with this function:
def current_position(self):
"""
Retrieves the current position.
"""
self.arcom.write_array([self.COM_GETCURRENTPOS])
data_in_bytes = b"".join(self.arcom.read_bytes_array(2))
ticks = int.from_bytes(data_in_bytes, byteorder="little", signed=True)
return self.__pos_2_degrees(ticks)
Where COM_GETCURRENTPOS = ord("Q")
Do you have any idea what might be happening?
Thanks in advance!