Ejemplo n.º 1
0
 def __init__(self, MotorE, MotorA, MotorB, servo_pin, trigger, echo,green,yellow,red,distance_timer):
     
     GPIO.setwarnings(False)
     
     self.distance_timer = distance_timer
     
     self.dcmotor = DCMotor(MotorE, MotorA, MotorB)
     self.servomotor = ServoMotor(servo_pin)
     self.distancesensor = DistanceSensor(trigger,echo)
     
     self.green = green
     self.yellow = yellow
     self.red = red
     
     GPIO.setup(self.green,GPIO.OUT)
     GPIO.setup(self.yellow,GPIO.OUT)
     GPIO.setup(self.red,GPIO.OUT)
Ejemplo n.º 2
0
# Complete project details at https://RandomNerdTutorials.com

from dcmotor import DCMotor
from machine import Pin, PWM
from time import sleep

frequency = 15000

pin1 = Pin(12, Pin.OUT)
pin2 = Pin(14, Pin.OUT)
enable = PWM(Pin(13), frequency)

dc_motor = DCMotor(pin1, pin2, enable, 350, 1023)

dc_motor.forward(50)
sleep(2)
dc_motor.stop()
sleep(3)
dc_motor.backwards(100)
sleep(2)
dc_motor.forward(5)
sleep(5)
dc_motor.stop()
Ejemplo n.º 3
0
# Complete project details at https://RandomNerdTutorials.com

from dcmotor import DCMotor
from machine import Pin, PWM
from time import sleep

frequency = 15000

pin1 = Pin(12, Pin.OUT)
pin2 = Pin(14, Pin.OUT)
enable = PWM(Pin(13), frequency)

dc_motor = DCMotor(pin1, pin2, enable)
#Set min duty cycle (350) and max duty cycle (1023)
#dc_motor = DCMotor(pin1, pin2, enable, 350, 1023)

dc_motor.forward(50)
sleep(2)
dc_motor.stop()
sleep(3)
dc_motor.backwards(100)
sleep(2)
dc_motor.forward(5)
sleep(5)
dc_motor.stop()
Ejemplo n.º 4
0
frequency = 15000

"""
#define ENAR   14         --> Enable/speed motors Right        GPIO14(D5)
#define ENBL   12         --> Enable/speed motors Left         GPIO12(D6)
#define pin1  15          --> L298N in1 motors Right           GPIO15(D8)
#define pin2  13          --> L298N in2 motors Right           GPIO13(D7)
#define pin3  2           --> L298N in3 motors Left            GPIO2(D4)
#define pin4  0           --> L298N in4 motors Left            GPIO0(D3)
"""

pin1 = Pin(15, Pin.OUT)
pin2 = Pin(13, Pin.OUT)
enableFB = PWM(Pin(14), frequency)
dc_motorFB = DCMotor(pin1, pin2, enableFB, 350, 1023)

enableRL = PWM(Pin(12), frequency)
pin3 = Pin(2, Pin.OUT)
pin4 = Pin(0, Pin.OUT)
dc_motorRL = DCMotor(pin3, pin4, enableRL, 350, 1023)


def cont(y, x, s):
    print('h,v,s=', y, x, s)
    r = 1023 / (2 ** .5)

    if (-r < x and x < r and y > 0):  # forward
        dc_motorFB.forward(s)
        dc_motorRL.stop()
        print("forword")
Ejemplo n.º 5
0
 def __init__(self, pinVelL, pinDirL, pinVelD, pinDirD):
     self.name = 'L9110URA'
     self.motorLeft = DCMotor(pinVelL, pinDirL)
     self.motorRight = DCMotor(pinVelD, pinDirD)
Ejemplo n.º 6
0
from dcmotor import DCMotor
from time import sleep

motor = DCMotor(20, 21, pwmPin=16)

motor.forward(0.2)
sleep(1)
motor.backward(0.2)
sleep(1)
motor.stop()


Ejemplo n.º 7
0
    import socket

import gc

from dcmotor import DCMotor
from machine import Pin, Signal, PWM

gc.collect()

ledLight = Signal(Pin(2, Pin.OUT), invert=True)  # GPIO2 ( D4 )
ledLight.on()
pwmFrequency = 500
enablePin = PWM(Pin(4), pwmFrequency)  # GPIO4 ( D2 )
pin1 = Pin(5, Pin.OUT)  # GPIO5 ( D1 )
pin2 = Pin(14, Pin.OUT)  # GPIO14 ( D5 )
dcMotorA = DCMotor(pin1, pin2, enablePin)

