Skip to content

Instantly share code, notes, and snippets.

@alon
Last active Aug 29, 2015
Embed
What would you like to do?
Raspberry pi gpio.
You can use bash:
root@bladderpi:~# echo 0 > /sys/class/gpio/export
root@bladderpi:~# echo out > /sys/class/gpio/gpio0/direction
root@bladderpi:~# echo 1 > /sys/class/gpio/gpio0/value
root@bladderpi:~# echo 0 > /sys/class/gpio/gpio0/value
root@bladderpi:~# while true; do (echo 0 > /sys/class/gpio/gpio0/value); (echo 1 > /sys/class/gpio/gpio0/value); done
You get ~0.5 KHz waves (i.e. 1 KHz toggles) from this (no nice), considerable jitter
You can use python:
from RPi.GPIO import setmode, setup, output, OUT, BOARD
setmode(BOARD)
setup(3, OUT)
val = 0
while True:
output(3, val)
val = 1 - val
You get ~50 KHz, considerable jitter
You can use c:
#include <fcntl.h>
int main(void)
{
int val;
int fd = open("/sys/class/gpio/export", O_WRONLY);
write(fd, "0", 1);
close(fd);
fd = open("/sys/class/gpio/gpio0/direction", O_WRONLY);
write(fd, "out", 3);
close(fd);
val = 0;
fd = open("/sys/class/gpio/gpio0/value", O_WRONLY);
while (1) {
write(fd, val ? "1" : "0", 1);
val = 1 - val;
}
close(fd);
return 0;
}
250 KHz, much less jitter but still considerable (perhaps real time execution will improve this)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment