Example #1
0
def gpio_init():
    GPIO.setboard(GPIO.PCPCPLUS)
    GPIO.setmode(GPIO.BOARD)
    # 这个接口接到LED的正极,LED的负极接到GND即可
    GPIO.setup(16, GPIO.OUT)
    GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    print("GPIO init success!")
Example #2
0
    def __init__(self):

        self.volume = 1
        self.preMuteVolume = self.volume
        self.button = 0
        self.last_screen_update = time.time()
        self.cast = False

        print('Trying to get handle to Chromecast ' + config.chromecasts[0] + '...')
        try:
            self.get_cast_handle(config.chromecasts[0])
        except cat_api.CastError as error:
            logging.error(logging.exception(error))
            sys.exit("ERROR: Couldn't connect to '" + config.chromecasts[0] + "'. Check config.py and name/IP.")

        if config.use_display:
            print('Trying to initialize screen on default i2c bus...')
            try:
                self.screen = Oled();
                self.show(';)')
                sleep(.5)
            except Exception as error:
                logging.error(logging.exception(error))
                sys.exit('ERROR Could not access screen: ' + str(error))

        if config.board_type == 'orange':
            GPIO.setboard(GPIO.ZERO)  # for orange pi zero
            GPIO.setmode(GPIO.BOARD)  # for orange pi zero
        if config.board_type == 'raspberry':
            GPIO.setmode(GPIO.BCM)  # for rasbpian on raspberry pi
        GPIO.setup(config.clk, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
        GPIO.setup(config.dt, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
        GPIO.setup(config.sw, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
        GPIO.add_event_detect(config.sw, GPIO.FALLING, callback=self.toggleMute, bouncetime=500)
    def __init__(self):

        # Distances in mm that each step of the stepper motor propels each axis
        self.mm_per_step = {'x': 0.000523, 'y': 0.000523, 'z': 0.000523}

        # This value will be used as speed for the 'rapid movement' of the machine
        # Measured in steps per second
        self.rapid_speed_maximum = 150.0

        # This value will be used as the fastest to move the machine when mill is lowered
        # Measured in steps per second
        self.work_speed_maximum = 150.0

        # These are the pins to control the L293D motor drivers for the CNC
        # in the order they are activated
        self.control_pins = {'x': (35, 31, 37, 33), 'y': (38, 32, 40, 36)}
        # 'z': (23, 27, 17, 22)}

        # Tracks how many steps have been taken on each axis at any point
        self.current_steps = {'x': 0, 'y': 0, 'z': 0}

        # Configure pinout options
        GPIO.setboard(GPIO.PCPCPLUS)
        GPIO.setmode(GPIO.BOARD)

        # Setup motor control pins
        for pins in self.control_pins.values():
            for pin in pins:
                GPIO.setup(pin, GPIO.OUT)
Example #4
0
 def __init__(self, dev='/dev/spidev0.0', spd=1000000):
     global spidev
     spidev = spi.openSPI(device=dev, speed=spd)
     GPIO.setboard(GPIO.PCPCPLUS)
     GPIO.setmode(GPIO.BOARD)
     GPIO.setup(22, GPIO.OUT)
     GPIO.output(self.NRSTPD, 1)
     self.MFRC522_Init()
Example #5
0
def gpio_init():
    GPIO.setboard(GPIO.PCPCPLUS)
    GPIO.setmode(GPIO.BOARD)
    # 这个接口接到LED的正极,LED的负极接到GND即可
    GPIO.setup(16, GPIO.OUT)
    GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.add_event_detect(18, GPIO.RISING, button_event, bouncetime=200)
    print("GPIO init success!")
def setup_button():
    GPIO.setboard(GPIO.ZERO)  # Orange Pi Zero board
    GPIO.setmode(GPIO.SOC)  # set up SOC numbering
    button = GPIO.PA + 10  # button  is on PA10
    led_button = GPIO.PA + 14
    GPIO.setup(button, GPIO.IN, pull_up_down=GPIO.PUD_DOWN
               )  # set PA10 as an output (Status led of board)
    GPIO.setup(led_button, GPIO.OUT)
    print('Button ready')
    return button, led_button
Example #7
0
def gpio_init():
    GPIO.setboard(GPIO.PCPCPLUS)
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(16, GPIO.OUT)
    GPIO.setup(18, GPIO.OUT)
    GPIO.setup(26, GPIO.OUT)
    GPIO.setup(29, GPIO.OUT)
    # 手上的继电器支持高低电平触发,这里以高电平触发演示,默认初始化时为低电平
    GPIO.output(16, 0)
    GPIO.output(18, 0)
    GPIO.output(26, 0)
    GPIO.output(29, 0)
    print("GPIO init success!")
Example #8
0
    def connect(self):
        GPIO.setboard(GPIO.ZEROPLUS2H5)
        GPIO.setmode(GPIO.SOC)  # set up SOC numbering

        reset_gpio = GPIO.PA + 2  # Pin for Arduino reset
        GPIO.setup(reset_gpio, GPIO.OUT)
        GPIO.output(reset_gpio, 0)

        while not self.connect_flag:
            # Restart arduino
            GPIO.output(reset_gpio, 1)
            sleep(0.7)
            GPIO.output(reset_gpio, 0)
            sleep(3)
            # Connect to Arduino
            self.handle_in_msg()
Example #9
0
    def __init__(self, pins, params):
        super().__init__(params)
        GPIO.setboard(GPIO.ZEROPLUS2H5)
        GPIO.setmode(GPIO.BOARD)

        GPIO.setup(pins['ENABLE'], GPIO.OUT)
        GPIO.setup(pins['STEP'], GPIO.OUT)
        GPIO.setup(pins['DIR'], GPIO.OUT)
        # GPIO.setup(pins['PWM'], GPIO.OUT)
        GPIO.setup(pins['FIRE'], GPIO.OUT)

        self.enable_pin = lambda x: GPIO.output(pins['ENABLE'], x)
        self.step_pin = lambda x: print('step') or GPIO.output(pins['STEP'], x)
        self.dir_pin = lambda x: GPIO.output(pins['DIR'], x)
        self.pwm_pin = lambda x: print('[M] PWM PIN ->', x)
        self.fire_pin = lambda x: GPIO.output(pins['FIRE'], x)
Example #10
0
def main():
    get_config()

    GPIO.setboard(GPIO.ZERO)
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(LCD_E, GPIO.OUT)
    GPIO.setup(LCD_RS, GPIO.OUT)
    GPIO.setup(LCD_D4, GPIO.OUT)
    GPIO.setup(LCD_D5, GPIO.OUT)
    GPIO.setup(LCD_D6, GPIO.OUT)
    GPIO.setup(LCD_D7, GPIO.OUT)
    GPIO.setup(LCD_LED, GPIO.OUT)

    lcd_init()
    GPIO.output(LCD_LED, 1)

    external_server_found = False
    while True:
        msg = "Busy"
        busy = server_busy()
        while "BUSY" in busy:
            lcd_lines[0] = msg
            msg += "."
            if len(msg) > 16:
                msg = "Busy"

            refresh_lcd()
            time.sleep(1)
            busy = server_busy()

        ipAddr = get_ip()
        lcd_lines[0] = ipAddr

        if "FREE" in busy:
            if (not external_server_found and (time.time() - last_ping_time) > FIRST_PING_TIMEOUT) or \
               (external_server_found and (time.time() - last_ping_time) > PING_TIMEOUT):

                tunnel_status = get_tunnel_status()
                if tunnel_status is not None:
                    if tunnel_status:
                        lcd_lines[1] = tunnel_url
                        external_server_found = True

        refresh_lcd()

        time.sleep(1)
Example #11
0
    def setup():
        """ Configure the Raspberry GPIOs
        :rtype : None
        """

        GPIO.setboard(GPIO.PCPCPLUS)
        GPIO.setmode(GPIO.BCM)
        # LED
        GPIO.setup(BOARD.LED, GPIO.OUT)
        GPIO.output(BOARD.LED, 0)
        # switch
        GPIO.setup(BOARD.SWITCH, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
        # DIOx
        for gpio_pin in [BOARD.DIO0, BOARD.DIO1, BOARD.DIO2, BOARD.DIO3]:
            GPIO.setup(gpio_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
        # blink 2 times to signal the board is set up
        BOARD.blink(.1, 2)
Example #12
0
def getDistance():
    GPIO.setwarnings(False)
    GPIO.setboard(GPIO.ZERO)
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(7, GPIO.OUT)
    GPIO.setup(8, GPIO.IN)
    time1 = int(round(time.time() * 1000))
    GPIO.output(7, GPIO.HIGH)
    time.sleep(0.00001)
    GPIO.output(7, GPIO.LOW)

    #    while GPIO.input(8) is 0:
    #        pass

    dt = int(round(time.time() * 1000)) - time1

    return random.randint(1, 100)
Example #13
0
    def __init__(self, config):
        global DIRECTIONS, PULLUPS
        import OPi.GPIO as gpio

        self.io = gpio
        DIRECTIONS = {PinDirection.INPUT: gpio.IN, PinDirection.OUTPUT: gpio.OUT}

        PULLUPS = {
            PinPullup.OFF: gpio.PUD_OFF,
            PinPullup.UP: gpio.PUD_UP,
            PinPullup.DOWN: gpio.PUD_DOWN,
        }

        board = config["board"].upper()
        mode = config["mode"].upper()
        if not hasattr(gpio, board):
            raise AssertionError("%s board not found" % board)
        gpio.setboard(getattr(gpio, board))
        gpio.setmode(getattr(gpio, mode))
Example #14
0
def init_board():
    """
    Initialize the GPIO pins and events.
    """
    global BUTTON_LED
    # Set up GPIO library
    GPIO.setboard(GPIO.PCPCPLUS)  # PCPCPLUS is pinout compatible with the Lite
    GPIO.setmode(GPIO.BOARD)

    # Set up pins
    BUTTON_LED = LED(PIN_LED_BUTTON)
    GPIO.setup(PIN_BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    for pin_number in PIN_SEG_DISPLAY.values():
        GPIO.setup(pin_number, GPIO.OUT)

    # Add button event
    GPIO.add_event_detect(PIN_BUTTON,
                          GPIO.FALLING,
                          callback=button_event,
                          bouncetime=BOUNCETIME)
Example #15
0
    def __init__(self, dout, pd_sck, gain=128):
        self.PD_SCK = pd_sck

        self.DOUT = dout

        # Mutex for reading from the HX711, in case multiple threads in client
        # software try to access get values from the class at the same time.
        self.readLock = threading.Lock()

        # GPIO.setmode(GPIO.BCM)
        GPIO.setboard(GPIO.ZERO)
        GPIO.setmode(GPIO.BOARD)

        GPIO.setup(self.PD_SCK, GPIO.OUT)
        GPIO.setup(self.DOUT, GPIO.IN)

        self.GAIN = 0

        # The value returned by the hx711 that corresponds to your reference
        # unit AFTER dividing by the SCALE.
        self.REFERENCE_UNIT = 1
        self.REFERENCE_UNIT_B = 1

        self.OFFSET = 1
        self.OFFSET_B = 1
        self.lastVal = long(0)

        self.DEBUG_PRINTING = False

        self.byte_format = 'MSB'
        self.bit_format = 'MSB'

        self.set_gain(gain)

        # Think about whether this is necessary.
        time.sleep(1)
Example #16
0
def setup():
    GPIO.setboard(GPIO.ZERO)
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(BTN_NEXT, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(BTN_PREV, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(BTN_PAUSE, GPIO.IN, pull_up_down=GPIO.PUD_UP)
Example #17
0
from time import sleep
import serial
import OPi.GPIO as GPIO

GPIO.setboard(GPIO.ZEROPLUS2H5)
GPIO.setmode(GPIO.SOC)  # set up SOC numbering

reset_gpio = GPIO.PA + 2  # Pin for Arduino reset
GPIO.setup(reset_gpio, GPIO.OUT)
GPIO.output(reset_gpio, 0)

buffer_in = [None] * 5  #Empty buffer for incoming message
buffer_out = [None] * 5  #Empty buffer for outcoming message
bufferSize = 5  #Frame of 5  bytes
readCounter = 0
isHeader = 0

header = 0x7E  #First byte in frame
connection = False

ser = serial.Serial(port="/dev/ttyS1", baudrate=9600)
ser.close()
ser.open()


def acceptmessage_from_UART():
    global buffer_in
    firstTimeHeader = 0
    isHeader = 0
    readCounter = 0
    while (ser.inWaiting() > 0):
Example #18
0
import OPi.GPIO as GPIO
import time

GPIO.setboard(GPIO.ZEROPLUS)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.OUT)
p = GPIO.PWM(7, 50)
p.start(7.5)
p.ChangeDutyCycle(12.5)
time.sleep(1)
p.stop()
GPIO.cleanup()
Example #19
0
import os
import OPi.GPIO as GPIO
from time import sleep  # this lets us have a time delay

GPIO.setboard(GPIO.ZERO)  # Orange Pi Zero board
GPIO.setmode(GPIO.SOC)  # set up SOC numbering

button = GPIO.PA + 10  # button  is on PA10
led_button = GPIO.PA + 14
GPIO.setup(
    button, GPIO.IN,
    pull_up_down=GPIO.PUD_DOWN)  # set PA10 as an output (Status led of board)
GPIO.setup(led_button, GPIO.OUT)

try:
    GPIO.output(led_button, 1)
    while True:
        if GPIO.input(button):  # if pin button == 1
            GPIO.output(led_button, 0)
            print "Button is 1/HIGH/True"
            os.system(
                'fswebcam -r 1280x720 --png 9 --no-banner --no-timestamp --no-shadow --no-info --no-underlay --no-overlay -D 1 -S 5 fswebcam.png'
            )
            os.system('lp -o fit-to-page fswebcam.png')
            for x in range(0, 33):
                GPIO.output(led_button, 1)  # set port/pin value to 1/HIGH/True
                sleep(0.1)
                GPIO.output(led_button, 0)  # set port/pin value to 0/LOW/False
                sleep(0.1)
                GPIO.output(led_button, 1)  # set port/pin value to 1/HIGH/True
                sleep(0.1)
import OPi.GPIO as GPIO
import dht11
import time
import datetime

# initialize GPIO
GPIO.setboard(GPIO.PRIME)  # Orange Pi PC board
GPIO.setwarnings(True)
#GPIO.setmode(GPIO.BCM)
GPIO.setmode(GPIO.BOARD)

# read data using pin 14
instance = dht11.DHT11(pin=35)

try:
    while True:
        result = instance.read()
        if result.is_valid():
            print("Last valid input: " + str(datetime.datetime.now()))

            print("Temperature: %-3.1f C" % result.temperature)
            print("Humidity: %-3.1f %%" % result.humidity)

        time.sleep(6)

except KeyboardInterrupt:
    print("Cleanup")
    GPIO.cleanup()
Example #21
0
        heater(heat_op)
    elif (t > t_max):
        heat_op = 0
        #Stop the heater
        heater(heat_op)
    else:
        heat_op = 2  #Nothing doing
        last_op = -1
        counter = 0
    log_data(t, p, h)


#Let's start
init_bme280()

GPIO.cleanup()
GPIO.setboard(GPIO.ZEROPLUS2H5)  # Orange Pi PC board
GPIO.setmode(GPIO.BOARD)  # set up BOARD BCM numbering
GPIO.setup(PowerPIN, GPIO.OUT)  #Pin 19 - power up transmitter
GPIO.setup(OnPIN, GPIO.OUT)  #Pin 21 - set to LOW to enable heater
GPIO.setup(OffPIN, GPIO.OUT)  #Pin 23 - set to LOW to disable heater

s = sched.scheduler(time.time, time.sleep)
s.enter(1, 1, time_func, ())
s.run()

while True:
    time.sleep(1)

GPIO.cleanup()
Example #22
0
def gpio_init():
    GPIO.setboard(GPIO.PCPCPLUS)
    GPIO.setmode(GPIO.BOARD)
    # 这个接口接到LED的正极,LED的负极接到GND即可
    GPIO.setup(16, GPIO.OUT)
    print("GPIO init success!")
Example #23
0
import OPi.GPIO as GPIO  # this was installed by sudo, so

from time import sleep  # this lets us have a time delay

GPIO.setboard(GPIO.ZERO)  # ZERO
GPIO.setmode(GPIO.BOARD)

# Usable Pins on the Zero: 7, 12, 15, ...
pin = 15
period = 0.5

GPIO.setup(pin, GPIO.OUT)

try:
    while True:
        GPIO.output(pin, 1)  # set port/pin value to 1/HIGH/True
        sleep(period)
        GPIO.output(pin, 0)  # set port/pin value to 1/HIGH/True
        sleep(period)
except KeyboardInterrupt:
    GPIO.output(pin, 0)  # set port/pin value to 0/LOW/False
    GPIO.cleanup()  # Clean GPIO
    print("Bye.")
    def __init__(self, debug=False):
        GPIO.setboard(GPIO.PCPCPLUS)    # Orange Pi PC Plus board
        GPIO.setmode(GPIO.BOARD)
        GPIO.setwarnings(False)
        GPIO.cleanup()
        self.piRevision = 3
        #self.piRevision = self.getPiRevision()
        self.i2cbus = 1
        #if self.piRevision == 1:
        #    self.i2cbus = 0
        #print "RPi.GPIO Version" , GPIO.VERSION
        print "OPi.GPIO Version" , GPIO.VERSION
        #print "Board Revision" , self.piRevision
        
		#self.numOfPins = 41 #Orange Pi has 40
        #Set some constants and initialise lists
        self.numOfPins = 27 #there are actually 26 but python can't count properly :)
        if self.piRevision > 2:
            self.numOfPins = 41
        self.PINPUT = 4
        self.POUTPUT = 1
        self.PPWM = 2
        self.PUNUSED = 8
        self.PSONAR = 16
        self.PULTRA = 32
        self.PSERVOD = 64
        self.PSTEPPER = 128
        self.PCOUNT = 256
        self.PINPUTDOWN = 512
        self.PINPUTNONE = 1024
        self.PPWMMOTOR = 2048
        self.PPWMLED = 4096

        #self.INVERT = False
        self.ledDim = 100

        self.PWMMOTORFREQ = 10        
        
        self.dsSensorId  = ""
        self.senderLoopDelay = 0.2
        self.mFreq = 10
        self.ultraFreq = 1
        self.ultraSamples = 7      
        self.pFreq = 200
       
       
       

        self.pinUse = [self.PUNUSED] * self.numOfPins
        self.servodPins = None
        
        self.pinRef = [None] * self.numOfPins
        self.pinCount = [0] * self.numOfPins
        self.countDirection = [1] * self.numOfPins
        self.pinEncoderDiff = [0] * self.numOfPins
        self.encoderStopCounting = [0] * self.numOfPins
        self.pinLastState = [0] * self.numOfPins
        self.encoderTime = [0] * self.numOfPins
        self.encoderTimeDiff = [0.0] * self.numOfPins
        self.gpioLookup = [0] * self.numOfPins
        self.callbackInUse = [False] * self.numOfPins
        self.pinValue = [0] * self.numOfPins
        self.pinInvert = [False] * self.numOfPins
        #print "pinValue" , self.pinValue
        #print "pin Value 3 = ", self.pinValue[3]
        self.pinUltraRef = [None] * self.numOfPins
        self.pinTrigger = [0] * self.numOfPins
        self.pinTriggerName = ["x"] * self.numOfPins
        self.anyTrigger = 0
        self.pinServoValue = [None] * self.numOfPins
        self.gpioMyPinEventDetected = [False] * self.numOfPins
        self.pinTriggerLastState = [0] * self.numOfPins        
        self.encoderCallback = 0
        self.piAndBash = [self.PUNUSED] * 16
        
        self.pinEventEnabled = True
        self.encoderInUse = 0
        
        self.nunchuckLevel = 1

        self.capTouch = None
        self.capTouchHelper = None
        self.ADS1015 = None
        self.lightDirection = 0
        self.lightValue = 0
        self.lightInfo = False
        self.autoLink = False
        self.linkPrefix = None
        self.linkIP = None
        self.mqttBroker = None
        self.mqttListener = None
        self.mqttClient = None
        self.mqttTopic = None
        self.mqttRetainFlag = True

        
        self.pinMapName = [None] * self.numOfPins  
        self.stepperAPos = 0
        self.stepperBPos = 0
        self.stepperDPos = 0

        self.validPins =      [ 3,         5,       7, 8,   10,11,12,13,   15,16,   18,19,   21,22,23,24,   26]
        
        
        if self.piRevision == 1:
        #                       0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
        #                     [ 3, 5,99,99, 7,99,99,26,24,21,19,23,99,99, 8,10,99,11,12,99,99,13,15,16,18,22,99]
            self.gpioLookup = [99,99,99, 0,99, 1,99, 4,14,99,15,17,18,21,99,22,23,99,24,10,99, 9,25,11, 8,99, 7]
        if self.piRevision == 2:
            self.gpioLookup = [99,99,99, 2,99, 3,99, 4,14,99,15,17,18,27,99,22,23,99,24,10,99, 9,25,11, 8,99, 7]
            
        if self.piRevision > 2:
            self.validPins =  [          3,    5,    7, 8,   10,11,12,13,   15,16,   18,19,   21,22,23,24,   26,      29,   31,32,33,   35,36,37,38,   40]
            self.gpioLookup = [99,99,99, 3,99, 5,99, 7, 8,99,10,11,12,13,99,15,16,99,18,19,99,21,22,23,24,99,26,99,99,29,99,31,32,33,99,35,36,37,38,99,40]
            #[99,99,99, 2,99, 3,99, 4,14,99,15,17,18,27,99,22,23,99,24,10,99, 9,25,11, 8,99, 7,99,99, 5,99, 6,12,13,99,19,16,26,20,99,21]

        self.revgpioLookup = [99] *41    
        for index, item in enumerate(self.gpioLookup):
            if item != 99:
                self.revgpioLookup[item] = index
        #print self.revgpioLookup        
        #self.ULTRA_IN_USE = [False] * self.PINS
        #self.ultraTotalInUse = 0
        #self.ultraSleep = 1.0
        self.debug = debug
        if self.debug:
            print "sghGC Debug enabled"
Example #25
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import OPi.GPIO as GPIO
from time import sleep

GPIO.setboard(GPIO.ZERO)
GPIO.setmode(GPIO.BOARD)  # set up BOARD BCM numbering
GPIO.setup(26, GPIO.OUT)  # set pin 26 as an output (LED)

p = GPIO.PWM(26, 10)  # new PWM on channel=26 frequency=10Hz
p.start(0)
try:
    while 1:
        for dc in range(0, 101, 5):
            p.ChangeDutyCycle(dc)
            sleep(0.1)
        for dc in range(100, -1, -5):
            p.ChangeDutyCycle(dc)
            sleep(0.1)
except KeyboardInterrupt:
    pass
p.stop()
GPIO.output(26, 0)
GPIO.cleanup()
Example #26
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import OPi.GPIO as GPIO
from time import sleep  # this lets us have a time delay

pin = 12

GPIO.setboard(GPIO.THREE)  # Orange Pi PC board
GPIO.setmode(GPIO.BOARD)  # set up BOARD BCM numbering
GPIO.setup(pin, GPIO.OUT)  # set BCM7 (pin 26) as an output (LED)

try:
    print("Press CTRL+C to exit")
    while True:
        GPIO.output(pin, 1)  # set port/pin value to 1/HIGH/True
        sleep(0.1)
        GPIO.output(pin, 0)  # set port/pin value to 0/LOW/False
        sleep(0.1)

        GPIO.output(pin, 1)  # set port/pin value to 1/HIGH/True
        sleep(0.1)
        GPIO.output(pin, 0)  # set port/pin value to 0/LOW/False
        sleep(0.1)

        sleep(0.5)

except KeyboardInterrupt:
    GPIO.output(pin, 0)  # set port/pin value to 0/LOW/False
    GPIO.cleanup()  # Clean GPIO
    print("Bye.")
Example #27
0
import OPi.GPIO as GPIO
import socket

in1 = 24
in2 = 23
in3 = 5
in4 = 6
temp1 = 1

GPIO.setboard(GPIO.PCPCPLUS)
GPIO.setmode(GPIO.BCM)
GPIO.setup(in1, GPIO.OUT)
GPIO.setup(in2, GPIO.OUT)
GPIO.setup(in3, GPIO.OUT)
GPIO.setup(in4, GPIO.OUT)
GPIO.output(in1, GPIO.LOW)
GPIO.output(in2, GPIO.LOW)
GPIO.output(in3, GPIO.LOW)
GPIO.output(in4, GPIO.LOW)

isConnected = False

sock = socket.socket()
sock.connect(('87.252.241.47', 3346))
print('Connected to the server')
isConnected = True

while (isConnected):
    x = sock.recv(7)
    x = x.decode('utf8')
    print(x)
Example #28
0
#!/usr/bin/env python3
#
# example of service to monitor a GPIO for Orange Pi PC 2e
# (unfortunately it doesn't support edge triggers)

import sys
import ssl
import time
from urllib import request
import OPi.GPIO as GPIO

URL = "https://localhost:9000/button"
PIN = 12
DEBOUNCE_CYCLES = 5

GPIO.setboard(GPIO.PC2)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(PIN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE

activeCycles = 0
while True:
    if GPIO.input(PIN):
        if activeCycles == DEBOUNCE_CYCLES:
            print("BUTTON PRESSED!")
            req =  request.Request(URL, data={})
            request.urlopen(req, context=ctx)
        activeCycles += 1
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import OPi.GPIO as GPIO
import time  # this lets us have a time delay

GPIO.setboard(GPIO.PCPCPLUS)  # Orange Pi PC board
GPIO.setmode(GPIO.BOARD)

LED_PIN = 7
GPIO.setup(LED_PIN, GPIO.OUT, initial=GPIO.LOW)

print "LED-Test [press ctrl+c to end]"

# main program loop
try:
    while True:
        print("LED is on for 4 seconds")
        GPIO.output(LED_PIN, GPIO.HIGH)  #LED will be switched on
        time.sleep(4)  # Waitmode for 4 seconds
        print("LED is off for 2 seconds")
        GPIO.output(LED_PIN, GPIO.LOW)  #LED will be switched off
        time.sleep(2)  # Waitmode for another 2 seconds

# Scavenging work after the end of the program
except KeyboardInterrupt:
    # here you put any code you want to run before the program
    # exits when you press CTRL+C
    print "An error or exception occurred!"

except:
import OPi.GPIO as gpio
import logging

#import RPi.GPIO as GPIO
import dht22
import time
import datetime

# initialize GPIO
#gpio.setwarnings(False)
gpio.setboard(gpio.PRIME)
gpio.setmode(gpio.SOC)
#PIN2 = port.PA13
pin = gpio.PA + 10
#gpio.cleanup()

gpio.setup(pin, gpio.IN, pull_up_down=gpio.PUD_OFF)
# read data using pin 14
instance = dht22.DHT22(pin)

while True:
    result = instance.read()
    if result.is_valid():
        fResult = (result.temperature * (9 / 5) + 32)
        print("Last valid input: " + str(datetime.datetime.now()))
        print("Temperature: %.2f C" % result.temperature)
        #im an American
        print("Temperature: %.2f F" % fResult)
        print("Humidity: %.2f %%\n" % result.humidity)

    time.sleep(1)