Exemple #1
0
import time
import lgpio

#17,27,22

LED = 17

# open the gpio chip and set the LED pin as output
h = lgpio.gpiochip_open(0)
lgpio.gpio_claim_output(h, LED)

try:
    while True:
        # Turn the GPIO pin high
        lgpio.gpio_write(h, LED, 0)
        print('GIO', LED, 'is On')
        time.sleep(3)

        # Turn the GPIO pin low
        lgpio.gpio_write(h, LED, 1)
        print('GIO', LED, 'is Off')
        time.sleep(1)

except KeyboardInterrupt:
    lgpio.gpio_write(h, LED, 1)
    lgpio.gpiochip_close(h)
Exemple #2
0
 def close(self):
     super().close()
     if self._handle is not None:
         lgpio.gpiochip_close(self._handle)
         self._handle = None
Exemple #3
0
status, dummy = sbc.spi_read(9999, 8888)
check("spi_read 2", sbc.BAD_HANDLE, status)

status = sbc.spi_write(9999, [])
check("spi_write 1", sbc.BAD_SPI_COUNT, status)

status = sbc.spi_write(9999, [88, 77, 66, 55, 44, 33, 22, 11])
check("spi_write 2", sbc.BAD_HANDLE, status)

status, dummy = sbc.spi_xfer(9999, [])
check("spi_xfer 1", sbc.BAD_SPI_COUNT, status)

status, dummy = sbc.spi_xfer(9999, [88, 77, 66, 55, 44, 33, 22, 11])
check("spi_xfer 2", sbc.BAD_HANDLE, status)

status = sbc.gpiochip_close(9999)
check("gpiochip_close 1", sbc.BAD_HANDLE, status)

status, dummy = sbc.group_read(9999, 8888)
check("group_read 1", sbc.BAD_HANDLE, status)

status = sbc.group_write(9999, 8888, 7777)
check("group_write 1", sbc.BAD_HANDLE, status)

status = sbc.gpiochip_open(9999)
check("gpiochip_open 1", sbc.CANNOT_OPEN_CHIP, status)

status, lines, name, label = sbc.gpio_get_chip_info(9999)
check("gpio_get_chip_info 1", sbc.BAD_HANDLE, status)

status, offset, flags, name, user = sbc.gpio_get_line_info(9999, 8888)
          ' (note) 0 is good working')
    #lgpio.gpio_claim_output(h, LED1)
    #lgpio.gpio_claim_output(h, LED2)

    try:
        # Turn the GPIO pin low
        lgpio.group_write(handle, 17, 0x6, 0x7)  # 3개 on, blue, green, red
        #lgpio.group_write(handle, 17, 0x4, 0x7) # 2개 on,       green, red
        #lgpio.group_write(handle, 17, 0x2, 0x7) # 2개on, blue, red, A
        #lgpio.group_write(handle, 17, 0x0, 0x7) # 1개on, red 0,8
        #lgpio.group_write(handle, 17, 0xa, 0x7) # no on 5,1,3,9
        print('GIO', 'is On')
        time.sleep(5)

        # Turn the GPIO pin high
        lgpio.group_write(handle, 17, 0x7, 0x7)
        #lgpio.group_write(handle, LEDS, 0x000008)
        #lgpio.gpio_write(h, LED0, 1)
        #lgpio.gpio_write(h, LED1, 1)
        #lgpio.gpio_write(h, LED2, 1)
        print('GIO', 'is Off')  #LED 보드 구현에 따라, H->On, L->On 이 다를수 있음
        time.sleep(2)

        lgpio.gpiochip_close(handle)

    except KeyboardInterrupt:
        lgpio.gpio_write(handle, LED0, 0)
        lgpio.gpio_write(handle, LED1, 0)
        lgpio.gpio_write(handle, LED2, 0)
        lgpio.gpiochip_close(h)
Exemple #5
0
OUT = [20, 21, 22, 23, 24, 25]

PULSES = 500

pulses = []
total = 0
delay = 1000

for i in range(PULSES):
    pulses.append(sbc.pulse(i, sbc.GROUP_ALL, delay))
    total += delay
    delay += 100

h = sbc.gpiochip_open(0)

sbc.group_claim_output(h, OUT)

sbc.tx_wave(h, OUT[0], pulses)

start = time.time()

while sbc.tx_busy(h, OUT[0], sbc.TX_WAVE):
    time.sleep(0.01)

end = time.time()

print("{} pulses took {:.1f} seconds (exp={:.1f})".format(
    PULSES, end - start, total / 1e6))

sbc.gpiochip_close(h)
Exemple #6
0
 def close(self):
     super(LGPIOFactory, self).close()
     if self._handle is not None:
         lgpio.gpiochip_close(self._handle)
         self._handle = None
Exemple #7
0
        gpio2 = int(sys.argv[3])
        gpio3 = int(sys.argv[4])
        gpio4 = int(sys.argv[5])

    elif len(sys.argv) == 5:  # gpio1 gpio2 gpio3 gpio4 (chip 0)
        chip = 0
        gpio1 = int(sys.argv[1])
        gpio2 = int(sys.argv[2])
        gpio3 = int(sys.argv[3])
        gpio4 = int(sys.argv[4])

    else:
        print("Usage: ./28BYJ_48.py [chip] gpio1 gpio2 gpio3 gpio4")
        exit()

    chip = sbc.gpiochip_open(0)

    s = stepper(sbc, chip, [gpio1, gpio2, gpio3, gpio4])

    for i in range(4096):
        time.sleep(0.0015)
        s.forward()

    for i in range(4096):
        time.sleep(0.0015)
        s.backward()

    s.stop()

    sbc.gpiochip_close(chip)