Exemplo n.º 1
0
def runMotor():
    # Motor 1 uses Pin 22, Pin 18, Pin 16
    motor1 = l293d.DC(22, 18, 16)
    # Run the motors so visible
    for i in range(0, 150):
        motor1.anticlockwise()

    l293d.cleanup()
Exemplo n.º 2
0
 def test_pins_string_list(self):
     """
     Test that the list of pins is returned correctly
     """
     import l293d as d
     print(d.pins_in_use)
     motor = d.DC(29, 7, 13)
     self.assertEqual(motor.pins_string_list(), '[29, 7 and 13]')
     reload(d.driver)
Exemplo n.º 3
0
 def test_motor_can_be_removed(self):
     """
     Test that a motor can be created and removed
     """
     import l293d as d
     original_pins = d.pins_in_use
     motor = d.DC(29, 7, 13)
     motor.remove()
     self.assertEqual(d.pins_in_use, original_pins)
     reload(d.driver)
Exemplo n.º 4
0
 def test_create_motor_with_force_selection(self):
     """
     Test DC class instance creation with explicity
     force_selection parameter
     """
     import l293d as d
     cases = (([33, 36, 37], False), ([19, 21, 23], True))
     for pins, force_selection in cases:
         motor = d.DC(*pins, force_selection=force_selection)
         self.assertEqual(d.pins_in_use, pins)
         motor.remove()
     reload(d.driver)
Exemplo n.º 5
0
def main():
    ''' main function'''

    # Motor 1 uses Pin 22, Pin 18, Pin 16
    motor = l293d.DC(22, 18, 16)
    motor.clockwise(duration=3, speed=25)

    # Run the motors so visible
    #for i in range(0,1500):
    #	motor.clockwise()

    l293d.cleanup()
Exemplo n.º 6
0
 def test_pin_numbering_lock(self):
     """"
     Test that pin_numbering can't be changed after a motor's definition
     """
     import l293d as d
     d.Config.set_pin_numbering('BcM')
     m1 = d.DC(4, 5, 6)
     error = 'No error'
     try:
         d.Config.set_pin_numbering('BoaRD')
     except ValueError as e:
         error = str(e)
     self.assertEqual(
         error, 'Pin numbering format cannot be changed '
         'if motors already exist. Set this at '
         'the start of your script.')
     m1.remove()
     reload(d.driver)
Exemplo n.º 7
0
#RIGHT SPEED 50
import l293d
import time

#m1 configuration
m1 = l293d.DC(11, 12, 13)
m2 = l293d.DC(15, 16, 18)
m3 = l293d.DC(22, 29, 31)
m4 = l293d.DC(32, 33, 36)

pwm = l293d.PWM(freq=30, cycle=30)

x = 1

while x == 1:
    m1.clockwise(speed=pwm)
    m2.clockwise(speed=pwm)
    m3.anticlockwise(speed=pwm)
    m4.clockwise(speed=pwm)
    time.sleep(1)
Exemplo n.º 8
0
IRsensor = 37

firebase = pyrebase.initialize_app(KEYS.config)
db = firebase.database()

GPIO.setmode(GPIO.BOARD)
GPIO.setup(IRsensor, GPIO.IN)


def isObstacle():
    return GPIO.input(IRsensor)


try:
    leftMotor = controller.DC(15, 13, 11)
    rightMotor = controller.DC(22, 16, 18)

    while True:
        if isObstacle():
            leftMotor.stop()
            rightMotor.stop()

        current = db.child("robot").child("action").get().val()

        if current == 'forward' and not isObstacle():
            leftMotor.anticlockwise(duration=1.5, wait=False)
            rightMotor.anticlockwise(duration=1.5, wait=False)
            db.child("robot").update({"action": "stop"})
        elif current == 'backward':
            leftMotor.clockwise(duration=1.5, wait=False)
Exemplo n.º 9
0
    GPIO.setup(pin_to_circuit, GPIO.OUT)
    GPIO.output(pin_to_circuit, GPIO.LOW)
    time.sleep(0.1)

    # Change the pin back to input
    GPIO.setup(pin_to_circuit, GPIO.IN)

    # Count until the pin goes high
    while (GPIO.input(pin_to_circuit) == GPIO.LOW):
        count += 1

    return count


