# How do I use the /sys file to control the GPIO pins

I am using a Raspberry Pi 2 Model B v1.1. I have looked at the GPIO file in /sys but I don't understand how I actually turn on/ turn off GPIO ports or I set them to read in/read out, I am trying to do a project for college using my Raspberry PI and LISP but without this knowledge I am unable to do this, this is the library that is written for NewLIsp: https://github.com/gatesphere/raspi-gpio-newlisp/blob/master/raspi-gpio.lsp Some clarification of what actually needs to be written and where it needs to be written to send out/read in values on the GPIO ports is need, any help will be greatly appreciated.

• Have you seen elinux.org/… ? You may not need to be root to export/unexport, it depends on the way your system is set up. – joan Oct 22 '15 at 9:55
• Have you read any of the man files e.g. man gpio? Why Lisp? Is this just to make it more difficult - I though Lisp was only used with Emacs these days. – Milliways Oct 22 '15 at 10:23
• @Milliways gpio is an executable and calling it from another is clunky and expensive vs. using a kernel fs interface. Lisp is still used in university intro AI courses (at least where I am), and along with Haskell probably one of the most popular functional languages. For what it's worth, it's actually ahead of Haskell on the TIOBE index, which tracks current internet references (and if you look at the long term index there, was in the top 15 overall until 5 years ago). – goldilocks Oct 22 '15 at 14:30
• @goldilocks I do not want to start a language war, but AFAIK NewLisp is NOT included with Raspbian, and I have never heard of anyone using Lisp on a Pi. – Milliways Oct 22 '15 at 23:26
• I think you fired the first salvo, lol. I've (made (my share(of lisp jokes) before)). But since I'm a perl head, I understand what it is to be badly misunderstood, etc., occasionally by people who actually think no one uses that anymore either ("Why???"), so I was trying to save the OP the hassle of having to respond. By my reading of the Q lisp is a requirement for a college project (and in any case, college is one of those places people are allowed to take an interest in esoteric things for their own sake). – goldilocks Oct 22 '15 at 23:56

This is clearly and simply documented in the kernel docs. I will not bother to regurgitate it here.

Note that you can't use sudo with echo > because of redirection, but that does not impact what you are trying to do.

Anecdotely I'd say using if using high level stream functions doesn't work on sys/proc nodes, use lower level methods. I don't speak lisp so I don't know how relevant that is.

• Thank you :D I'll give this a read and see where I get. I want to write my own library to easily handle the I/O of the GPIO ports, but I've been confused as to how to actually do any of it. – Floofk Oct 22 '15 at 14:30

Here are some chunks of a program that might help - the whole thing is too big

import sys

### sys.path.insert(0, '/home/pi/pgms')

import RPi.GPIO as GPIO import time import datetime from datetime import timedelta import os import subprocess import glob import suntime

GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) ## Use board pin numbering

dirarr=["off","on"] pinarr=[7,8,10,11,12,13]

for i in range(0,6): ## Print current pin usage
fno = GPIO.gpio_function(pinarr[i]) ## get function number print ("Pin " + str(pinarr[i]) + " usage is " + pin_use[fno])

for i in range(0,2):
print (" " )

print ("Python version is %s " % str(sys.version[0:6]))

print ("GPIO version is %s " % GPIO.VERSION)

print ("Board revision is %s " % getbr()[:4])

print ("Program name is %s " % sys.argv[0])

## print("System path is ",sys.path)

for i in range(len(pinarr)): GPIO.setup((pinarr[i]), GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

• I appreciate the help but that's not LISP. – Floofk Nov 5 '15 at 14:22