Example #1
0
    def __init__(self,
                 serial_port,
                 baud_rate=115200,
                 parity="E",
                 gpio_reset_pin=int(18),
                 gpio_boot0_pin=int(17)):
        """Construct a SerialConnectionRpi (not yet connected)."""
        self.serial_port = serial_port
        self.baud_rate = baud_rate
        self.parity = parity
        self.can_toggle_reset = True
        self.can_toggle_boot0 = True
        self.reset_active_high = False
        self.boot0_active_low = False

        # call connect() to establish connection
        self.serial_connection = None

        self._timeout = 5
        self._gpio_reset_pin = gpio_reset_pin
        self._gpio_boot0_pin = gpio_boot0_pin

        try:
            from periphery import GPIO
        except ImportError as e:
            print(
                "Couldn't import periphery.GPIO. Check if the periphery is installed on your system"
            )
            exit(1)
        self._reset = GPIO(self._gpio_reset_pin, "out")
        self._boot0 = GPIO(self._gpio_boot0_pin, "out")
Example #2
0
def data_in_out():
    for q in GPIO(20):
        if y == "IN":                                       # If we have a pin that is an active input
            GPIO.output(p) = "actuator_input"
            q += 1                                          # Increment q past pin for we dont need to send it's data
        else
            pi_pin[q] = GPIO(q)                             # Store GPIO values to array and send to global storage
    return pi_pin[20]
Example #3
0
def pickUpCard():
	# Swivelhead over
	#TODO: These values WILL NEED TO BE CHECKED
	GPIO.output(15, GPIO.HIGH)

	while (not GPIO.input(36)):
		GPIO.output(13, GPIO.HIGH)
		sleep(0.015)
		GPIO.output(13, GPIO.LOW)
		sleep(0.015)

	# Check if Uno is done setting the buckets
	done = i2cComms.readNumber()
	while (not done):
		sleep(0.5)
		done = i2cComms.readNumber()

	# Send vacuuming command
	i2cComms.writeNumber(8)

	curPressure = pressure.pressure()
	while (curPressure < SOME VALUE):
		pass

	# Bring swivelhead back
	GPIO.output(15, GPIO.LOW)

	while (not GPIO(input(38))):
		GPIO.output(13, GPIO.HIGH)
		sleep(0.015)
		GPIO.output(13, GPIO.LOW)
		sleep(0.015)

	# Tell Uno to drop the card
	i2cComms.writeNumber(8)
Example #4
0
 def __init__(self, **kw):
     tk.Frame.__init__(self, **kw)
     GPIO.setmode(GPIO.BCM)
     self.ports = []
     ## Get the RPI Hardware dependant list of GPIO
     gpio = self.getRPIVersionGPIO()
     for num, (p, r, c) in enumerate(gpio):
         self.ports.append(GPIO(self, pin=p))
         self.ports[-1].grid(row=r, column=c)
     self.update()
Example #5
0
    def __init__(self,
                 serial_port,
                 baud_rate=115200,
                 parity="E",
                 gpio_reset_pin=int(18),
                 gpio_boot0_pin=int(17)):
        """Construct a SerialConnectionRpi (not yet connected)."""
        self.serial_port = serial_port
        self.baud_rate = baud_rate
        self.parity = parity
        self.can_toggle_reset = True
        self.can_toggle_boot0 = True
        self.reset_active_high = False
        self.boot0_active_low = False
        self.GPIO_DEV = '/dev/gpiochip4'

        # call connect() to establish connection
        self.serial_connection = None

        self._timeout = 5
        self._gpio_reset_pin = gpio_reset_pin
        self._gpio_boot0_pin = gpio_boot0_pin

        try:
            from periphery import GPIO
        except ImportError:
            print(
                "Couldn't import periphery.GPIO. Check if the periphery is installed on your system",
                file=sys.stderr)
            exit(1)
        try:
            self._reset = GPIO(self._gpio_reset_pin, "out")
            self._boot0 = GPIO(self._gpio_boot0_pin, "out")
        except IOError:
            print(
                "Couldn't initialise the periphery.GPIO instances. Try use the script with sudo.",
                file=sys.stderr)
            exit(1)
Example #6
0
def test1():
    """demo """
    lcd = NJU6450(122, 32, GPIO())

    drv = HD44780(lcd, True)
    print(drv.width, drv.height)
    lcd = CharLCD(drv.width, drv.height, drv, 0, 0)
    lcd.init()
    lcd.write('First Line')
    lcd.write(' it is not', 0, 0)

    lcd.write('HD44780', 6, 3)
    lcd.flush()
    lcd.write('/* ', 12, 0)
    lcd.write('|*|', 12, 1)
    lcd.write(' */', 12, 2)
    lcd.flush()
