Exemple #1
0
 def __init__(self):
     GPIO.setmode(GPIO.Board)
     GPIO.setwarnings(False)
     GPIO.setup(10, GPIO.IN)
     GPIO.setup(16, GPIO.OUT)
     GPIO.setup(18, GPIO.OUT)
     GPIO.setup(2, GPIO.OUT)
     GPIO.setup(12, GPIO.OUT)
Exemple #2
0
    def __init__(self, pinDir, pinPWM):
        self.dirPin = pinDir
        self.pwmPin = pinPWM
        GPIO.setup(self.dirPin, GPIO.OUT)
        GPIO.output(self.dirPin, GPIO.LOW)
        GPIO.setup(self.pwmPin, GPIO.OUT)

        self.pwmControl = GPIO.PWM(self.pwmPin, 10000)
        self.pwmControl.start(0)
Exemple #3
0
    def __init__(self, pinDir, pinPWM):
        self.dirPin = pinDir
        self.pwmPin = pinPWM
        GPIO.setup(self.dirPin, GPIO.OUT)
        GPIO.output(self.dirPin, GPIO.LOW)
        GPIO.setup(self.pwmPin, GPIO.OUT)

        self.pwmControl = GPIO.PWM(self.pwmPin, 10000)
        self.pwmControl.start(0)
Exemple #4
0
def moisture():
    channel = 26
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(channel, GPIO.IN)

    def callback(channel):
        if GPIO.input(channel):
            return (1)
        else:
            return (0)
Exemple #5
0
def main():
    # Configurações iniciais
    gpio.setmode(gpio.BOARD)
    gpio.setup(13, gpio.OUT)
    gpio.setput(18, gpio.IN)

    # Criar um socket TCP    
    interface = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    # Habilitar a reutilização do endereço/porta
    interface.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    # Conectando o socket no servidor
    server_adress = (host, port)
    interface.connect(server_adress)
    
    send_thread = threading.Thread(target = send, args = (interface,))
    receive_thread = threading.Thread(target = receive, args = (interface,))
Exemple #6
0
 def lit(self,prob):
  i=0
  GPIO.setmode(GPIO.BOARD)
  GPIO.setup(7,GPIO.OUT)
  GPIO.setwarnings(False)
  while(i>0):
   if prob>0.5:
    GPIO.output(7,GPIO.HIGH)
    time.sleep(1)
    GPIO.output(7,GPIO.LOW)
    GPIO.output(7,GPIO.LOW)
    time.sleep(1)
    i-=1
   else:
    GPIO.output(7,GPIO.LOW)
    time.sleep(1)
    i-=1
  GPIO.output(7,GPIO.LOW) 
  GPIO.cleanup()
Exemple #7
0
    def __intit__(self):
        gpio.setmode(gpio.Board)
        TRIG = 1
        ECHO = 2
        HIGH_VOL = 3
        LOW_VOL = 4
        gpio.setup(HIGH_VOL,gpio.OUT)
        gpio.setup(LOW_VOL,gpio.OUT)
        gpio.output(HIGH_VOL, gpio.HIGH)
        gpio.output(LOW_VOL, gpio.LOW)
        gpio.setup(TRIG, gpio.OUT)
        gpio.setup(ECHO, gpio.IN)
	self.dist = 0
Exemple #8
0
# this python file use for insert sensor data in database

#import MyDB connection module
import MyDB
db = MyDB.DB()
import Rpi.GPIO as GPIO
import time

sensorPin1 = 18 #Broadcom pin 18
#pin setup:
GPIO.setmode(GPIO.BCM) #Broadcom pin numbering scheem
GPIO.setup(sensorPin1, GPIO.IN, pull_up_down=GPIO.PUD_UP) # sensor pin set as input
user_id = 1023
data = [user_id]

try:
    while 1:
        if GPIO.input(sensorPin1):
            db.execute("INSERT INTO Zones (user_id,zone1) \
                  VALUES (%s, NOW() )", [data]);

            db.commit()
            print "Records created successfully";
            db.close()

except KeyboardInterrupt: # If CTRL+C is pressed, exit cleanly:

    GPIO.cleanup() # cleanup all GPIO
import Rpi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)

while TRUE:
    try:
        GPIO.output(18, GPIO.HIGH)
        time.sleep(1)
        GPIO.output(18, GPIO.LOW)
        time.sleep(1)
    except KeyboardInterrupt:
        break

