Skip to content
This repository was archived by the owner on Nov 12, 2019. It is now read-only.

Commit 1853d6a

Browse files
committed
Merge branch 'aequitas-rpi1b_gpio_fallback'
2 parents 9a77169 + 61c70b2 commit 1853d6a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Adafruit_DHT/Raspberry_Pi.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ def read(sensor, pin):
3131
# Signal no result could be obtained, but the caller can retry.
3232
return (None, None)
3333
elif result == common.DHT_ERROR_GPIO:
34-
raise RuntimeError('Error accessing GPIO.')
34+
raise RuntimeError(
35+
'Error accessing GPIO. If `/dev/gpiomem` does not exist '
36+
'run this program as root or sudo.')
3537
elif result != common.DHT_SUCCESS:
3638
# Some kind of error occured.
3739
raise RuntimeError('Error calling DHT test driver read: {0}'.format(result))

source/Raspberry_Pi/pi_mmio.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,15 @@ volatile uint32_t* pi_mmio_gpio = NULL;
3737

3838
int pi_mmio_init(void) {
3939
if (pi_mmio_gpio == NULL) {
40-
int fd = open("/dev/gpiomem", O_RDWR | O_SYNC);
40+
int fd;
41+
42+
// On older kernels user readable /dev/gpiomem might not exists.
43+
// Falls back to root-only /dev/mem.
44+
if( access( "/dev/gpiomem", F_OK ) != -1 ) {
45+
fd = open("/dev/gpiomem", O_RDWR | O_SYNC);
46+
} else {
47+
fd = open("/dev/mem", O_RDWR | O_SYNC);
48+
}
4149
if (fd == -1) {
4250
// Error opening /dev/gpiomem.
4351
return MMIO_ERROR_DEVMEM;

0 commit comments

Comments
 (0)