예제 #1
0
def t1():

   print("Mode/PUD/read/write tests.")

   pigpio.set_mode(GPIO, pigpio.INPUT)
   v = pigpio.get_mode(GPIO)
   CHECK(1, 1, v, 0, 0, "set mode, get mode")

   pigpio.set_pull_up_down(GPIO, pigpio.PUD_UP)
   v = pigpio.read(GPIO)
   CHECK(1, 2, v, 1, 0, "set pull up down, read")

   pigpio.set_pull_up_down(GPIO, pigpio.PUD_DOWN)
   v = pigpio.read(GPIO)
   CHECK(1, 3, v, 0, 0, "set pull up down, read")

   pigpio.write(GPIO, pigpio.LOW)
   v = pigpio.get_mode(GPIO)
   CHECK(1, 4, v, 1, 0, "write, get mode")

   v = pigpio.read(GPIO)
   CHECK(1, 5, v, 0, 0, "read")

   pigpio.write(GPIO, pigpio.HIGH)
   v = pigpio.read(GPIO)
   CHECK(1, 6, v, 1, 0, "write, read")
예제 #2
0
def t1():

    print("Mode/PUD/read/write tests.")

    pigpio.set_mode(GPIO, pigpio.INPUT)
    v = pigpio.get_mode(GPIO)
    CHECK(1, 1, v, 0, 0, "set mode, get mode")

    pigpio.set_pull_up_down(GPIO, pigpio.PUD_UP)
    v = pigpio.read(GPIO)
    CHECK(1, 2, v, 1, 0, "set pull up down, read")

    pigpio.set_pull_up_down(GPIO, pigpio.PUD_DOWN)
    v = pigpio.read(GPIO)
    CHECK(1, 3, v, 0, 0, "set pull up down, read")

    pigpio.write(GPIO, pigpio.LOW)
    v = pigpio.get_mode(GPIO)
    CHECK(1, 4, v, 1, 0, "write, get mode")

    v = pigpio.read(GPIO)
    CHECK(1, 5, v, 0, 0, "read")

    pigpio.write(GPIO, pigpio.HIGH)
    v = pigpio.read(GPIO)
    CHECK(1, 6, v, 1, 0, "write, read")
    def set_motor_direction_pins(self):
        if ( self.current_pulse_width >= 0):
            pigpio.write(self.gpio_direction_pin, 0)
        else:
            pigpio.write(self.gpio_direction_pin, 1)

        self.logger.info("Direction pin set to %s" % pigpio.read(self.gpio_direction_pin))
    def set_motor_direction_pins(self):
        if (self.current_pulse_width >= 0):
            pigpio.write(self.gpio_direction_pin, 0)
        else:
            pigpio.write(self.gpio_direction_pin, 1)

        self.logger.info("Direction pin set to %s" %
                         pigpio.read(self.gpio_direction_pin))
예제 #5
0
def consider_stopping():
    # Sleep for duration of the video
    time.sleep(MIN_VIDEO_LENGTH)

    # Start checking - is there still motion?
    while pigpio.read(GPIO_PIN):
        print "  %s: Movement still detected..." % timestamp()
        time.sleep(5)  # Every 5 seconds
예제 #6
0
def t8():
    print("Bank read/write tests.")

    pigpio.write(GPIO, 0)
    v = pigpio.read_bank_1() & (1 << GPIO)
    CHECK(8, 1, v, 0, 0, "read bank 1")

    pigpio.write(GPIO, 1)
    v = pigpio.read_bank_1() & (1 << GPIO)
    CHECK(8, 2, v, (1 << GPIO), 0, "read bank 1")

    pigpio.clear_bank_1(1 << GPIO)
    v = pigpio.read(GPIO)
    CHECK(8, 3, v, 0, 0, "clear bank 1")

    pigpio.set_bank_1(1 << GPIO)
    v = pigpio.read(GPIO)
    CHECK(8, 4, v, 1, 0, "set bank 1")

    t = 0
    v = 1 << 16
    for i in range(100):
        if pigpio.read_bank_2() & v:
            t += 1
    CHECK(8, 5, t, 60, 75, "read bank 2")

    v = pigpio.clear_bank_2(0)
    CHECK(8, 6, v, 0, 0, "clear bank 2")

    pigpio.exceptions = False
    v = pigpio.clear_bank_2(0xFFFFFF)
    pigpio.exceptions = True
    CHECK(8, 7, v, pigpio.PI_SOME_PERMITTED, 0, "clear bank 2")

    v = pigpio.set_bank_2(0)
    CHECK(8, 8, v, 0, 0, "set bank 2")

    pigpio.exceptions = False
    v = pigpio.set_bank_2(0xFFFFFF)
    pigpio.exceptions = True
    CHECK(8, 9, v, pigpio.PI_SOME_PERMITTED, 0, "set bank 2")