GPIO.cleanup()
from Rpi import GPIO  #import GPIO Module
GPIO.setmode(GPIO.BOARD)  # Board Pin
GPIO.setwarnings(False)  # set Warnings
GPIO.setup(40, GPIO.IN)  #declare input pin
GPIO.setup(5, GPIO.OUT)  #declare output pin
while True:  #use to While loop
    a = GPIO.input(40)  #input pin
    if a == 1:  #condition
        GPIO.output(5, HIGH)  #Led On
    else:
        GPIO.output(5, LOW)  #Led Off
Exemple #11
0
import Rpi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO_TRIGGER=18
GPIO_ECHO24

GPIO.setup(GPIO_TRIGGER,GPIO.OUT)
GPIO.setup(GPIO_-ECHO,GPIO.IN)

Def distance():
		GPIO.output(GPIO_TRIGGER,True)
		Time.sleep(0.0001)
		GPIO.output(GPIO_TRIGGER,False)

		StartTime=time.time()
		StopTime=time.time()

		while GPIO.input(GPIO_ECHO) == 0:
			StartTime = time.time()

		while GPIO.inut(GPIO_ECHO) ==1:
			StopTime=time.time()

		TimeElapsed=StopTime-StartTime
		distance=(TimeElapsed * 34300)/2
		Return distance

if__name__ == ‘__main__:
		try:
			while True:
Exemple #12
0
import Rpi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)

GPIO.setup(12,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)

while True:

	if(GPIO.input(12)==1):
		print 'Motion Detected'
		

	time.sleep(.1)
	
from ubidots import ApiClient
import Rpi.GPIO as GPIO
import time
import picamera
from time import sleep

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11,GPIO.IN)

api=ApiClient("2355dc90c5e93fc697295b33f9a6ed4e5003c2e1")

#create a "Variable" object

test_variable=api.get_variable("566993407625420e4e82690a")

while True:
	i=GPIO.input(11)
	i=0
	if i==1
		test_variable.save_value({'value':1})
		camera=picamera.PiCamera()
		camera.capture('suyash.jpg')

		camera.start_preview()
		camera.vflip=True
		camera.hflip=True
		camera.brightness=60
		
		sleep(10)
Exemple #14
0
def setup():
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(LedPin, GPIO.OUT)
    GPIO.output(LedPin, GPIO.HIGH)
Exemple #15
0
def press_button():
    log('Debug: press_button')
    import Rpi.GPIO as GPIO

    GPIO.setmode(GPIO.BOARD)

    GPIO.setup(SERVER_POWER, GPIO.OUT)
    GPIO.setup(SERVER_RESET, GPIO.OUT)
    GPIO.setup(DESKTOP_POWER, GPIO.OUT)
    GPIO.setup(DESKTOP_RESET, GPIO.OUT)
    log('Debug: set up GPIO')

    try:
        if machine_to_control == "S":
            if button_to_press == "P":  # Server Power
                GPIO.output(SERVER_POWER, True)
                log('Info: pressing server power button')
                time.sleep(BUTTON_PRESS_TIME)
                GPIO.output(SERVER_POWER, False)
                log('Info: button released')
            elif button_to_press == "R":  # Server Reset
                GPIO.output(SERVER_RESET, True)
                log('Info: pressing server reset button')
                time.sleep(BUTTON_PRESS_TIME)
                GPIO.output(SERVER_RESET, False)
                log('Info: button released')
            elif button_to_press == "PH":  # Server Power Hold
                GPIO.output(SERVER_POWER, True)
                log('Info: holding server power button')
                time.sleep(BUTTON_HOLD_TIME)
                GPIO.output(SERVER_POWER, False)
                log('Info: button released')
        else:
            log('Error: machine variables not set correctly')
            GPIO.cleanup()
            return

        if machine_to_control == "D":
            if button_to_press == "P":  # Desktop Power
                GPIO.output(DESKTOP_POWER, True)
                log('Info: pressing desktop power button')
                time.sleep(BUTTON_PRESS_TIME)
                GPIO.output(DESKTOP_POWER, False)
                log('Info: button released')
            elif button_to_press == "R":  # Desktop Reset
                GPIO.output(DESKTOP_RESET, True)
                log('Info: pressing desktop reset button')
                time.sleep(BUTTON_PRESS_TIME)
                GPIO.output(DESKTOP_RESET, False)
                log('Info: button released')
            elif button_to_press == "PH":  # Desktop Power Hold
                GPIO.output(DESKTOP_POWER, True)
                log('Info: holding desktop power button')
                time.sleep(BUTTON_HOLD_TIME)
                GPIO.output(DESKTOP_POWER, False)
                log('Info: button released')
        else:
            log('Error: desktop variables not set correctly')
            GPIO.cleanup()
            return
    # TODO: catch and log the error.
    finally:
        GPIO.cleanup()
