Python GPIO Library for the Rock64 (R64.GPIO)
#1
R64.GPIO aims to re-implement RPi.GPIO for the Rock64, with the goal of 100% code compatibility with the original Raspberry Pi module.

The following functions are currently implemented and working:
  • GPIO.setmode()
  • GPIO.setwarnings()
  • GPIO.setup()
  • GPIO.output()
  • GPIO.input()
  • GPIO.cleanup()
  • GPIO.PWM() (start, stop, ChangeFrequency, ChangeDutyCycle)
  • GPIO.wait_for_edge()
Not yet implemented, but planned for the near future:
  • Interrupts (GPIO.event_detect)
The latest version of R64.GPIO can be found on my github, here: https://github.com/Leapo/Rock64-R64.GPIO
I'm currently updating the library very frequently, so make sure to grab the latest code!

Importing the R64.GPIO module:
  • Download the entire "R64" folder from the repo, then place the "R64" folder in the same directory as the Python script you're working on.
  • Within your script, substitute the normal "import RPi.GPIO as GPIO" line for "import R64.GPIO as GPIO". Syntax for implemented functions should be identical to RPi.GPIO.
You may use GPIO.setmode() to select between ROCK, BOARD, and BCM numbering.
  • ROCK numbering is the default. I've created a reference spreadsheet of Rock64 pins, their functions, and their GPIO numbers, which you can find here: https://github.com/Leapo/Rock64-R64.GPIO...rence.xlsx
  • BOARD numbering works exactly like it does in RPi.GPIO. Simply input a pin number, and the correct ROCK GPIO will be selected for you.
  • BCM numbering attempts to emulate the physical layout of the Pi. This isn't perfect (some pins had to be mapped to the P5 header, can't use some pins with MicroSD, etc.), but I figured someone might find it useful.
  Reply
#2
Thanks for the update, I hope I get some time over the holidays to test some things....
Come have a chat in the Pine IRC channel >>
  Reply
#3
Just updated the llibrary with software PWM support.

PWM currently defaults to high-precision mode. This mode achieves the highest possible PWM timing accuracy, and works the same on all platforms/kernels, but uses a lot of CPU time due to the use of a busy-wait.
Low-precision mode is much lighter, but accuracy is kernel-dependent. You'll have to test low-precision mode to see if it's adequate for your needs.

Low-precision mode can be enabled by passing "pwm_precision=GPIO.LOW" as an argument for start()
  Reply
#4
thank you @Leapo , can't wait to test it out.... so excited
  Reply
#5
Hi @Leapo

I have this error..running
Code:
R64-GPIO-test.py



Code:
root@rock64:/home/Rock64-R64.GPIO# sudo python R64-GPIO-test.py
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 first
Output State : None
You must setup() the GPIO channel as an output first
You must setup() the GPIO channel first
Input State  : None
You must setup() the GPIO channel 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 58, in <module>
    p.start(50)
  File "/home/Rock64-R64.GPIO/R64/_GPIO.py", line 333, in start
    self.pwm_calc()
  File "/home/Rock64-R64.GPIO/R64/_GPIO.py", line 350, in pwm_calc
    self.sleep_low = (1.0 / self.freq) * ((100 - self.dutycycle) / 100.0)
AttributeError: PWM instance has no attribute 'freq'
root@rock64:/home/Rock64-R64.GPIO# uname -a
Linux rock64 4.4.114-rockchip-ayufan-193 #1 SMP Sun Mar 4 20:24:21 UTC 2018 aarch64 GNU/Linux

@Leapo

I update to 4.4.120, it fixed the issue with IO  error


Code:
Linux rock64 4.4.120-rockchip-ayufan-209 #1 SMP Mon Apr 2 16:05:07 UTC 2018 aarch64 GNU/Linux
  Reply
#6
(04-08-2018, 04:11 AM)i69fstop Wrote: I update to 4.4.120, it fixed the issue with IO  error

