コード例 #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)
コード例 #2
0
 def __init__(self, chip=0):
     super().__init__()
     self._handle = lgpio.gpiochip_open(chip)
     self._chip = chip
     self.pin_class = LGPIOPin
コード例 #3
0
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)
check("gpio_get_line_info 1", sbc.BAD_HANDLE, status)

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

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

status = sbc.gpio_free(9999, 8888)
コード例 #4
0
#gpio_claim_output	Claims a GPIO for output
#group_claim_output(handle, gpio, levels=[0], lFlags=0)
#group_write(handle, gpio, group_bits, group_mask=GROUP_ALL)
#gpio_write(handle, gpio, level)

LED0 = 17
LED1 = 27
LED2 = 22
LEDS = [17, 27, 22]

if __name__ == "__main__":

    print("...Start...")

    # open the gpio chip and set the LED pin as output
    handle = lgpio.gpiochip_open(0)
    print(' return ', lgpio.group_claim_output(handle, LEDS, [1, 1, 1]),
          ' (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)
コード例 #5
0
            exit()

        EDGE = rgpio.FALLING_EDGE

    else:

        import lgpio as sbc

        EDGE = sbc.FALLING_EDGE

    def cbf(chip, gpio, level, tick):
        print(adc.read_voltage())

    if ALERT_RDY:
        ALERT = 21  # set
        chip = sbc.gpiochip_open(0)
        err = sbc.gpio_claim_alert(chip, ALERT, EDGE)
        if err < 0:
            print("GPIO in use: {} ({})".format(ALERT, sbc.error_text(err)))
            exit()

    adc = lg_ads1x15.ads1015(sbc, 1, 0x48)

    adc.set_voltage_range(3.3)
    adc.set_sample_rate(0)  # minimum sampling rate
    adc.set_channel(adc.A0)

    if ALERT_RDY:
        adc.set_comparator_polarity(0)
        cb_id = sbc.callback(chip, ALERT, EDGE, cbf)
        adc.set_comparator_latch(True)
コード例 #6
0
ファイル: shutdown.py プロジェクト: msfrt/PiLogger
# dave yonkers, 2021

import time
import lgpio as sbc
import os

chip = 0  # GPIO chip
gpio = 3  # button is connected to GPIO
debounce_micros = 100000

# open the gpio chip.
# gets gpio chip's handle upon success
handle = sbc.gpiochip_open(chip)  
if handle < 0:
    print(f"Couldn't open gpio chip {chip} ({sbc.error_text(handle)})")
    exit()


# register the gpio for alerts (edge detection)
err = sbc.gpio_claim_alert(handle, gpio, sbc.FALLING_EDGE)
if err < 0:
    print("GPIO in use {}:{} ({})".format(
        chip, gpio, sbc.error_text(err)))
    exit()


# set the debounce time in microseconds so that the button is only pressed
# once when it's actually pressed once
sbc.gpio_set_debounce_micros(handle, gpio, debounce_micros)

# callback function called when edge is detected
コード例 #7
0
    if temp < MIN_TEMP:
        setFanSpeed(FAN_OFF, temp)

    # Set fan speed to MAXIMUM if the temperature is above MAX_TEMP
    elif temp > MAX_TEMP:
        setFanSpeed(FAN_MAX, temp)

    # Caculate dynamic fan speed
    else:
        step = (FAN_HIGH - FAN_LOW) / (MAX_TEMP - MIN_TEMP)
        delta = temp - MIN_TEMP
        speed = FAN_LOW + (round(delta) * step)
        setFanSpeed(speed, temp)

    return ()


try:
    # Setup GPIO pin
    fan = sbc.gpiochip_open(0)
    sbc.gpio_claim_output(fan, PWM_GPIO_NR)
    setFanSpeed(FAN_LOW, MIN_TEMP)

    # Handle fan speed every WAIT_TIME sec
    while True:
        handleFanSpeed()
        time.sleep(WAIT_TIME)

except KeyboardInterrupt:  # trap a CTRL+C keyboard interrupt
    setFanSpeed(FAN_LOW, MIN_TEMP)