import Rpi.GPIO as GPIO
import time
GPIO.setmode(GPIO.board)

echo = 3
trig = 5

GPIO.setup(trig, GPIO.OUT)
GPIO.setup(ECHO, GPIO.IN)

# clear trig pin
GPIO.output(trig, False)
time.sleep(1)


def distance():
    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
    d = pulse_duration * 17150
    d = round(distance, 2)
    return d
Exemple #17
0
#! /usr/bin/python

# Import the libraries we need
import Rpi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

LED = 21

GPIO.setup(LED, GPIO, OUT)

GPIO.output(LED, True)

time.sleep(5)

GPIO.output(LED, False)
import Rpi.GPIO as GPIO
GPIO.setup(18, GPIO.OUT)
GPIO.setup(11, GPIO.IN)
while True:
	if GPIO.input(11):
		GPIO.output(18, True)
	else:
		GPIO.output(18, False)
Exemple #19
0
import os
from time import sleep

import Rpi.GPIO as GPIO


GPIO.setmode(GPIO.BCM)

GPIO.setup(23, GPIO.IN)
GPIO.setup(24, GPIO.IN)
GPIO.setup(25, GPIO.IN)

while True:
        if(GPIO.input(23) == False):
                os.system('amixer -q sset Master 3%+')
        if(GPIO.input(24) == False):
                os.system('amixer -q sset Master 3%-')
        if(GPIO.input(25) == False):
                os.system('mpc clear')
                
        sleep(0.1)
import Rpi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT)

frequencyHertz = 50
pwm = GPIO.PWM(11, frequenyHertz)

leftPosition = 0.75
rightPosition = 2.5
middlePosition = (rightPosition - leftPosition) / 2 + leftPosition

position = [leftPosition, middlePosition, rightPosition, middlePosition]
msPerCycle = 1000 / frequencyHertz

for i in range(2):
	for position in positionList:
		dutyCuclePercentage = position * 100 / msPerCycle
		print "Position: " + str(position)
		print "Duty Cycle: " + str(dutyCyclePercentage) + "%"
		print ""
		pwm.start(dutyCyclePercentage)
		time.sleep(.5)

pwm.stop()
GPIO.cleanup()
Exemple #21
0
import Rpi.GPIO as gpio
import time

gpio.setmode(gpio,BCM)
gpio.setup(21,gpio.OUT)

while(1):
	x=input('Enter the state')
	if x == 'ON':
		gpio.output(21,1)
		print('LED ON')
	if x =='OFF'
		gpio.output(21,0)
		print('LED OFF')
gpio.cleanup()
import Rpi.GPIO as GPIO, time

GPIO.setmode(GPIO.BCM)
GREEN_LED = 22
RED_LED = 21
GPIO.setup(GREEN_LED, GPIO.OUT)
GPIO.setup(RED_LED, GPIO.OUT)

GPIO.output(GREEN_LED, True)
time.sleep(5)
GPIO.output(GREEN_LED, False)
#ports for motors
motorR1A = 7
motorR1B = 11
motorR2A = 12
motorR2B = 13
motorR3A = 15
motorR3B = 16
motorL1A = 18
motorL1B = 22
motorL2A = 29
motorL2B = 31
motorL3A = 32
motorL3B = 33

GPIO.setup(motorR1A, GPIO.OUT)
GPIO.setup(motorR1B, GPIO.OUT)
GPIO.setup(motorR2A, GPIO.OUT)
GPIO.setup(motorR2B, GPIO.OUT)
GPIO.setup(motorR3A, GPIO.OUT)
GPIO.setup(motorR3B, GPIO.OUT)
GPIO.setup(motorL1A, GPIO.OUT)
GPIO.setup(motorL1B, GPIO.OUT)
GPIO.setup(motorL2A, GPIO.OUT)
GPIO.setup(motorL2B, GPIO.OUT)
GPIO.setup(motorL3A, GPIO.OUT)
GPIO.setup(motorL3B, GPIO.OUT)

def drive(duration):
    GPIO.output(motorR1A, GPIO.LOW)
    GPIO.output(motorR1B, GPIO.HIGH)
Exemple #24
0
#Servo Code

#makes servo go left and right 100 degrees
'Servo Scan Code Example'
import Rpi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)
pwn = GPIO.PWN(12, 50)
pwn.start(0)
for i in range(100):
    pwn.ChangeDutyCycle(i)
    time.sleep(0.1)
for i in range(100, 0, -1):
    pwn.ChangeDutyCycle(i)
    time.sleep(0.1)
'''
Build a circuit using your Raspberry Pi that causes an LED to blink when a push button is NOT pressed.
However, the LED should stay on continually when the push button IS pressed.
Video should show the LED blinking when the push button is not pressed,
and it should show that the LED is constantly on while the button is pressed.

The code can be tested without Raspberry Pi board by using print statements

'''
import Rpi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)  #setup or initialize the gpio board
GPIO.setup(10, GPIO.IN,
           pull_up_down=GPIO.PUD_UP)  #setup pin 10 for this project, button up
while True:
    input_state = GPIO.output(10)
    if input_state == True:  #if button up, it blinks
        print("Button Pressed")
        GPIO.output(10, True)
        time.sleep(0.5)  #sleep half second
        GPIO.output(10, False)
        time.sleep(0.5)
else:  #if button down, it stays constantly
    print "Button Not Pressed"
    GPIO.output(10, True)
Exemple #26
0
import Rpi.GPIO as GPIO
import curses

GPIO.setwarnings(False)

screen = curses.initscr()
curses.noecho()
curses.cbreak()
screen.keypad(True)

GPIO.setmode(GPIO.BCM)

GPIO.setup(4, GPIO.OUT)  # Motor 1
GPIO.setup(14, GPIO.OUT)  # Motor 1

GPIO.setup(17, GPIO.OUT)  #Motor 2
GPIO.setup(18, GPIO.OUT)  # Motor 2

while True:
    a = screen.getch()
    if a == ord('q'):
        break
    elif a == curses.KEY_UP:
        GPIO.output(4, True)
        GPIO.output(14, False)
        GPIO.output(17, True)
        GPIO.output(18, False)
        print("W")
    elif a == curses.KEY_DOWN:
        GPIO.output(4, False)
        GPIO.output(14, True)
Exemple #27
0
	def __init__(self, ch_port):
		super(GPIOOutput, self).__init__(ch_port)
		GPIO.setup(ch_port, GPIO.OUT)
Exemple #28
0
#!/usr/bin/python3
# A simple Raspberry pi 3 GPIO test
# Written by
# (except lines 5-13, these are from the RPi site raspberrypi.org/documentation/usage/python/more.md)
# plscks 
import Rpi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)  # set board mode to Broadcom

GPIO.setup(17, GPIO.OUT)  # set up pin 17
GPIO.setup(18, GPIO.OUT)  # set up pin 18

GPIO.output(17, 1)  # turn on pin 17
GPIO.output(18, 1)  # turn on pin 18
while True:
    ret, frame = video_capture.read()
    rgb_frame = frame[:, :, ::-1]
    face_locations = face_recognition.face_locations(rgb_frame)
    face_encodings = face_recognition.face_encodings(rgb_frame, face_locations)
    for (top, right, bottom, left), face_encoding in zip(face_locations, face_encodings):
        matches = face_recognition.compare_faces(known_face_encodings, face_encoding)
        name = "Abhijit"
	DIR=20
	STEP=21
	CW=1
	CCW=0
	SPR=12 #90/7.5
	GPIO.setmode(GPIO.BCM)
	GPIO.setup(DIR,GPIO.OUT)
	GPIO.setup(STEP,GPIO.OUT)
	GPIO.output(DIR,CW)
	step_count=SPR
	delay=0.833 #1/12
	for x in range(step_count):
		GPIO.output(STEP,GPIO.HIGH)
		sleep(delay)
		GPIO.output(STEP,GPIO.LOW)
		sleep(delay)
	sleep(5)
	GPIO.outdoor(DIR,CCW)
	for x in range(step_down)
		GPIO.output(STEP,GPIO.HIGH)
		sleep(delay)
		GPIO.output(STEP,GPIO.LOW)
Exemple #30
0
import time
import picamera
import Rpi.GPIO as GPIO

GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.IN, GPIO.PUD_UP)

