status = sbc.gpio_set_watchdog_micros(9999, 8888, 400000000) check("gpio_set_watchdog_micros 1", sbc.BAD_WATCHDOG_MICS, status) status = sbc.gpio_set_watchdog_micros(9999, 8888, 4000) check("gpio_set_watchdog_micros 2", sbc.BAD_HANDLE, status) status = sbc.gpio_claim_alert(9999, 8888, 7777, 6666, 5555) check("gpio_claim_alert 1", sbc.BAD_HANDLE, status) status = sbc.gpio_claim_input(9999, 8888) check("gpio_claim_input 1", sbc.BAD_HANDLE, status) status = sbc.group_claim_input(9999, [8888, 7777, 6666]) check("group_claim_input 1", sbc.BAD_HANDLE, status) status = sbc.gpio_claim_output(9999, 8888, 7777) check("gpio_claim_output 1", sbc.BAD_HANDLE, status) status = sbc.group_claim_output(9999, [8888, 7777, 6666]) check("group_claim_output 1", sbc.BAD_HANDLE, status) status = sbc.gpio_write(9999, 8888, 7777) check("gpio_write 1", sbc.BAD_HANDLE, status) err = sbc.error_text(0) check("error_text 1", "No error", err) err = sbc.error_text(-1) check("error_text 2", "initialisation failed", err) err = sbc.error_text(1)
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)
""" bench.py 2020-11-18 Public Domain http://abyz.me.uk/lg/py_lgpio.html ./bench.py """ import time import lgpio OUT = 21 LOOPS = 100000 h = lgpio.gpiochip_open(0) lgpio.gpio_claim_output(h, OUT) t0 = time.time() for i in range(LOOPS): lgpio.gpio_write(h, OUT, 0) lgpio.gpio_write(h, OUT, 1) t1 = time.time() lgpio.gpiochip_close(h) print("{:.0f} toggles per second".format(LOOPS / (t1 - t0)))
#17: location 11 Header pin #27: location 13 Header pin #22: location 15 Header pin LED0 = 17 LED1 = 27 LED2 = 22 if __name__ == "__main__": print("...Start...") # open the gpio chip and set the LED pin as output h = lgpio.gpiochip_open(0) print(lgpio.gpio_claim_output(h, LED0)) lgpio.gpio_claim_output(h, LED1) lgpio.gpio_claim_output(h, LED2) try: while True: # Turn the GPIO pin low lgpio.gpio_write(h, LED0, 0) lgpio.gpio_write(h, LED1, 0) lgpio.gpio_write(h, LED2, 0) print('GIO', 'is On') time.sleep(90) # Turn the GPIO pin high lgpio.gpio_write(h, LED0, 1)
Public Domain http://abyz.me.uk/lg/py_lgpio.html ./tx_pulse.py """ import time import lgpio as sbc OUT = 21 LOOPS = 120 h = sbc.gpiochip_open(0) sbc.gpio_claim_output(h, OUT) sbc.tx_pulse(h, OUT, 20000, 30000) # 20 Hz 40 % duty cycle time.sleep(2) sbc.tx_pulse(h, OUT, 20000, 5000, pulse_cycles=LOOPS) # 40 Hz 80 % start = time.time() while sbc.tx_busy(h, OUT, sbc.TX_PWM): time.sleep(0.01) end = time.time() print("{} cycles at 40 Hz took {:.1f} seconds".format(LOOPS, end - start))
./testbed.py """ import time import lgpio as sbc MCP23017_1 = 0x20 MCP23017_2 = 0x21 NANO = 0x2c DAC_CS = 8 # spidev 0.0 ADC_CS = 25 # spidev 0.1 NANO_CS = 24 # spidev 0.1 chip = sbc.gpiochip_open(0) sbc.gpio_claim_output(chip, ADC_CS, 1) sbc.gpio_claim_output(chip, NANO_CS, 1) dac = sbc.spi_open(0, 0, 50000) others = sbc.spi_open(0, 1, 50000) nano_i2c = sbc.i2c_open(1, NANO) nano_serial = sbc.serial_open("serial0", 115200) inc = True potpos = 0 while True:
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)