def __init__(self, gpio, address=0x29, debug=False): # Depending on if you have an old or a new Raspberry Pi, you # may need to change the I2C bus. Older Pis use SMBus 0, # whereas new Pis use SMBus 1. If you see an error like: # 'Error accessing 0x29: Check your I2C address ' # change the SMBus number in the initializer below! # setup i2c bus and SFR address self.i2c = smbus.SMBus(2) self.address = 0x29 self.wanted_address = address self.gpio = gpio self.debug = debug # Module identification self.idModel = 0x00 self.idModelRevMajor = 0x00 self.idModelRevMinor = 0x00 self.idModuleRevMajor = 0x00 self.idModuleRevMinor = 0x00 self.idDate = 0x00 self.idTime = 0x00 GPIO.setup(self.gpio, GPIO.OUT) self.deactivate() # Must be started turned off
def __init__(self, gpio=params.START_STOP_BUTTON_PIN, from_ros=False): ''' Init routine ''' self.from_ros = from_ros if self.from_ros: self.activated = False rospy.Subscriber("button", String, self.callback) else: self.gpio = gpio GPIO.setup(self.gpio, GPIO.IN)
def __init__(self, pins=params.motors_pins): """ pins are provided by a dictionary formatted like: { 'fr':fr, 'fl':fl, 'rr':rr, 'rl':rl, 'dir_fr':dir_fr, 'dir_fl':dir_fl, 'dir_rr':dir_rr, 'dir_rl':dir_rl } """ GPIO.setup(pins['dir_fr'], GPIO.OUT) GPIO.setup(pins['dir_fl'], GPIO.OUT) GPIO.setup(pins['dir_rr'], GPIO.OUT) GPIO.setup(pins['dir_rl'], GPIO.OUT) self.pins = pins self.actual_l = 0 self.actual_r = 0
import sys import os import time import utils.GPIO as GPIO import subprocess import signal import actuators.motors as motors import config.params as params if __name__ == '__main__': pin = "gpio65" #os.system("sh /root/rsm-2017-ga/start.sh") #os.system("sh /root/rsm-2017-ga/start_routine.sh") os_command = "python /root/rsm-2017-ga/main.py" GPIO.setup(pin, GPIO.IN) m = motors.Motor(params.motors_pins) m.stop() pro = subprocess.Popen(os_command, stdout=open(os.devnull, 'wb'), shell=True, preexec_fn=os.setsid) print(os.getpgid(pro.pid)) print(pro.pid) while True: if GPIO.input(pin) == True: started_pressing = time.time() while GPIO.input(pin) == True: pass pressed_time = time.time() - started_pressing print("OMFG, you pressed da button!")
def __init__(self, pins=params.touch_pins): self.pins = pins GPIO.setup(self.pins['E'], 'in') GPIO.setup(self.pins['O'], 'in')
def __init__(self, pin= params.LED_PIN): self.pin = pin GPIO.setup(self.pin, GPIO.OUT) GPIO.output(self.pin, GPIO.LOW)