camera = PiCamera()
camera.start_preview()
GPIO.wait_for_edge(17, GPIO.FALLING)
camera.capture('/home/pi/image.jpg')
camera.stop_preview()


Exemple #31
0
'''
Created on 28 дек. 2016 г.

@author: Evegen
'''
import Rpi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(13, GPIO.OUT)
while True:
    GPIO.output(13, True)
    time.sleep(1)
    GPIO.output(13, True)
    time.sleep(1)
Exemple #32
0
	def __init__(self, ch_port):
		super(GPIOInput, self).__init__(ch_port)
		GPIO.setup(ch_port, GPIO.IN)
Exemple #33
0
import Rpi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

TRIG = 12
ECHO = 24

GPIO.setup(TRIG, GPIO.OUT)
GPIO.output(TRIG, 0)

GPIO.setup(ECHO, GPIO.IN)

time.sleep(0.1)

print("Starting Measurement....")

GPIO.output(TRIG, 1)
time.sleep(0.00001)
GPIO.output(TRIG, 0)

while GPIO.input(ECHO) == 0:
    pass
start = time.time()

while GPIO.input(ECHO) == 1:
    pass
stop = time.time()

print(stop - start) * 17000
def SetTriggerPin():
  gpio.setmode(gpio.BOARD)
  gpio.setup(TRIGGER, gpio.IN)
 
if __name__ == '__main__':
  gpsp = GpsPoller() # create the thread
  try:
    gpsp.start() # start it up
    while True:
      #It may take a second or two to get good data
      #print gpsd.fix.latitude,', ',gpsd.fix.longitude,'  Time: ',gpsd.utc
 
        os.system('clear')
	    latitude = gpsd.fix.latitude
	    longitude = gpsd.fix.longitude
	    time = gpsd.utc,' + ', gpsd.fix.time
	  
	  #GPIO read
	    GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_UP)
	    button = GPIO.input(11)
	  
	  #if button is pressed than write to file
	    if button == False:
	        gpsdLog = open("GPSLOG.txt", "a")
	        print(latitude, sep = "*", end="\n",file=gpsdLog)
		    print(longitude, sep = "*", end="\n",file=gpsdLog)
		    print(time, sep = "*", end="\n",file=gpsdLog)
		    button = True
		    time.sleep(3) #delay
	    else:
            time.sleep(3) 
		    print("variables are resetting")
 
  except (KeyboardInterrupt, SystemExit): #when you press ctrl+c
Exemple #36
0
import Rpi.GPIO as gpio
# RPI gpio library
import time
#module for time
import random
# module for randomised number

gpio.setmode(gpio,BCM)	#used to set the RPI mode
gpio.setup(21,gpio.OUT) #used to set pin as output

while(1):
    otp = random.randint(10000,99999)
    print('OTP is' + otp)

    a = int(input("Enter the OTP"))
    if a == otp:
        print("OTP Accepted")
        gpio.output(21,1)	
	    print('LED ON')
	    time.sleep(2)
        gpio.output(21,0)	
    else:
        print("Invalid OTP")
        gpio.output(21,0)
	
gpio.cleanup()			# clear existing states of GPIO
import Rpi.GPIO as GPIO
import numpy as np
import imutils
import cv2
import serial
import time

lf = 16
lb = 18
en1 = 22
rf = 23
rb = 21
en2 = 19

GPIO.setup(lf,GPIO.OUT)
GPIO.setup(lb,GPIO.OUT)
GPIO.setup(en1,GPIO.OUT)
GPIO.setup(rf,GPIO.OUT)
GPIO.setup(rb,GPIO.OUT)
GPIO.setup(en2,GPIO.OUT)

def straight():

 GPIO.output(lf,GPIO.HIGH)
 GPIO.output(lb,GPIO.LOW)
 GPIO.output(en1,GPIO.HIGH)
 GPIO.output(rf,GPIO.HIGH)
 GPIO.output(rb,GPIO.LOW)
 GPIO.output(en2,GPIO.HIGH)

Exemple #38
0
import Rpi.GPIO as GPIO
import time
GPIO.setwarnings(Fale)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(3, GPIO.OUT)

while True:
    GPIO.output(3, 1)
    time.sleep(1)
    GPIO.output(3, 0)
    time.sleep(1)
Exemple #39
0
import Rpi.GPIO as GPIO

GPIO.setmode(GPIO.BOARD)

GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

GPIO.setup(6, GPIO.OUT)
GPIO.output(7, 0)