Example #7
0
def setup():
    global adc
    if (adc.detectI2C(0x48)): # If pcf8591.
        adc = PCF8591()
    elif (adc.detectI2C(0x4b)): # If ads7830.
        adc = ADS7830()
    else:
        print("No correct I2C address found, \n"
               "Use command 'i2cdetect -y 1' to check I2C address")
        exit(-1)

    global p
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(motorPin1, GPIO.OUT)
    GPIO.setup(motorPin2, GPIO.OUT)
    GPIO.setup(enablePin, GPIO.OUT)
    p = GPIO(enablePin, 1000)
    p.start(0)
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
TRIG = 23
ECHO = 24
GPIO.setup(TRIG, GPIO.OUT)
GPIO.setup(TRIG, GPIO.IN)
GPIO(TRIG, False)
time.sleep(2)
GPIO.output(TRIG, True)
time.sleep(0.00001)
GPIO.output(TRIG, False)

while GPIO.input(ECHO) == 0:
    pulse_start = time.time()
while GPIO.input(ECHO) == 1:
    pulse_end = time.time()
pulse_duration = pulse_end - pulse_start
distance = round(distance, 2)
print("Distance:  " + str(distance) + " cm.")
GPIO.cleanup()
Example #9
0
def button_callback(channel):
    print("Button was pushed!")
    GPIO(18, True)
    sleep(2)
    GPIO(18, False)
Example #10
0
    # GPIOを ローにします、とは。
    def ローにします(self):
        if self.mode == RPi.GPIO.IN:
            self.mode = RPi.GPIO.OUT
            RPi.GPIO.setup(self.pin, self.mode)
        RPi.GPIO.output(self.pin, RPi.GPIO.LOW)

    # GPIOが ハイです、とは。
    def ハイです(self):
        if self.mode == RPi.GPIO.OUT:
            self.mode = RPi.GPIO.IN
            RPi.GPIO.setup(self.pin, self.mode)
        return RPi.GPIO.input(self.pin) == RPi.GPIO.HIGH


GPIO1 = GPIO(34)
GPIO2 = GPIO(35)
GPIO3 = GPIO(36)


class ライト:
    def default(self):
        if ひと.います():
            self.スイッチ.いれます()
        else:
            self.スイッチ.きります()


class スイッチ:
    def いれます(self):
        self.GPIO.ハイにします()
Example #11
0
from datetime import datetime
import RPi.GPIO as GPIO
from time import sleep

GPIO.setmode(GPIO.BCM)

buzzer_pin = 24
led_pin = 18
GPIO.setup(24, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)
camera = PiCamera()
pir = MotionSensor(4)

while True:
    pir.wait_for_motion()
    filename = datetime.now().strftime("%Y-%m-%d_%H.%M.%S.h264")
    camera.capture("/home/pi/Desktop/image.jpg")
    camera.start_recording(filename)
    GPIO.output(buzzer_pin, True)
    GPIO.output(led_pin, True)
    sleep(1)
    GPIO(1)
    GPIO.output(buzzer_pin, False)
    pir.wait_for_no_motion()
    GPIO.output(led_pin, True)
    GPIO.output(buzzer_pin, True)
    sleep(1)
    GPIO.output(buzzer_pin, False)
    camera.stop_recording()

Example #12
0
import RPi.GPIO as GPIO
import time

GPIO.setwarnings(False)
GPIO.setmode

