Ok, I've just tested this and it works.
But if you want to use it "root-less" you need to change referencies to "/dev/mem" to "/dev/gpiomem" in the library source before you install it.
I installed it like this
Code: Select all
git clone https://github.com/vsergeev/python-periphery.git
cd python-periphery
**** Need to edit mmio.py here **************
python setup.py install
Then I put a couple of LED on GPIO 5 and 6, and ran this code..
Code: Select all
#!/usr/bin/python
from periphery import MMIO
import time
# Open the GPIO register page
# This is the right address for a PI3
gpio_mmio = MMIO(0x3F200000, 0x1000)
# Read the current pin input/output states
bits = gpio_mmio.read32(0x00);
print "bits = ",bits
#Clear the bits for pins 5 and 6
bits &= ~( (7<<15) | (7<<18) )
print "bits = ",bits
gpio_mmio.write32(0x00,bits);
#Set pins 5 and 6 to outputs
bits |= (1<<15 | 1<<18)
print "bits = ",bits
gpio_mmio.write32(0x00,bits);
for num in range(1,20):
# Turn pins 5 and 6 ON (0x60 = 1<<5 + 1<<6)
gpio_mmio.write32(0x1C,0x60)
time.sleep(1)
# Turn pins 5 and 6 OFF
gpio_mmio.write32(0x28,0x60)
time.sleep(1)
# Tidy up the librayy handle
gpio_mmio.close()
The document at
https://www.raspberrypi.org/wp-content/ ... herals.pdf
Explains the port addresses and bit assignments for controling the pin directions (tables 6.3,6.4,6.5) and setting or clearing the pins (table 6.1)
HTH
PeterO