pin3 = Pin(12, Pin.OUT)  # GPIO12 ( D6 )
pin4 = Pin(13, Pin.OUT)  # GPIO13 ( D7 )
dcMotorB = DCMotor(pin3, pin4, enablePin)

forwardSpeed = 100
backwardSpeed = 80


def web_page():
    html = """
<html>
<head>
    <style>
        html {
Ejemplo n.º 8
0
#!/usr/bin/env python3
# REF: https://www.electronicshub.org

from dcmotor import DCMotor

G_LOW_SPEED = 4
G_MEDIUM_SPEED = 7
G_HIGH_SPEED = 10

dcMotorA = DCMotor(17, 27)  # GPIO17, GPIO27


def printCmdTips():
    print('\nPlease enter the following cmd to continue ↓')
    print('f: Run forward, b: Run backward, h: High speed, s: Stop\n')


def go():
    printCmdTips()
    while True:
        x = input()
        try:
            if x == 'f':
                dcMotorA.runForward(G_MEDIUM_SPEED)
            elif x == 'b':
                dcMotorA.runBackward(G_LOW_SPEED)
            elif x == 'h':
                dcMotorA.runForward(G_HIGH_SPEED)
            elif x == 's':
                dcMotorA.stop()
            else:
Ejemplo n.º 9
0
def main():
    gc.collect()

    ledLight = Signal(Pin(2, Pin.OUT), invert=False)  # GPIO2 ( D2 )
    sleep(0.1)
    ledLight.on()
    dcMotorA = DCMotor(4, 5)  # GPIO4 ( D4 ), GPIO5 ( D5 )
    sleep(0.1)
    dcMotorA.stop()
    servoB = CServo(15)  # GPIO15 ( D15 )

    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.bind(('', 80))
    sock.listen(5)
    while True:
        try:
            if gc.mem_free() < G_GC_THRESHOLD:
                gc.collect()
            conn, addr = sock.accept()
            conn.settimeout(3.0)
            print('Received HTTP GET connection request from %s' % str(addr))
            request = conn.recv(1024)
            conn.settimeout(None)
            request = str(request)
            print('GET Rquest Content = %s' % request)
            car_direction = request.find('/?car_direction')
            turn_left = request.find('/?turn_left')
            car_forward = request.find('/?car_forward')
            turn_right = request.find('/?turn_right')
            speed_up = request.find('/?speed_up')
            car_stop = request.find('/?car_stop')
            slow_down = request.find('/?slow_down')
            car_backward = request.find('/?car_backward')
            if car_direction == G_CMD_IDX:
                endIdx = request.find(' HTTP/')
                subReq = request[G_CMD_IDX:endIdx]
                startIdx = subReq.find('=') + 1
                virtualAngle = int(subReq[startIdx:])
                print('cmd: car_direction, virtualAngle =', virtualAngle)
                ledLight.on()
                servoB.carDirection(virtualAngle)
            elif turn_left == G_CMD_IDX:
                print('cmd: turn_left')
                ledLight.on()
                servoB.turnLeft()
            elif car_forward == G_CMD_IDX:
                print('cmd: car_forward')
                ledLight.on()
                dcMotorA.forward(G_FORWARD_SPEED)
            elif turn_right == G_CMD_IDX:
                print('cmd: turn_right')
                ledLight.on()
                servoB.turnRight()
            elif speed_up == G_CMD_IDX:
                print('cmd: speed_up')
                ledLight.on()
                dcMotorA.speedUp()
            elif car_stop == G_CMD_IDX:
                print('cmd: car_stop')
                ledLight.off()
                dcMotorA.stop()
            elif slow_down == G_CMD_IDX:
                print('cmd: slow_down')
                ledLight.on()
                dcMotorA.slowDown()
            elif car_backward == G_CMD_IDX:
                print('cmd: car_backward')
                ledLight.on()
                dcMotorA.backward(G_BACKWARD_SPEED)
            resHtml = getWebPage()
            conn.send('HTTP/1.1 200 OK\n')
            conn.send('Content-Type: text/html\n')
            conn.send('Connection: closed.\n\n')
            conn.sendall(resHtml)
            conn.close()
        except OSError as e:
            conn.close()
            print('Connection closed. OSError =', e)