예제 #7
0
def t8():
   print("Bank read/write tests.")

   pigpio.write(GPIO, 0)
   v = pigpio.read_bank_1() & (1<<GPIO)
   CHECK(8, 1, v, 0, 0, "read bank 1")

   pigpio.write(GPIO, 1)
   v = pigpio.read_bank_1() & (1<<GPIO)
   CHECK(8, 2, v, (1<<GPIO), 0, "read bank 1")

   pigpio.clear_bank_1(1<<GPIO)
   v = pigpio.read(GPIO)
   CHECK(8, 3, v, 0, 0, "clear bank 1")

   pigpio.set_bank_1(1<<GPIO)
   v = pigpio.read(GPIO)
   CHECK(8, 4, v, 1, 0, "set bank 1")

   t = 0
   v = (1<<16)
   for i in range(100):
      if pigpio.read_bank_2() & v:
         t += 1
   CHECK(8, 5, t, 60, 75, "read bank 2")

   v = pigpio.clear_bank_2(0)
   CHECK(8, 6, v, 0, 0, "clear bank 2")

   pigpio.exceptions = False
   v = pigpio.clear_bank_2(0xffffff)
   pigpio.exceptions = True
   CHECK(8, 7, v, pigpio.PI_SOME_PERMITTED, 0, "clear bank 2")

   v = pigpio.set_bank_2(0)
   CHECK(8, 8, v, 0, 0, "set bank 2")

   pigpio.exceptions = False
   v = pigpio.set_bank_2(0xffffff)
   pigpio.exceptions = True
   CHECK(8, 9, v, pigpio.PI_SOME_PERMITTED, 0, "set bank 2")
예제 #8
0
def check_pixel(x, y):
	print 'checking pixel state for ' + str(x) + ', ' + str('y')
	# TODO: maybe take a few readings, average them out, round up/down to get state?
	pigpio.set_mode(config['pins']['actuator_power'], pigpio.OUTPUT)
	pigpio.set_mode(config['pins']['actuator_sensor'], pigpio.INPUT)

	# Read value
	light_sensor = pigpio.read(config['pins']['actuator_sensor'])

	print 'light sensor: ' + str(light_sensor)

	pigpio.write(config['pins']['actuator_power'], pigpio.LOW)

	return light_sensor
예제 #9
0
def read_gpio(ValueHeating):
    CountGpio = 0
    Matrix_Heating_Value = dict_heating_value[ValueHeating]
    for ValuePin in Matrix_Heating_Value:
        GpioPin = dict_gpio_heating_relay[CountGpio]
        if str(ValuePin) != ".":
            #print (ValuePin)
            #print (GpioPin)
            #print (CountGpio)
            if ValuePin == "1":
                pi.set_pull_up_down(int(GpioPin), pigpio.PUD_UP)
                #print (ValuePin,GpioPin)
            else:
                pi.set_pull_up_down(int(GpioPin), pigpio.PUD_DOWN)
                #print (ValuePin,GpioPin)
            print(pi.read(int(GpioPin)))
            CountGpio = CountGpio + 1
예제 #10
0
def change_pixel(state):
	print 'turning pixel to state ' + str(state)
	pigpio.set_mode(config['pins']['actuator_power'], pigpio.OUTPUT)
	pigpio.set_mode(config['pins']['actuator_sensor'], pigpio.INPUT)

	pigpio.write(config['pins']['actuator_power'], pigpio.HIGH)

	turning = 1
	while turning > 0:
		turning += 1
		light_sensor = pigpio.read(config['pins']['actuator_sensor'])
		print 'light sensor: ' + str(light_sensor)
		time.sleep(0.2)
		if turning > 10:
			turning = 0

	pigpio.write(config['pins']['actuator_power'], pigpio.LOW)
	print 'done turning'

	return light_sensor
예제 #11
0
파일: control.py 프로젝트: alexreser/FEMTA
import pigpio

pigpio.start()

for g in range(0,32):
       print("gpio {} is {}".format(g, pigpio.read(g)))

       pigpio.stop()
예제 #12
0
	print "Usage: ./set_pin.py pin_number [0/1]\n"
	sys.exit(-1)

try:
	PIN = int(sys.argv[1])
	VALUE = int(sys.argv[2])

	stdscr = init_curses()

	println("\nPress Enter to flip between values")
	init_pin(PIN)
	set_pin_to(PIN, VALUE)
	
	while True:
		key = stdscr.getch()
		if key == 10:
			set_pin_to(PIN, int(not bool(pigpio.read(PIN))))
	
	
	
except:
	etype, value, tb = sys.exc_info()
	traceback.print_exception(etype, value, tb)
	
finally:
	restore_terminal()
	print "Cleaning up..."
	time.sleep(0.1)
	pigpio.stop()
	
예제 #13
0

if (len(sys.argv) < 3):
    print "Usage: ./set_pin.py pin_number [0/1]\n"
    sys.exit(-1)

try:
    PIN = int(sys.argv[1])
    VALUE = int(sys.argv[2])

    stdscr = init_curses()

    println("\nPress Enter to flip between values")
    init_pin(PIN)
    set_pin_to(PIN, VALUE)

    while True:
        key = stdscr.getch()
        if key == 10:
            set_pin_to(PIN, int(not bool(pigpio.read(PIN))))

except:
    etype, value, tb = sys.exc_info()
    traceback.print_exception(etype, value, tb)

finally:
    restore_terminal()
    print "Cleaning up..."
    time.sleep(0.1)
    pigpio.stop()
예제 #14
0
# disable gpio 28 as the PCM clock is swamping the system

cb[28].cancel()

stdscr.nodelay(1)

stdscr.addstr(0, 23, "Status of gpios 0-31", curses.A_REVERSE)

while True:

    for g in range(GPIOS):
        tally = cb[g].tally()
        mode = pigpio.get_mode(g)

        col = (g / 11) * 25
        row = (g % 11) + 2

        stdscr.addstr(row, col, "{:2}".format(g), curses.A_BOLD)

        stdscr.addstr("={} {:>6}: {:<10}".format(pigpio.read(g), MODES[mode],
                                                 tally))

    stdscr.refresh()

    time.sleep(0.1)

    c = stdscr.getch()

    if c != curses.ERR:
        break