So it's all working now? Smile

I've updated the readme on the GitHub repo to include the test platform (Ayufan 0.5.15, Debian Jessie, 32bit). I can't guarantee that this library will work on newer/older releases until tested.
  Reply
#7
(04-09-2018, 10:29 AM)Leapo Wrote:
(04-08-2018, 04:11 AM)i69fstop Wrote: I update to 4.4.120, it fixed the issue with IO  error

So it's all working now? Smile

I've updated the readme on the GitHub repo to include the test platform (Ayufan 0.5.15, Debian Jessie, 32bit). I can't guarantee that this library will work on newer/older releases until tested.

Thanks and appreciate on your GitHub contribution :-)
  Reply
#8
Thanks a lot for the module. Smile 

It would be great if you add "GPIO.add_event_detect". I need this for a motion python script.
  Reply
#9
(04-09-2018, 10:29 AM)Leapo Wrote:
(04-08-2018, 04:11 AM)i69fstop Wrote: I update to 4.4.120, it fixed the issue with IO  error

So it's all working now? Smile

I've updated the readme on the GitHub repo to include the test platform (Ayufan 0.5.15, Debian Jessie, 32bit). I can't guarantee that this library will work on newer/older releases until tested.

Hi @Leapo,

Actually, it didn't work. There is no more error but when testing the the LED, it din't work.
  Reply
#10
I'd like to report my test on the interrupt of the GPIO, I wish this will be help for the development.


Hardware : Rock64 4GB (Rock64 V2 2017-0713)
Software : bionic-minimal-rock64-0.6.31-209-arm64 (kernel 4.4.120).


I tried interrupts with gpio-int-test.c on physical pin 16 (GPIO3_A5):
Code:
root@rock64:~# ./gpio-int-test 101

poll() GPIO 101 interrupt occurred
..
poll() GPIO 101 interrupt occurred

It had responses, but I found the followings :
  1. once gpio-int-test started, pin 16 had already been pulled-up internally to 3.2 V.
  2. it was difficult for me to pull-down the pin. With a 20K resistor pull-down to ground, interrupt was triggered repeatedly. With a 10K resistor, pin voltage became 0.443V, and it became more stable. When I opened the 10K resistor, interrupt was triggered.

The problem is : 
10K pull-down resistor is quite small, and even with the 10K resistor, the pin voltage is still 0.443V, not close 0V. There should be something wrong.
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Shocked Rock64 - Reboots after few minutes addezai 2 157 04-22-2021, 07:03 PM
Last Post: addezai
Question Hardware issues with Rock64 grobbs 10 834 04-08-2021, 05:24 AM
Last Post: t4_4t
  Rock64 Long Term stability ramprasad 4 1,370 03-16-2021, 07:23 PM
Last Post: Rocklobster
  Rock64 No Audio - Solved wbecks 11 14,302 03-15-2021, 03:15 PM
Last Post: lowry
  Safest way to send shutdown signal to headless Rock64 SMB server? bmurphr1 3 803 03-14-2021, 06:01 PM
Last Post: clach04
  Rock64 as a router (OpenWRT,etc) bob-anon 2 1,282 03-12-2021, 01:16 AM
Last Post: arkadione
  Rock64 enable 1-wire to read DS18B20 or Dallas temperature sensor Perry 2 976 02-12-2021, 08:02 PM
Last Post: Perry
  Will Mobian Run On Rock64? Porcupine 1 468 01-13-2021, 12:39 PM
Last Post: tophneal
  Rock64 v2 as Openmediavault server - buffers / shutdown problems helpmerock 2 829 12-29-2020, 09:46 AM
Last Post: helpmerock
  rock64, compile problems "illegal instruction", "memory fault" -> ddr_333Mhz? hunderteins 10 4,824 11-17-2020, 08:00 AM
Last Post: Johannes

Forum Jump:


Users browsing this thread: 1 Guest(s)