Skip to content

Commit

Permalink
version 3.2-3
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinlyonsrepo committed Oct 16, 2022
1 parent bce8a19 commit a0836ee
Show file tree
Hide file tree
Showing 26 changed files with 89 additions and 66 deletions.
4 changes: 1 addition & 3 deletions Documentation/28BYJ.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Documentation/DRV8833_DC.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Documentation/L298N_DC.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def motorone():
print("No errors")
finally:
print("cleaning up")
MotorOne.cleanup(True)
MotorOne.cleanup(False)

if __name__ == '__main__':
motorone()
Expand Down
4 changes: 2 additions & 2 deletions Documentation/L9110S_DC.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions Documentation/Nema11A3967Easy.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()

```
2 changes: 0 additions & 2 deletions Documentation/Nema11A4988.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()

```
3 changes: 0 additions & 3 deletions Documentation/Nema11DRV8825.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()

```
2 changes: 0 additions & 2 deletions Documentation/Nema11L298N.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions Documentation/changelog/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

File renamed without changes.
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
--------------------------------------------------
Expand All @@ -17,7 +18,7 @@ Table of contents
* [Files](#files)
* [Dependencies](#dependencies)
* [Components](#components)
* [Notes](#notes)
* [Notes and Issues](#notes-and-issues)

Overview
--------------------------------------------
Expand All @@ -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
Expand Down Expand Up @@ -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**
Expand All @@ -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.
12 changes: 9 additions & 3 deletions RpiMotorLib/RpiMotorLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand All @@ -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."""
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions RpiMotorLib/RpiMotorScriptLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
# display the version and help for Rpi package RpiMotorlib
# author :Gavin Lyons
# web :https://github.com/gavinlyonsrepo/RpiMotorLib
# mail :[email protected]
# python_version :3.5.3
# python_version :3.7.3
"""

# ==========================IMPORTS======================
# Import the system module needed to run rpiMotorScriptLib.py
import argparse
import sys

__version__ = "3.1-2"
__version__ = "3.2-3"
__author__ = "Gavin Lyons"
__url__ = "https://github.com/gavinlyonsrepo/RpiMotorLib"

Expand Down
8 changes: 5 additions & 3 deletions RpiMotorLib/rpi_dc_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
author :Gavin Lyons
web :https://github.com/gavinlyonsrepo/RpiMotorLib
mail :[email protected]
python_version :3.5.3
python_version :3.7.3
"""

# ========================== IMPORTS ======================
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down
3 changes: 1 addition & 2 deletions RpiMotorLib/rpiservolib.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
# This file is for servos controlled by GPIO PWM
# author :Gavin Lyons
# web :https://github.com/gavinlyonsrepo/RpiMotorLib
# mail :[email protected]
# python_version :3.4.2
# python_version :3.7.3
"""
# ========================== IMPORTS ======================
# Import the system modules needed to run rpiMotorlib.py
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="rpimotorlib",
version="3.1",
version="3.2",
author="Gavin Lyons",
author_email="[email protected]",
description="A python 3 library for various motors and servos to connect to a raspberry pi",
Expand All @@ -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)",
],
)
8 changes: 4 additions & 4 deletions test/BYJ_Motor_Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,22 @@
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():
"""main function loop"""

# ====== 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
Expand Down Expand Up @@ -68,9 +69,8 @@ def button_callback(channel):

print("START")
main()
GPIO.cleanup()
GPIO.cleanup() # Optional
exit()



# =====================END===============================
2 changes: 1 addition & 1 deletion test/DRV8825_Nema_Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def button_callback(channel):

print("TEST START")
main()
GPIO.cleanup()
GPIO.cleanup() # Optional
print("TEST END")
exit()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -131,7 +135,7 @@ def motortwo():
print(error)
print("Unexpected error:")
finally:
MotorTwo.cleanup(True)
MotorTwo.cleanup(False)

# ===================MAIN===============================

Expand Down
Loading

0 comments on commit a0836ee

Please sign in to comment.