diff --git a/Documentation/28BYJ.md b/Documentation/28BYJ.md index 900f76a..f699b7f 100644 --- a/Documentation/28BYJ.md +++ b/Documentation/28BYJ.md @@ -133,11 +133,9 @@ GpioPins = [18, 23, 24, 25] # Declare an named instance of class pass a name and motor type mymotortest = RpiMotorLib.BYJMotor("MyMotorOne", "28BYJ") -# call the function pass the parameters +# call the function , pass the parameters mymotortest.motor_run(GpioPins , .01, 100, False, False, "half", .05) -# good practise to cleanup GPIO at some point before exit -GPIO.cleanup() ``` If verbose is set to True various information on pin output and status is outputted to screen at the end of a run diff --git a/Documentation/DRV8833_DC.md b/Documentation/DRV8833_DC.md index 7cc855f..1f55057 100644 --- a/Documentation/DRV8833_DC.md +++ b/Documentation/DRV8833_DC.md @@ -73,8 +73,8 @@ NOTE their is no error handling in this class but their is the "cleanup" function, Its left to user to catch exceptions and call "cleanup" if they want. The cleanup function executes GPIO.cleanup() if passed True -More example code is in the DRV8833_DCMot_Test.py file in test subfolder of -rpiMotorLib repository. +More example code is in the DRV8833_or_ L9110S_DC_Test.py file +in test subfolder of rpiMotorLib repository. ```sh import time diff --git a/Documentation/L298N_DC.md b/Documentation/L298N_DC.md index 1aefb5e..2b54c79 100644 --- a/Documentation/L298N_DC.md +++ b/Documentation/L298N_DC.md @@ -166,7 +166,7 @@ def motorone(): print("No errors") finally: print("cleaning up") - MotorOne.cleanup(True) + MotorOne.cleanup(False) if __name__ == '__main__': motorone() diff --git a/Documentation/L9110S_DC.md b/Documentation/L9110S_DC.md index 4ac1794..bfa5fe9 100644 --- a/Documentation/L9110S_DC.md +++ b/Documentation/L9110S_DC.md @@ -89,8 +89,8 @@ NOTE their is no error handling in this class but their is the "cleanup" function, Its left to user to catch exceptions and call "cleanup" if they want. The cleanup function executes GPIO.cleanup() if passed True -More example code is in the DRV8833_DCMot_Test.py file in test subfolder of -rpiMotorLib repository. +More example code is in the DRV8833_or_ L9110S_DC_Test.py file +in test subfolder of rpiMotorLib repository. ```sh import time diff --git a/Documentation/Nema11A3967Easy.md b/Documentation/Nema11A3967Easy.md index deced33..c0cdda1 100644 --- a/Documentation/Nema11A3967Easy.md +++ b/Documentation/Nema11A3967Easy.md @@ -168,7 +168,5 @@ mymotortest = RpiMotorLib.A3967EasyNema(direction, step, GPIO_pins) mymotortest.motor_move(.005, 200 , False, True, "Full", .05) -# good practise to cleanup GPIO at some point before exit -GPIO.cleanup() ``` diff --git a/Documentation/Nema11A4988.md b/Documentation/Nema11A4988.md index 6973f68..5e36c50 100644 --- a/Documentation/Nema11A4988.md +++ b/Documentation/Nema11A4988.md @@ -175,7 +175,5 @@ mymotortest = RpiMotorLib.A4988Nema(direction, step, GPIO_pins, "A4988") # call the function, pass the arguments mymotortest.motor_go(False, "Full" , 100, .01, False, .05) -# good practise to cleanup GPIO at some point before exit -GPIO.cleanup() ``` diff --git a/Documentation/Nema11DRV8825.md b/Documentation/Nema11DRV8825.md index 5c19aca..cc5fa37 100644 --- a/Documentation/Nema11DRV8825.md +++ b/Documentation/Nema11DRV8825.md @@ -133,7 +133,4 @@ mymotortest = RpiMotorLib.A4988Nema(direction, step, GPIO_pins, "DRV8825") # call the function, pass the arguments mymotortest.motor_go(False, "Full" , 100, .01, False, .05) -# good practise to cleanup GPIO at some point before exit -GPIO.cleanup() - ``` diff --git a/Documentation/Nema11L298N.md b/Documentation/Nema11L298N.md index ac47841..3f3b578 100644 --- a/Documentation/Nema11L298N.md +++ b/Documentation/Nema11L298N.md @@ -183,8 +183,6 @@ time.sleep(0.5) # call the function pass the parameters mymotortest.motor_run(GpioPins , 0.1, 50, False, False, "half", .05) -# good practise to cleanup GPIO at some point before exit -GPIO.cleanup() ``` If verbose is set to True various information on pin output and status is outputted to screen at end of a run diff --git a/Documentation/changelog/CHANGELOG.md b/Documentation/changelog/CHANGELOG.md index 42c10c1..f63d5cd 100644 --- a/Documentation/changelog/CHANGELOG.md +++ b/Documentation/changelog/CHANGELOG.md @@ -60,3 +60,8 @@ Version control history: * Added support for LV8729 motor controller. * Added basic test file for threading example. +* version 3.2-3 151022 + * Minor update. + * Added pwm.stop command to all DC motor classes, see github issue 21 + * Added check for negative step numbers in the BYJMotor class, see github issue 20 + diff --git a/Documentation/license/LICENSE.txt b/LICENSE similarity index 100% rename from Documentation/license/LICENSE.txt rename to LICENSE diff --git a/README.md b/README.md index 70b8549..3b49206 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/paypalme/whitelight976) + +[![Website](https://img.shields.io/badge/Website-Link-blue.svg)](https://gavinlyonsrepo.github.io/) [![Rss](https://img.shields.io/badge/Subscribe-RSS-yellow.svg)](https://gavinlyonsrepo.github.io//feed.xml) [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/paypalme/whitelight976) RpiMotorLib, A Raspberry pi python motor library -------------------------------------------------- @@ -17,7 +18,7 @@ Table of contents * [Files](#files) * [Dependencies](#dependencies) * [Components](#components) - * [Notes](#notes) + * [Notes and Issues](#notes-and-issues) Overview -------------------------------------------- @@ -36,7 +37,7 @@ The library is modular so user can just import/use the section they need. * Main Author: Gavin Lyons , [website.](https://gavinlyonsrepo.github.io/). * Project URL: [URL LINK](https://github.com/gavinlyonsrepo/RpiMotorLib) * History: CHANGELOG.md is at repository in documentation. -* Copyright: See LICENSE.md in documentation. +* Copyright: See LICENSE.md * Pull requests,bug reports, suggestions for new components and features welcome. Installation @@ -149,7 +150,7 @@ which uses hardware based timing. The disadvantage being they must install a dependency. -Notes +Notes and Issues ------------------------ **Note 1 Running two motors simultaneously** @@ -162,11 +163,14 @@ file for using threading in test folder. 1. For Unipolar 28BYJ-48 MultiMotorThreading_BYJ.py 2. For Bipolar DRV8825 Stepper MultiMotorThreading_DRV8825.py -**Note 2 Potential Issue with GPIO.cleanup() not working** +**Note 2 Potential Issue with GPIO.cleanup() not working** -See github issue #18 +See github issue #18 and #21 Some users are reporting that GPIO.cleanup() does not work. -This is external function from RPi.GPIO used in test scripts , -I have left it in scripts for the moment as I am not seeing the issue. -If you see this issue simply remove GPIO.cleanup and clear the GPIO you set manually. +It does not switch off or "cleanup" GPIO as it should. +This is external function from RPi.GPIO. It is mainly used in the test scripts. +It is also called by the classes in DC motor if the cleanup method is passed argument "true". +If you see this issue simply don't use GPIO.cleanup() or remove GPIO.cleanup +and clear the GPIO you set manually or use python "del" method to destroy the relevant class object, +to free resources if you need them again. diff --git a/RpiMotorLib/RpiMotorLib.py b/RpiMotorLib/RpiMotorLib.py index 1ac6b9e..bc00003 100755 --- a/RpiMotorLib/RpiMotorLib.py +++ b/RpiMotorLib/RpiMotorLib.py @@ -70,6 +70,10 @@ def motor_run(self, gpiopins, wait=.001, steps=512, ccwise=False, GPIO pins initialized but before motor is moved. """ + if steps < 0: + print("Error BYJMotor 101: Step number must be greater than 0") + quit() + try: self.stop_motor = False for pin in gpiopins: @@ -102,7 +106,8 @@ def motor_run(self, gpiopins, wait=.001, steps=512, ccwise=False, step_sequence[2] = [gpiopins[2]] step_sequence[3] = [gpiopins[3]] else: - print("Error: unknown step type ; half, full or wave") + print("Error: BYJMotor 102 : unknown step type : half, full or wave") + print(steptype) quit() # To run motor in reverse we flip the sequence order. @@ -119,7 +124,8 @@ def display_degree(): print("Size of turn in degrees = {}".format(round(steps*degree, 2))) else: # Unknown Motor type - print("Size of turn in degrees = N/A Motor: {}".format(self.motor_type)) + print("Warning 201 : Unknown Motor Type : {}".format(self.motor_type)) + print("Size of turn in degrees = N/A") def print_status(enabled_pins): """ Print status of pins.""" @@ -154,7 +160,7 @@ def print_status(enabled_pins): except Exception as motor_error: print(sys.exc_info()[0]) print(motor_error) - print("RpiMotorLib : Unexpected error:") + print("Error : BYJMotor 103 : RpiMotorLib : Unexpected error:") else: # print report status if everything went well if verbose: diff --git a/RpiMotorLib/RpiMotorScriptLib.py b/RpiMotorLib/RpiMotorScriptLib.py index 904d0f5..606e8c6 100755 --- a/RpiMotorLib/RpiMotorScriptLib.py +++ b/RpiMotorLib/RpiMotorScriptLib.py @@ -6,8 +6,7 @@ # display the version and help for Rpi package RpiMotorlib # author :Gavin Lyons # web :https://github.com/gavinlyonsrepo/RpiMotorLib -# mail :glyons66@hotmail.com -# python_version :3.5.3 +# python_version :3.7.3 """ # ==========================IMPORTS====================== @@ -15,7 +14,7 @@ import argparse import sys -__version__ = "3.1-2" +__version__ = "3.2-3" __author__ = "Gavin Lyons" __url__ = "https://github.com/gavinlyonsrepo/RpiMotorLib" diff --git a/RpiMotorLib/rpi_dc_lib.py b/RpiMotorLib/rpi_dc_lib.py index a8bd577..ddd8745 100755 --- a/RpiMotorLib/rpi_dc_lib.py +++ b/RpiMotorLib/rpi_dc_lib.py @@ -14,8 +14,7 @@ author :Gavin Lyons web :https://github.com/gavinlyonsrepo/RpiMotorLib - mail :glyons66@hotmail.com - python_version :3.5.3 + python_version :3.7.3 """ # ========================== IMPORTS ====================== @@ -112,6 +111,7 @@ def cleanup(self, clean_up=False): GPIO.output(self.pin_one, False) GPIO.output(self.pin_two, False) self.my_pwm.ChangeDutyCycle(0) + self.my_pwm.stop() if clean_up: GPIO.cleanup() @@ -193,8 +193,9 @@ def cleanup(self, clean_up=False): if self.verbose: print("rpi_dc_lib.py : Cleaning up") GPIO.output(self.pin_one, False) - self.my_pwm.ChangeDutyCycle(0) GPIO.output(self.pin_two, False) + self.my_pwm.ChangeDutyCycle(0) + self.my_pwm.stop() if clean_up: GPIO.cleanup() @@ -331,6 +332,7 @@ def cleanup(self, clean_up=False): GPIO.output(self.pin_one, False) GPIO.output(self.pin_two, False) self.my_pwm.ChangeDutyCycle(0) + self.my_pwm.stop() if clean_up: GPIO.cleanup() diff --git a/RpiMotorLib/rpiservolib.py b/RpiMotorLib/rpiservolib.py index d4df1dc..d01b667 100755 --- a/RpiMotorLib/rpiservolib.py +++ b/RpiMotorLib/rpiservolib.py @@ -7,8 +7,7 @@ # This file is for servos controlled by GPIO PWM # author :Gavin Lyons # web :https://github.com/gavinlyonsrepo/RpiMotorLib -# mail :glyons66@hotmail.com -# python_version :3.4.2 +# python_version :3.7.3 """ # ========================== IMPORTS ====================== # Import the system modules needed to run rpiMotorlib.py diff --git a/setup.py b/setup.py index 3400c81..24bfba2 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="rpimotorlib", - version="3.1", + version="3.2", author="Gavin Lyons", author_email="glyons66@hotmail.com", description="A python 3 library for various motors and servos to connect to a raspberry pi", @@ -11,14 +11,14 @@ license="GPL", keywords="TB6612FNG L9110S DRV8833 A3967 L298 servo motor library raspberry pi 28BYJ-48 A4988 stepper DRV8825", url="https://github.com/gavinlyonsrepo/RpiMotorLib", - download_url='https://github.com/gavinlyonsrepo/RpiMotorLib/archive/3.1.tar.gz', + download_url='https://github.com/gavinlyonsrepo/RpiMotorLib/archive/3.2.tar.gz', packages=['RpiMotorLib'], data_files=[('', ['README.md'])], install_requires=['pip'], setup_requires=['pip'], scripts=['RpiMotorLib/RpiMotorScriptLib.py'], classifiers=[ - "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.7", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", ], ) diff --git a/test/BYJ_Motor_Test.py b/test/BYJ_Motor_Test.py index c9c3329..a7472ff 100755 --- a/test/BYJ_Motor_Test.py +++ b/test/BYJ_Motor_Test.py @@ -16,13 +16,14 @@ from RpiMotorLib import RpiMotorLib """ +# Needed for testing motor stop # To Test motor stop put push button to VCC on GPIO 17 GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) """ -# Declare an named instance of class pass your name and type of motor +# Declare an named instance of class pass your custom name and type of motor mymotortest = RpiMotorLib.BYJMotor("MyMotorOne", "28BYJ") def main(): @@ -30,7 +31,7 @@ def main(): # ====== tests for motor 28BYJ48 ==== - # To Test motor stop , put push button to VCC on GPIO 17 + # Needed for testing motor stop # GPIO.add_event_detect(17, GPIO.RISING, callback=button_callback) # Connect GPIO to [IN1 , IN2 , IN3 ,IN4] on Motor PCB @@ -68,9 +69,8 @@ def button_callback(channel): print("START") main() - GPIO.cleanup() + GPIO.cleanup() # Optional exit() - # =====================END=============================== diff --git a/test/DRV8825_Nema_Test.py b/test/DRV8825_Nema_Test.py index fdd05a5..34ea6f5 100755 --- a/test/DRV8825_Nema_Test.py +++ b/test/DRV8825_Nema_Test.py @@ -92,7 +92,7 @@ def button_callback(channel): print("TEST START") main() - GPIO.cleanup() + GPIO.cleanup() # Optional print("TEST END") exit() diff --git a/test/DRV8833_or_ L9110S_DC_Test.py b/test/DRV8833_or_L9110S_DC_Test.py similarity index 86% rename from test/DRV8833_or_ L9110S_DC_Test.py rename to test/DRV8833_or_L9110S_DC_Test.py index a86a68e..afdc1ec 100755 --- a/test/DRV8833_or_ L9110S_DC_Test.py +++ b/test/DRV8833_or_L9110S_DC_Test.py @@ -4,13 +4,18 @@ import time import RPi.GPIO as GPIO -#import sys -#sys.path.insert(0, '/home/pi/Documents/tech/RpiMotorLib/RpiMotorLib') +""" +# Next 3 lines for development local library path testing import +# Comment out in production release and change rpi_dc_lib.DRV8833NmDc to DRV8833NmDc +import sys +sys.path.insert(0, '/home/pi/Documents/tech/RpiMotorLib/RpiMotorLib') +from rpi_dc_lib import DRV8833NmDc +""" +# Production installed library import from RpiMotorLib import rpi_dc_lib - # ====== tests L9110S -DRV8833 ==== # my pin-outs L9110S -DRV8833 @@ -21,16 +26,15 @@ # in4 B-1A - black = 21 # L9110S B output dir A output PWM -# ======== test motor 1 ================== def motorone(): print(" TEST: testing motor 1") - # Motorssetup + # Motors setup MotorOne = rpi_dc_lib.DRV8833NmDc(26 ,19 ,50 ,True, "motor_one") - # ================ Motors one test section 1============= + # ================ Motors one test section ============= try: print("1. motor forward") MotorOne.forward(15) @@ -81,10 +85,10 @@ def motorone(): def motortwo(): print(" TEST: testing motor ") - # Motorssetup + # Motors setup MotorTwo = rpi_dc_lib.DRV8833NmDc(13 ,21 ,50 ,True, "motor_two") - # ================ Motors two test section 1============= + # ================ Motors two test section ============= try: print("1. motor forward") MotorTwo.forward(15) @@ -131,7 +135,7 @@ def motortwo(): print(error) print("Unexpected error:") finally: - MotorTwo.cleanup(True) + MotorTwo.cleanup(False) # ===================MAIN=============================== diff --git a/test/L298_DCMot_Test.py b/test/L298_DCMot_Test.py index 44e81a4..a617da5 100755 --- a/test/L298_DCMot_Test.py +++ b/test/L298_DCMot_Test.py @@ -3,8 +3,16 @@ import time import RPi.GPIO as GPIO -#import sys -#sys.path.insert(0, '/home/pi/Documents/tech/RpiMotorLib/RpiMotorLib') + +""" +# Next 3 lines for development local library path testing import +# Comment out in production release and change rpi_dc_lib.L298NMDc to L298NMDc +import sys +sys.path.insert(0, '/home/pi/Documents/tech/RpiMotorLib/RpiMotorLib') +from rpi_dc_lib import L298NMDc +""" + +# Production installed library import from RpiMotorLib import rpi_dc_lib # ====== tests for DC motor L298 ==== @@ -124,7 +132,7 @@ def motortwo(): print(error) print("Unexpected error:") finally: - MotorTwo.cleanup(True) + MotorTwo.cleanup(False) # ===================MAIN=============================== diff --git a/test/L298_Step_Test.py b/test/L298_Step_Test.py index f0e9913..c903739 100755 --- a/test/L298_Step_Test.py +++ b/test/L298_Step_Test.py @@ -67,7 +67,7 @@ def button_callback(channel): print("START") main() - GPIO.cleanup() + GPIO.cleanup() # Optional exit() diff --git a/test/LV8729_Nema_Test.py b/test/LV8729_Nema_Test.py index 8d9996e..d01b91f 100755 --- a/test/LV8729_Nema_Test.py +++ b/test/LV8729_Nema_Test.py @@ -102,7 +102,7 @@ def button_callback(channel): print("TEST START") main() - GPIO.cleanup() + GPIO.cleanup() # Optional print("TEST END") exit() diff --git a/test/MultiMotorThreading_BYJ.py b/test/MultiMotorThreading_BYJ.py index 37e6cab..f9ed737 100755 --- a/test/MultiMotorThreading_BYJ.py +++ b/test/MultiMotorThreading_BYJ.py @@ -62,7 +62,7 @@ def button_callback(channel): print("START") main() - GPIO.cleanup() + GPIO.cleanup() # Optional print("END") exit() diff --git a/test/MultiMotorThreading_DRV8825.py b/test/MultiMotorThreading_DRV8825.py index 229ba91..c469edb 100755 --- a/test/MultiMotorThreading_DRV8825.py +++ b/test/MultiMotorThreading_DRV8825.py @@ -71,7 +71,7 @@ def button_callback(channel): print("START") main() - GPIO.cleanup() + GPIO.cleanup() # Optional print("END") exit() diff --git a/test/TB6612FNG_DCMot_Test.py b/test/TB6612FNG_DCMot_Test.py index c922d7c..c135d39 100755 --- a/test/TB6612FNG_DCMot_Test.py +++ b/test/TB6612FNG_DCMot_Test.py @@ -4,9 +4,16 @@ import time import RPi.GPIO as GPIO -#import sys -#sys.path.insert(0, '/home/pi/Documents/tech/RpiMotorLib/RpiMotorLib') -#import rpi_dc_lib + +""" +# Next 3 lines for development local library path testing import +# Comment out in production release and change rpi_dc_lib.TB6612FNGDc to TB6612FNGDc +import sys +sys.path.insert(0, '/home/pi/Documents/tech/RpiMotorLib/RpiMotorLib') +from rpi_dc_lib import TB6612FNGDc +""" + +# Production installed library import from RpiMotorLib import rpi_dc_lib # ====== tests for DC motor driven by TB6612FNG ==== @@ -176,7 +183,7 @@ def motorboth(): time.sleep(1) finally: rpi_dc_lib.TB6612FNGDc.standby(Standby, False) - GPIO.cleanup() + GPIO.cleanup() # optional exit() diff --git a/test/TB6612FNG_Nema_Test.py b/test/TB6612FNG_Nema_Test.py index 2a3b7c6..91b729d 100755 --- a/test/TB6612FNG_Nema_Test.py +++ b/test/TB6612FNG_Nema_Test.py @@ -117,7 +117,7 @@ def button_callback(channel): print("START") main() - GPIO.cleanup() + GPIO.cleanup() # Optional exit()