try:
    while True:
        if (GPIO.output(11) == 1):
            GPIO.output(7, 1)
        else:
            GPIO.output(7, 0)

except KeyboardInterrupt:
    GPIO.cleanup()
Exemple #40
0
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
'''

'''	Import relevant libraries '''
import Rpi.GPIO as GPIO
import sys
import os
from subprocess import Popen

'''	Setup GPIO pins on the Raspberry Pi '''
GPIO.setmode(GPIO.BCM)
GPIO.setup(14, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(15, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP)

'''	Set up movie locations and names '''	
movie1 = ("/home/pi/Videos/movie1.mp4")
movie2 = ("/home/pi/Videos/movie2.mp4")
movie3 = ("/home/pi/Videos/movie3.mp4")
movie4 = ("/home/pi/Videos/movie4.mp4")

'''	Set up state variables for the videos and GPIO pins '''
last_state1 = True
last_state2 = True
last_state3 = True
Exemple #41
0
import os
import time
from sht1x.Sht1x import Sht1x as SHT1x
import Rpi.GPIO as GPIO
from Adafruit_BMP085 import BMP085
import smbus
import math

GPIO.setmode(GPIO.BOARD)
GPIO.setup(8, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

bus = smbus.SMBus(0)
address = 0x1e

def read_byte(adr):
    return bus.read_byte_data(address,adr)

def read_word(adr):
    high = bus.read_byte_data(address, adr)
    low = bus.read_byte_data(address, adr)
    val = (high << 8) + low
    return val

def read_word_2c(adr):
    val = read_word(adr)
    if (val >= 0x8000):
        return -((65535 - val) + 1)
    else:
        return val

def write_byte(adr, value):
Exemple #42
0
#GPIO.setup(portua2, GIPO.out(), initial = 0) # Portua2 Output gisa sortzen aktibatu gabe

#try:
 #GPIO.output(portua1, 1) # portua1 eko Output/a aktibatu
  #     sleep(5.0) # 5 segundu itxarongo ditu
   #    GPIO.output(portua1, 0)# portua1 eko Output/a desaktibatu
#except KeyboardInterrupt:
 #   GPIO.cleanup()


import Rpi.GPIO as GPIO
import time

GPIO.setupmode(GPIO.BOARD)

GPIO.setup(18, GPIO.OUT)# PWM-rako erabilgarriak diren bakarrak 18, 12, 13 19
GPIO.setup(12, GPIO.OUT)

m1 = input(str(´Lehen motorraren GPIO portua´))
GPIO.pwm(m1, 40) #Motorraren portua eta bere frekuentzia jartzen. GPIO.PWM(Portua, frekuentzia)
m2 = input(str(´Lehen motorraren GPIO portua´))
GPIO.pwn(m2, 40)
motorrak[m1, m2]

# motorren "duty cicle" = 50. %50 eko potentziarekin = 3.3V / 2
motorrak.start(50)

x = 0
try:
    while True:
        if x != 100:
Exemple #43
0
 def __init__(self):
     self.pin1 = pin1
     self.pin2 = pin2
     GPIO.setup(self.pin1, GPIO.OUT)
     GPIO.setup(self.pin2, GPIO.OUT)
Exemple #44
0
# !/usr/bin/python3
# -- coding: UTF-8 --
# Author   :WindAsMe
# Date     :18-7-24 下午12:49
# File     :detectButton.py
# Location:/Home/PycharmProjects/..
import Rpi.GPIO as GPIO
import time

# Pin Definition
butPin = 12

# Pin Setup
GPIO.setmode(GPIO.BOARD)
GPIO.setup(butPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

print("Running...")

try:
    while True:
        if GPIO.input(butPin):
            print("Released!")
        else:
            print("Pressed!")
        time.sleep(0.25)
except KeyboardInterrupt:
    GPIO.cleanup()
    print("Terminal!")
Exemple #45
0
#!usr/bin/python
# coding: utf-8

import argparse
import Rpi.GPIO as GPIO
import time
import sys

parser = argparse.ArgumentParser(description='this script is motorcontroller')
parser.add_argument("GPIO",type=int)
parser.add_argument("GPIO2",type=int)
parser.add_argument("PMW",type=int)
args = parser.parse_args()

print args.GPIO1
print args.GPIO2
print args.PMW

GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.OUT)
GPIO.setup(24, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)

GPIO.PWM(args.PWM)