Skip to content

Instantly share code, notes, and snippets.

@alon
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alon/9291986 to your computer and use it in GitHub Desktop.
Save alon/9291986 to your computer and use it in GitHub Desktop.
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