Hello-
I have a question related to digital IO , and a (small) contribution.
From reading some of the posts on this board, I've figured out SOME of the
digital IO pinouts for the TS-7260 as accessed via sysfs. With Linux 2.6, and
sysfs, the mapping is like so:
Format: /sys/class/gpio/gpio# -> Pin #
8:1
9:2
10:3
11: ??
12: ??
13:6
14:7
15:8
where, for the TS-7260, the Pin # notation corresponds to the DIO1 header, with
the ethernet port on the right, like so:
------------------------------
9 | a | b | c | d | e | f | g
------------------------------
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8
------------------------------
My question is, how are pins 4 and 5 accessed? When I attempt to set them
up in what I would expect is the usual way (echo 11 > /sys/class/gpio/export )
, a device is not created as it is for the others.
My (small) contribution is a python class that eases access to those pins
which I have figured out the mapping for. Thanks to the help I received from
Petr, I was able to build myself a new kernel and filesystem, using Angstrom,
which includes Python. Subsequently I wrote some code and a tester which might
save someone else a little time if they are also trying to get this stuff
working in Python.
I uploaded the code to the "files" section of this board as
ts7260_gpio.tar.gz , and have also pasted it below here. ( I have no idea if
python code is readable / valid if copied and pasted off of this yahoo board ).
Thanks,
Erik
gpio.py:
#!/usr/bin/python
# Copyright 2011, Erik Dykema
# Licensed under the GNU GPL Version 3 , available at
# http://www.gnu.org/licenses/gpl-3.0.txt
import time, os
class ts7260_gpio_pin:
output_pin_to_gpio_socket_mapping = {1:"8",
2:"9",
3:"10",
6:"13",
7:"14",
8:"15",
}
pin_mode_mapping = {"output":"out",
"input":"in",
}
gpio_prefix = "/sys/class/gpio"
def __init__(self, output_pin=1, mode="output"):
# Should test to make sure the inputs are good here.
self.output_pin = output_pin
self.mode = mode
self.socket_mode = self.pin_mode_mapping[mode]
self.gpio_export_target = "%s/export" % (self.gpio_prefix)
self.gpio_socket_number =
self.output_pin_to_gpio_socket_mapping[output_pin]
self.gpio_socket_path = "%s/gpio%s" %(self.gpio_prefix,
self.gpio_socket_number)
self.value_target = "%s/value" % (self.gpio_socket_path)
self.direction_target ="%s/direction" % (self.gpio_socket_path)
# Can't "export" the device if it already exists
if not os.path.exists(self.gpio_socket_path):
# Signal sysfs to Export the GPIO device to the filesystem
self.write_character(self.gpio_socket_number,self.gpio_export_target)
# Setup the device for the specified mode
self.write_character(self.socket_mode,self.direction_target)
# It seems wise, where speed during setup is not of ultimate importance
# to allow the unit some time to adjust after changing output
# modes. This might be over cautious and could be deleted
time.sleep(.25)
def write_character(self, byte="1",target="/dev/null"):
#print "target = %s" %(target)
#print "byte = %s" %(byte)
# print the output to the target
fsock = open(target,'w')
print >>fsock, byte
#time.sleep(2)
fsock.close()
def on(self):
self.write_character("1",self.value_target)
def off(self):
self.write_character("0",self.value_target)
def blink(self, seconds=1):
self.on() # Turn on
time.sleep(seconds)
self.off() # Turn off
gpio_test.py:
#!/usr/bin/python
# Copyright 2011, Erik Dykema
# Licensed under the GNU GPL Version 3 , available at
# http://www.gnu.org/licenses/gpl-3.0.txt
from gpio import ts7260_gpio_pin
pin = dict()
for index in range(1,9):
print "Attempting to Set Up pin %s" %(index)
try:
pin[index] = ts7260_gpio_pin(index)
except:
print "Pin %s doesn't work yet." %(index)
for index in range(1,9):
if index in pin.keys():
print "Blinking pin %s" %(index)
pin[index].blink(.5)
------------------------------------
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ts-7000/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/ts-7000/join
(Yahoo! ID required)
<*> To change settings via email:
<*> To unsubscribe from this group, send an email to:
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|