RPi_demo Source Code
RPi_demo_#GPIO_basic#_run_on_VisionFive.py
#import RPi.GPIO as GPIO # import RPi.GPIO module
#*******************************************************
#Note: above command must be replaced with command below
import VisionFive.gpio as GPIO # import VisionFive.gpio module
#*******************************************************
from time import sleep # let us have a delay
GPIO.setmode(GPIO.BCM) # choose BCM or BOARD
GPIO.setup(36, GPIO.OUT) # set GPIO27 as an output
try:
while True:
GPIO.output(36, 1) # set GPIO27 to 1/GPIO.HIGH/True
sleep(0.5) # wait half a second
GPIO.output(36, 0) # set GPIO27 to 0/GPIO.LOW/False
sleep(0.5) # wait half a second
except KeyboardInterrupt: # trap a CTRL + C keyboard interrupt
GPIO.cleanup() # reset all GPIO ports used by this program
RPi_demo_#PWM#_run_on_VisionFive.py
#import RPi.GPIO as GPIO
#*******************************************************
#Note: above command must be replaced with command below
import VisionFive.gpio as GPIO
#*******************************************************
from time import sleep
ledpin = 36 # PWM pin connected to LED
GPIO.setwarnings(False) # disable warnings
GPIO.setmode(GPIO.BOARD) # set pin numbering system
GPIO.setup(ledpin, GPIO.OUT)
pi_pwm = GPIO.PWM(ledpin, 1000) # create PWM instance with frequency
pi_pwm.start(0) # start PWM of required duty cycle
while True:
for duty in range(0, 101, 1):
pi_pwm.ChangeDutyCycle(duty) # provide duty cycle in the range 0-100
sleep(0.01)
sleep(0.5)
for duty in range(100, -1, -1):
pi_pwm.ChangeDutyCycle(duty)
sleep(0.01)
sleep(0.5)