Exemplo n.º 1
0
#print GPIO.RPI_REVISION
print("\nNPi.GPIO version:")
print(GPIO.VERSION)

time.sleep(1)

while True:
    try:
        pin = int(
            input(
                'Choose board pin number: \n( 3 - 24; excluded: 4, 6, 9, 14, 17, 20 )\n'
            ))
        mode = int(
            input('Choose pin state: \n( 0 - Low, 1 - High, 2 - Quit )\n'))
        print("\n\nChoosen %d (state %s)\n" % (mode, v_modes_str[mode]))
        GPIO.setup(pin, GPIO.OUT)
        GPIO.output(pin, mode)
        time.sleep(0.5)
        print("Pin state changed!\n")
        #GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_OFF)
        time.sleep(0.5)
        print("Now pin %d state is: %s\n" %
              (pin, v_modes_str[GPIO.input(pin)]))
        time.sleep(3)
    except ValueError:
        print("Not a number")
        continue
    except IndexError:
        if mode == 2:
            GPIO.cleanup()
            print("Bye :-(\n")
Exemplo n.º 2
0
from __future__ import print_function
import NPi.GPIO as GPIO
import time

PIN_NUM = 12
GPIO.setmode(GPIO.BOARD)
GPIO.setup(PIN_NUM, GPIO.IN, GPIO.PUD_DOWN)

print("The value of Pin %d is %d" % (PIN_NUM, GPIO.input(PIN_NUM)))


def my_callback(channel):
    print("Callback trigger %d" % channel)
    print("Now value of the Pin is %d" % (GPIO.input(PIN_NUM)))
    print("Click Ctr + C to exit")


GPIO.add_event_detect(PIN_NUM,
                      GPIO.RISING,
                      callback=my_callback,
                      bouncetime=300)

try:
    while True:
        time.sleep(0.1)
except KeyboardInterrupt:
    pass

GPIO.cleanup()
Exemplo n.º 3
0
def setupGPIO():
    GPIO.setwarnings(False)  # Ignore warning for now
    GPIO.setmode(GPIO.BOARD)  # Use physical pin numbering
    GPIO.setup(PIN_BTN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    return ()
Exemplo n.º 4
0
def modetype(mode):
    for pin in range(range_pins[0], range_pins[1] + 1):
        if not pin in inv_pins:
            GPIO.setup(pin, GPIO.IN, pull_up_down=mode)
            print("value_%d = %d" % (pin, GPIO.input(pin)))
            time.sleep(0.1)
Exemplo n.º 5
0
#!/usr/bin/env python
from __future__ import print_function
import NPi.GPIO as GPIO
import time
from threading import Timer

PIN_NUM = 12
channel = 7
GPIO.setmode(GPIO.BOARD)
GPIO.setup(PIN_NUM,GPIO.OUT)

GPIO.output(PIN_NUM,True)
print("\n value_%d = %d\n" %(PIN_NUM,GPIO.input(PIN_NUM)))

GPIO.setup(channel,GPIO.IN,GPIO.PUD_DOWN)
print("\n value_%d = %d\n" %(channel,GPIO.input(channel)))


def makehigh():
    print("\n value_%d = %d\n" %(channel,GPIO.input(channel)))
    GPIO.output(PIN_NUM,False)
    print("\n value_%d = %d\n" %(PIN_NUM,GPIO.input(PIN_NUM)))
    
    
GPIO.wait_for_edge(channel, GPIO.RISING)
t = Timer(1,makehigh)
t.start()
Exemplo n.º 6
0
from __future__ import print_function
import NPi.GPIO as GPIO

validPins = [11,12,13,15]

GPIO.setmode(GPIO.BOARD)

GPIO.setup(11,GPIO.IN)
GPIO.setup(12,GPIO.OUT)
GPIO.setup(13,GPIO.IN)
GPIO.setup(15,GPIO.OUT)

for pin in validPins:
    fun = GPIO.gpio_function(pin)
    print(fun)
Exemplo n.º 7
0
import NPi.GPIO as GPIO
import time

PIN_NUM = 12
GPIO.setmode(GPIO.BOARD)
GPIO.setup(PIN_NUM, GPIO.OUT)

frequency = 50
p = GPIO.PWM(PIN_NUM, frequency)
p.start(0)

try:
    while True:
        for dutyCycle in range(0, 100, 5):
            p.ChangeDutyCycle(dutyCycle)
            time.sleep(0.1)
        for dutyCycle in range(100, 0, -5):
            p.ChangeDutyCycle(dutyCycle)
            time.sleep(0.1)
except KeyboardInterrupt:
    pass

p.stop()
GPIO.cleanup()
Exemplo n.º 8
0
#!/usr/bin/env python
from __future__ import print_function
import NPi.GPIO as GPIO
import time
from threading import Timer

SWITCH_PIN = 10
GPIO.setmode(GPIO.BOARD)
GPIO.setup(SWITCH_PIN, GPIO.IN, GPIO.PUD_DOWN)
print("\n value_%d = %d\n" % (SWITCH_PIN, GPIO.input(SWITCH_PIN)))

GPIO.add_event_detect(SWITCH_PIN, GPIO.RISING,
                      bouncetime=200)  # add rising edge detection on a channel

switchcount = 0
while switchcount < 2:
    if GPIO.event_detected(SWITCH_PIN):
        switchcount += 1
        print('Button pressed', switchcount)
        print("\n value_%d = %d\n" % (SWITCH_PIN, GPIO.input(SWITCH_PIN)))

GPIO.remove_event_detect(SWITCH_PIN)
Exemplo n.º 9
0
#!/usr/bin/env python
from __future__ import print_function
import NPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.IN, pull_up_down=GPIO.PUD_UP)
print("\n value_7 = %d\n" % (GPIO.input(7)))

GPIO.setup(8, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
print("\n value_8 = %d\n" % (GPIO.input(8)))

GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_UP)
print("\n value_12 = %d\n" % (GPIO.input(12)))
GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
print("\n value_12 = %d\n" % (GPIO.input(12)))

#GPIO.cleanup()
Exemplo n.º 10
0
import NPi.GPIO as GPIO
import time

channel = 7

GPIO.setmode(GPIO.BOARD)
GPIO.setup(channel, GPIO.IN, GPIO.PUD_DOWN)
print(" Now input is Low\n Our task is performed when it becomes High")

while True:
    if GPIO.input(channel):
        print("Input was High,begin to perform")
        print("Count Down")
        for i in range(7, 0, -1):
            print("%d" % i)
            time.sleep(1)
        print("Performed!")
        exit()
Exemplo n.º 11
0
# PATH File
fileAip = '/media/AIP/Cut-01.csv'
fileCut = '/media/CuttingMachine/'

# Config Mount I/O to Windows
cutDrive = 'sudo mount.cifs //PathCutting/data /media/AIP -o rw,uid=pi,password=eseuser'
aipDrive = 'sudo mount.cifs //PathAIP/data /nedia/AIP -o rw,uid=pi,password=eseuser'

# Config CSV
mt = 'MT'
yd = 'YD'
header =  [yd,mt]

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

reader = csv.reader(open("csvfile.csv"), delimiter=";")
included_cols = [22]
count = 0
content = []

def openFile():
    # os.system(cutDrive)
    now = datetime.now()  # current date and time
    nowdate = now.strftime("%Y%m%d")
    fileReport = 'Reporting_' + nowdate + '-Job.csv'
    while (os.path.ismount('/media/AIP') == False):
        os.system(cutDrive)
    try:
        reader = csv.reader(open(fileCut+fileReport), delimiter=";")