01-31-2019, 02:41 AM
Greetings,
Well received my board yesterday. Tried to use GPIO in a small python code used library from https://github.com/Leapo/Rock64-R64.GPIO. But even the test file in it shows error. Looking for help need to finish my college project asap.
Well received my board yesterday. Tried to use GPIO in a small python code used library from https://github.com/Leapo/Rock64-R64.GPIO. But even the test file in it shows error. Looking for help need to finish my college project asap.
Code:
import R64.GPIO as GPIO
from time import sleep
print("Testing R64.GPIO Module...")
# Test Variables
print("")
print("Module Variables:")
print("Name Value")
print("---- -----")
print("GPIO.ROCK " + str(GPIO.ROCK))
print("GPIO.BOARD " + str(GPIO.BOARD))
print("GPIO.BCM " + str(GPIO.BCM))
print("GPIO.OUT " + str(GPIO.OUT))
print("GPIO.IN " + str(GPIO.IN))
print("GPIO.HIGH " + str(GPIO.HIGH))
print("GPIO.LOW " + str(GPIO.LOW))
print("GPIO.PUD_UP " + str(GPIO.PUD_UP))
print("GPIO.PUD_DOWN " + str(GPIO.PUD_DOWN))
print("GPIO.VERSION " + str(GPIO.VERSION))
print("GPIO.RPI_INFO " + str(GPIO.RPI_INFO))
# Set Variables
var_gpio_out = 16
var_gpio_in = 18
# GPIO Setup
GPIO.setwarnings(True)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(var_gpio_out, GPIO.OUT, initial=GPIO.HIGH) # Set up GPIO as an output, with an initial state of HIGH
GPIO.setup(var_gpio_in, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Set up GPIO as an input, pullup enabled
# Test Output
print("")
print("Testing GPIO Input/Output:")
var_gpio_state = GPIO.input(var_gpio_out) # Return state of GPIO
print("Output State : " + str(var_gpio_state)) # Print results
sleep(1)
GPIO.output(var_gpio_out, GPIO.LOW) # Set GPIO to LOW
# Test Input
var_gpio_state = GPIO.input(var_gpio_in) # Return state of GPIO
print("Input State : " + str(var_gpio_state)) # Print results
sleep(0.5)
# Test interrupt
print("")
print("Waiting 3 seconds for interrupt...")
var_interrupt = GPIO.wait_for_edge(var_gpio_in, GPIO.FALLING, timeout=3000)
if var_interrupt is None:
print("Timeout!")
else:
print("Detected!")
# Test PWM Output
p=GPIO.PWM(var_gpio_out, 60) # Create PWM object/instance
print("")
print("Testing PWM Output - DutyCycle - High Precision:")
print("60Hz at 50% duty cycle for 1 second")
p.start(50)
sleep(1)
print("60Hz at 25% duty cycle for 1 second")
p.ChangeDutyCycle(25)
sleep(1)
print("60Hz at 10% duty cycle for 1 second")
p.ChangeDutyCycle(10)
sleep(1)
print("60Hz at 1% duty cycle for 1 second")
p.ChangeDutyCycle(1)
sleep(1)
p.stop()
print("")
print("Testing PWM Output - DutyCycle - Low Precision:")
print("60Hz at 50% duty cycle for 1 second")
p.start(50, pwm_precision=GPIO.LOW)
sleep(1)
print("60Hz at 25% duty cycle for 1 second")
p.ChangeDutyCycle(25)
sleep(1)
print("60Hz at 10% duty cycle for 1 second")
p.ChangeDutyCycle(10)
sleep(1)
print("60Hz at 1% duty cycle for 1 second")
p.ChangeDutyCycle(1)
sleep(1)
p.stop()
print("")
print("Testing PWM Output - Frequency - Low Precision:")
print("60Hz at 50% duty cycle for 1 second")
p.start(50, pwm_precision=GPIO.LOW)
sleep(1)
print("30Hz at 50% duty cycle for 1 second")
p.ChangeFrequency(30)
sleep(1)
print("20Hz at 50% duty cycle for 1 second")
p.ChangeFrequency(20)
sleep(1)
print("10Hz at 50% duty cycle for 1 second")
p.ChangeFrequency(10)
sleep(1)
p.stop()
GPIO.cleanup([var_gpio_in, var_gpio_out]) # Perform cleanup on specified GPIOs
print("")
print("Test Complete")
----------------------------------------------------------------------------------------------------------------------------------------------------------
###########OUTPUT################
Testing R64.GPIO Module...
Module Variables:
Name Value
---- -----
GPIO.ROCK ROCK
GPIO.BOARD BOARD
GPIO.BCM BCM
GPIO.OUT out
GPIO.IN in
GPIO.HIGH 1
GPIO.LOW 0
GPIO.PUD_UP 0
GPIO.PUD_DOWN 1
GPIO.VERSION 0.6.3
GPIO.RPI_INFO {'P1_REVISION': 3, 'RAM': '1024M', 'REVISION': 'a22082', 'TYPE': 'Pi 3 Model B', 'PROCESSOR': 'BCM2837', 'MANUFACTURER': 'Embest'}
Error: Unable to export GPIO
Error: Unable to set GPIO direction
Error: Unable to export GPIO
Error: Unable to set GPIO direction
Testing GPIO Input/Output:
You must setup() the GPIO channel (BOARD 27) first
Output State : None
You must setup() the GPIO channel (BOARD 27) as an output first
You must setup() the GPIO channel (BOARD 32) first
Input State : None
Waiting 3 seconds for interrupt...
You must setup() the GPIO channel (BOARD 32) as an input first
Timeout!
You must setup() the GPIO channel (BOARD 27) as an output first
Testing PWM Output - DutyCycle - High Precision:
60Hz at 50% duty cycle for 1 second
Traceback (most recent call last):
File "R64-GPIO-test.py", line 71, in <module>
p.start(50)
File "/home/rock64/camcode/R64/_GPIO.py", line 351, in start
self.pwm_calc()
File "/home/rock64/camcode/R64/_GPIO.py", line 368, in pwm_calc
self.sleep_low = (1.0 / self.freq) * ((100 - self.dutycycle) / 100.0)
AttributeError: PWM instance has no attribute 'freq'