try:
    motor = l293d.DC(22, 18, 16)
    while True:
        current = db.child("feeder").child("motor").get().val()
        if current == True:
            print("Feedr On...")
            motor.clockwise(duration=3)
            currentTime = datetime.datetime.fromtimestamp(
                time.time()).strftime('%Y-%m-%d %H:%M:%S')
            db.child("feedings").push(currentTime)
            db.child("feeder").update({"motor": False})
            if rc_time(7) < 2000:
                s.sendmail(INFO.senderEmail, INFO.recipientEmail, message)
                print("EMAIL SENT!")
        else:
            print("Feedr Off..")
        time.sleep(0.5)
Exemplo n.º 10
0
import l293d
import time

# Documentation for L239D chip - https://l293d.readthedocs.io/en/latest/user-guide/python-scripts/
# Parameters used in code - https://l293d.readthedocs.io/en/latest/methods/clockwise-anticlockwise/
# Hardware set up used - https://l293d.readthedocs.io/en/latest/user-guide/hardware-setup/
""" 
IMPORTANT NOTE TO SELF/OTHERS - Make sure GPIO pin numbers from Raspberry pi 
match up with diagram (order matters), as an incomplete connection could reverse
the polarity of the DC motors and possibly break the gears, not spin, or make 
the motors jitter and not move (reversed polarity)
"""
""" Code """
""" Sets motor 1 and motor 2 GPIO pins """
# Motor 1 uses Rpi pins 22, 18, 16
upDownMotor1 = l293d.DC(22, 18, 16)
# Motor 2 uses Rpi pins 15, 13, 11
upDownMotor2 = l293d.DC(15, 13, 11)
""" Sets motor 3 and motor 4 GPIO pins """
# Motor 3 uses Rpi pins 29, 31, 33
turnMotor = l293d.DC(32, 31, 29)
# Motor 4 uses Rpi pins 37, 36, 35
clawMotor = l293d.DC(37, 36, 33)
""" Used for arm control up and down"""


def up():
    """ 
    Function that makes the robotic arm go up.
    Arguments of duration (1.95) and speed (10) makes the VEX motor 269 
    turn 90 degrees when attached to a 6V power supply.
Exemplo n.º 11
0
import RPi.GPIO as GPIO
import l293d

try:
    motor1 = l293d.DC(22, 18, 16)
    motor2 = l293d.DC(15, 13, 7)
    GPIO.setmode(GPIO.BOARD)

    from evdev import InputDevice, categorize, ecodes

    # Use ls /dev/input to find the gamepad's event
    gamepad = InputDevice('/dev/input/event0')

    # Prints information about gamepad
    print(gamepad)

    # Might be useful to list the button codes here as variable
    aBtn = 289

    # Runs each time something happens
    for event in gamepad.read_loop():

        # Runs if we get a key pressed
        if event.type == ecodes.EV_KEY:
            print(event)

            # Runs if the key is PRESSED
            if event.value == 1:
                if event.code == aBtn:
                    print("The A button was pressed")
                    motor1.clockwise(speed=100)
Exemplo n.º 12
0
import l293d
from flask import Flask, render_template, request, copy_current_request_context
global xspeed
xspeed = int
app = Flask(__name__)

motorR = l293d.DC(18, 16, 12)
motorL = l293d.DC(13, 11, 7)


@app.route("/")
def index():
    return render_template('home.html')


@app.route("/Pikey")
def pikey():
    return render_template('Pikey.html')


@app.route("/Monitoren")
def monitoren():
    return render_template('Monitoring.html')


@app.route("/FastenYourSeatbelts")
def fastenyourseatbelts():
    return render_template('FastenYourSeatbelts.html')


@app.route("/MyRealMusic")
Exemplo n.º 13
0
# use Raspberry Pi board pin numbers
GPIO.setmode(GPIO.BOARD)

# set GPIO input and output channels
GPIO.setup(rc.pinTrigger, GPIO.OUT)
GPIO.setup(rc.pinEcho, GPIO.IN)
GPIO.setup(rc.sensor, GPIO.IN)

# setup Motor pins
l293d.Config.pin_numbering = 'BOARD'
cases = (([rc.Motor1E, rc.Motor1A,
           rc.Motor1B], True), ([rc.Motor2E, rc.Motor2A, rc.Motor2B], True))
motors = []
for pins, force_selection in cases:
    motors.append(l293d.DC(*pins, force_selection=force_selection))

motor1 = motors[0]
motor2 = motors[1]


def close():
    logging.info("\nMain    : Turning off sensors and motors...\n")
    GPIO.cleanup()
    l293d.cleanup()
    sys.exit(0)


signal.signal(signal.SIGINT, close)