diff --git a/examples/stepper_absolute.py b/examples/stepper_absolute.py index c4fc914..c2f705e 100644 --- a/examples/stepper_absolute.py +++ b/examples/stepper_absolute.py @@ -70,7 +70,7 @@ def step_absolute(the_board): # create an accelstepper instance for a TB6600 motor drive # if you are using a micro stepper controller board: # pin1 = pulse pin, pin2 = direction - motor = the_board.set_pin_mode_stepper(interface=2, pin1=PULSE_PIN, + motor = the_board.set_pin_mode_stepper(interface=1, pin1=PULSE_PIN, pin2=DIRECTION_PIN) # if you are using a 28BYJ-48 Stepper Motor with ULN2003 diff --git a/examples/stepper_continuous.py b/examples/stepper_continuous.py index 19bc590..291ad1a 100644 --- a/examples/stepper_continuous.py +++ b/examples/stepper_continuous.py @@ -26,6 +26,9 @@ """ Run a motor continuously without acceleration """ +# GPIO Pins +PULSE_PIN = 8 +DIRECTION_PIN = 9 # Create a Telemetrix instance. board = telemetrix.Telemetrix() @@ -39,24 +42,31 @@ def the_callback(data): # create an accelstepper instance for a TB6600 motor driver -# motor = board.set_pin_mode_stepper(interface=1, pin1=7, pin2=8) +motor = board.set_pin_mode_stepper(interface=1, pin1=PULSE_PIN, pin2=DIRECTION_PIN) -# if you are using a 28BYJ-48 Stepper Motor with ULN2003 -# comment out the line above and uncomment out the line below. -motor = board.set_pin_mode_stepper(interface=8, pin1=8, pin2=10, pin3=9, pin4=11) +try: + while True: + # set the max speed and speed + board.stepper_set_max_speed(motor, 999) + board.stepper_set_speed(motor, 500) + # run the motor + board.stepper_run_speed(motor) -# set the max speed and speed -board.stepper_set_max_speed(motor, 900) -board.stepper_set_speed(motor, 500) + time.sleep(5) + + # reverse direction + board.stepper_stop(motor) + time.sleep(2) + + board.stepper_set_max_speed(motor, 999) + board.stepper_set_speed(motor, -500) + board.stepper_run_speed(motor) + + time.sleep(5) + +except KeyboardInterrupt: + board.shutdown() + sys.exit(0) -# run the motor -board.stepper_run_speed(motor) -# keep application running -while True: - try: - time.sleep(1) - except KeyboardInterrupt: - board.shutdown() - sys.exit(0) diff --git a/examples/stepper_relative.py b/examples/stepper_relative.py index 670e25b..1bf31af 100644 --- a/examples/stepper_relative.py +++ b/examples/stepper_relative.py @@ -63,7 +63,7 @@ def step_relative(the_board): # create an accelstepper instance for a TB6600 motor driver # if you are using a micro stepper controller board: # pin1 = pulse pin, pin2 = direction - motor = the_board.set_pin_mode_stepper(interface=2, pin1=PULSE_PIN, + motor = the_board.set_pin_mode_stepper(interface=1, pin1=PULSE_PIN, pin2=DIRECTION_PIN) # if you are using a 28BYJ-48 Stepper Motor with ULN2003 diff --git a/examples/stepper_run_speed_to_position.py b/examples/stepper_run_speed_to_position.py index 8a6e52c..6cd1850 100644 --- a/examples/stepper_run_speed_to_position.py +++ b/examples/stepper_run_speed_to_position.py @@ -24,6 +24,9 @@ """ Run a motor using runSpeedToPosition position """ +# GPIO Pins +PULSE_PIN = 8 +DIRECTION_PIN = 9 # Create a Telemetrix instance. board = telemetrix.Telemetrix() @@ -39,7 +42,7 @@ def the_callback(data): # if you are using a 28BYJ-48 Stepper Motor with ULN2003 # comment out the line above and uncomment out the line below. -motor = board.set_pin_mode_stepper(interface=8, pin1=8, pin2=10, pin3=9, pin4=11) +motor = board.set_pin_mode_stepper(interface=1, pin1=PULSE_PIN, pin2=DIRECTION_PIN) # set the max speed and target position diff --git a/examples/wifi/blink_wifi.py b/examples/wifi/blink_wifi.py index 9a83f23..ff1331d 100644 --- a/examples/wifi/blink_wifi.py +++ b/examples/wifi/blink_wifi.py @@ -28,10 +28,10 @@ """ # some globals -DIGITAL_PIN = 5 # the board LED +DIGITAL_PIN = 2 # the board LED # Create a Telemetrix instance. -board = telemetrix.Telemetrix(ip_address='192.168.2.112') +board = telemetrix.Telemetrix(ip_address='192.168.2.118', ip_port=31336) # Set the DIGITAL_PIN as an output pin board.set_pin_mode_digital_output(DIGITAL_PIN) diff --git a/examples/wifi/servo_wifi.py b/examples/wifi/servo_wifi.py index 0cb7a47..9d8115b 100644 --- a/examples/wifi/servo_wifi.py +++ b/examples/wifi/servo_wifi.py @@ -31,7 +31,7 @@ SERVO_PIN = 4 # Create a Telemetrix instance. -board = telemetrix.Telemetrix(ip_address='192.168.2.220') +board = telemetrix.Telemetrix(ip_address='192.168.2.168') board.set_pin_mode_servo(SERVO_PIN) time.sleep(.2) board.servo_write(SERVO_PIN, 90) diff --git a/setup.py b/setup.py index 1cfb995..27b2fb8 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ packages=['telemetrix'], install_requires=['pyserial'], - version='1.20', + version='1.30', description="Remotely Control And Monitor Arduino-Core devices", long_description=long_description, long_description_content_type='text/markdown', diff --git a/telemetrix/private_constants.py b/telemetrix/private_constants.py index aef814a..d71bb91 100644 --- a/telemetrix/private_constants.py +++ b/telemetrix/private_constants.py @@ -103,7 +103,7 @@ class PrivateConstants: FEATURES = 20 DEBUG_PRINT = 99 - TELEMETRIX_VERSION = "1.20" + TELEMETRIX_VERSION = "1.30" # reporting control REPORTING_DISABLE_ALL = 0 diff --git a/telemetrix/telemetrix.py b/telemetrix/telemetrix.py index 7655871..ed41519 100644 --- a/telemetrix/telemetrix.py +++ b/telemetrix/telemetrix.py @@ -315,8 +315,9 @@ def __init__(self, com_port=None, arduino_instance_id=1, raise RuntimeError(f'Telemetrix4Arduino firmware version') else: - if self.firmware_version[0] < 5: - raise RuntimeError('Please upgrade the server firmware to version 5.0.0 or greater') + # if self.firmware_version[0] < 5: + # raise RuntimeError('Please upgrade the server firmware to version ' + # '5.0.0 or greater') print(f'Telemetrix4Arduino firmware version: {self.firmware_version[0]}.' f'{self.firmware_version[1]}.{self.firmware_version[2]}') command = [PrivateConstants.ENABLE_ALL_REPORTS] @@ -1280,7 +1281,7 @@ def stepper_set_speed(self, motor_id, speed): :param motor_id: 0 - 3 - :param speed: 0 - 1000 The desired constant speed in steps per + :param speed: -1000 - 1000 The desired constant speed in steps per second. Positive is clockwise. Speeds of more than 1000 steps per second are unreliable. Speed accuracy depends on the Arduino crystal. Jitter depends on how frequently you call the @@ -1288,23 +1289,34 @@ def stepper_set_speed(self, motor_id, speed): The speed will be limited by the current value of stepper_set_max_speed(). """ + if not self.stepper_info_list[motor_id]['instance']: if self.shutdown_on_exception: self.shutdown() raise RuntimeError('stepper_set_speed: Invalid motor_id.') - if not 0 < speed <= 1000: + if not -1000 <= speed <= 1000: if self.shutdown_on_exception: self.shutdown() - raise RuntimeError('stepper_set_speed: Speed range is 0 - ' - '1000.') + raise RuntimeError('stepper_set_speed: speed range is -1000 to 1000') - self.stepper_info_list[motor_id]['speed'] = speed + if speed < 0: + polarity = 1 + else: + polarity = 0 - speed_msb = speed >> 8 - speed_lsb = speed & 0xff + speed = abs(speed) + if not self.stepper_info_list[motor_id]['instance']: + if self.shutdown_on_exception: + self.shutdown() + raise RuntimeError('stepper_move: Invalid motor_id.') + + position_bytes = list(speed.to_bytes(2, 'big', signed=True)) - command = [PrivateConstants.STEPPER_SET_SPEED, motor_id, speed_msb, speed_lsb] + command = [PrivateConstants.STEPPER_SET_SPEED, motor_id] + for value in position_bytes: + command.append(value) + command.append(polarity) self._send_command(command) def stepper_get_speed(self, motor_id):