while True:
    (error, tag_type) = GPIO.request()
    if not error:
        print("Tag detected")
        (error, uid) = GPIO.anticoll()
        if not error:
            print("UID: " + GPIO(uid))
            # Select Tag is required before Auth
            if not GPIO.select_tag(uid):
                # Auth for block 10 (block 2 of sector 2) using default shipping key A
                if not GPIO.card_auth(GPIO.auth_a, 10,
                                      [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
                                      uid):
                    # This will print something like (False, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
                    print("Reading block 10: " + GPIO(GPIO.read(10)))
                    # Always stop crypto1 when done working
                    GPIO.stop_crypto()

# Calls GPIO cleanup
GPIO.cleanup()
Example #13
0
import RPi.GPIO as GPIO
from keypad.MatrixKeypad import MatrixKeypad

key_map = [[1, 2, 3, "A"], [4, 5, 6, "B"], [7, 8, 9, "C"], ["*", 0, "#", "D"]]
gpio_pins_for_rows = [29, 31, 33, 35]
gpio_pins_for_columns = [37, 36, 38, 40]
key_matrix = MatrixKeypad(key_map, gpio_pins_for_rows, gpio_pins_for_columns,
                          GPIO())

if __name__ == '__main__':
    while True:
        key = key_matrix.get_key()

        if key == "B":
            break
def beep():
    GPIO(17,GPIO.LOW)
    time.sleep(0.5)
    GPIO(17.GPIO.HIGH)
    time.sleep(0.5)
Example #15
0
import RPi.GPIO
import sys
from PIL import Image
sys.path.append("../../")
from gfxlcd.driver.nju6450.gpio import GPIO
from gfxlcd.driver.nju6450.nju6450 import NJU6450
RPi.GPIO.setmode(RPi.GPIO.BCM)

lcd_nju = NJU6450(122, 32, GPIO())
lcd_nju.rotation = 90
lcd_nju.init()
lcd_nju.auto_flush = False

image_file = Image.open("assets/20x20.png")
lcd_nju.threshold = 0

lcd_nju.draw_image(10, 0, image_file)

lcd_nju.flush(True)
Example #16
0
 def setEnableLedFlag(self, enable):
     GPIO(17, GPIO.LOW)
     self.enableLed = enable
Example #17
0
TRIG = 17
ECHO = 27

led = 26

m1a = 23
m1b = 24
m2a = 25
m2b = 8

GPIO.setup(TRIG, GPIO.OUT)
GPIO.setup(ECHO, GPIO.IN)
GPIO.setup(led, GPIO.OUT)

GPIO(m1a, GPIO.OUT)
GPIO(m1b, GPIO.OUT)
GPIO(m2a, GPIO.OUT)
GPIO(m2b, GPIO.OUT)

time.sleep(5)


def stop():
    GPIO.output(m1a, 0)
    GPIO.output(m1b, 0)
    GPIO.output(m2a, 0)
    GPIO.output(m2b, 0)


def forward():
Example #18
0
from array import array
import RPi.GPIO as GPIO

pi_pin = array(20)                                          # For however many local sensors; this sample uses 20

GPIO.setmode(GPIO.BOARD)

for x, y in GPIO(20):                                       # Pin Initialization
    if y == "OUT":                                          # Example of 2 output pins
        GPIO.setup(x, GPIO.y, pull_up_down=GPIO.PUD_DOWN)   # Output active operating @ 3.3V
        GPIO.output(x)
    if y == "IN":
        GPIO.setup(x, GPIO.y)
        GPIO.input(x, GPIO.HIGH)                            # Input active operating @ 3.3V

def data_in_out():
    for q in GPIO(20):
        if y == "IN":                                       # If we have a pin that is an active input
            GPIO.output(p) = "actuator_input"
            q += 1                                          # Increment q past pin for we dont need to send it's data
        else
            pi_pin[q] = GPIO(q)                             # Store GPIO values to array and send to global storage
    return pi_pin[20]

def globalstorage():
    data_in_out()
    return
Example #19
0
import RPi.GPIO
import sys
from PIL import Image
sys.path.append("../../")
from gfxlcd.driver.nju6450.gpio import GPIO
from gfxlcd.driver.nju6450.nju6450 import NJU6450
RPi.GPIO.setmode(RPi.GPIO.BCM)

lcd = NJU6450(122, 32, GPIO())
lcd.rotation = 0
lcd.init()
lcd.auto_flush = False

lcd.draw_text(25, 1, "Star Wars")
lcd.draw_text(30, 10, "Death Star")

image_file = Image.open("assets/20x20.png")
lcd.threshold = 0

lcd.draw_image(0, 0, image_file)

lcd.flush(True)
Example #20
0
 def __init__(self):
     self.pin=18
     self.mode=1 #open is 1 close is 0
     self.mgpio=GPIO()
     self.mgpio.setPinMode(pin=self.pin,mode=1) #OUTPUT 1 INPUT 0
Example #21
0
def servoControl(angle, pinNum):
    pwm = GPIO(pinNum, 50)
    slope = (1 / 18)  #need to adjust slope based on calibration of our motor
    constant = 2  #constant will also need to be calibrated
    dutyCycle = slope * angle - constant
    pwm.ChangeDutyCycle(dutyCycle)
Example #22
0
 def __init__(self, binding, handler, context, index):
     BaseHTTPServer.HTTPServer.__init__(self, binding, handler)
     self.context = context
     self.index = index
     self.gpio = GPIO()
Example #23
0
from .transport import discover_port
import time
import serial
from serial.tools.list_ports import comports
try:
    import RPi.GPIO as GPIO
except Exception:
    # Fake GPIO
    class GPIO:
        def fake(self, *args, **kwargs):
            pass

        def __getattr__(self, *args, **kwargs):
            return self.fake

    GPIO = GPIO()
import usb

logger = logging.getLogger('ZiGate Flasher')
_responses = {}

ZIGATE_CHIP_ID = 0x10408686
ZIGATE_BINARY_VERSION = bytes.fromhex('07030008')
ZIGATE_FLASH_START = 0x00000000
ZIGATE_FLASH_END = 0x00040000


class Command:
    def __init__(self, type_, fmt=None, raw=False):
        assert not (raw and
                    fmt), 'Raw commands cannot use built-in struct formatting'
Example #24
0
def button_callback(channel):
    print("Button iwas pushed!")
    GPIO(SOLENOID_PIN,TRUE)
    sleep(20)
    GPIO(SOLENOID_PIN,False)