Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
O
OssoPI
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
nexlab
OssoPI
Commits
d5164046
Commit
d5164046
authored
Jun 06, 2015
by
Stefy Lanza (nextime / spora )
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added test script for OssoPI
parent
086688da
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
101 additions
and
0 deletions
+101
-0
ossopitest.py
ossopitest.py
+101
-0
No files found.
ossopitest.py
0 → 100644
View file @
d5164046
#!/usr/bin/env python
"""
OssoPI test script.
This is a test script to demostrate the use
of the OssoPI board on raspberry pi version 1B+ and 2
It must work out of the box on any recent raspbian install,
it uses python Rpi.GPIO library, installed by default on raspbian.
"""
import
sys
,
time
import
RPi.GPIO
as
GPIO
INPUTS
=
{
1
:
12
,
2
:
16
,
3
:
18
,
4
:
22
,
5
:
11
,
6
:
13
,
7
:
15
,
8
:
29
}
RELAYS
=
{
1
:
32
,
2
:
36
,
3
:
38
,
4
:
40
,
5
:
31
,
6
:
33
,
7
:
35
,
8
:
37
}
GPIO
.
setmode
(
GPIO
.
BOARD
)
def
printhelp
():
print
"Usage:"
,
sys
.
argv
[
0
],
"<input|relay>"
print
print
"Example:"
print
print
sys
.
argv
[
0
],
"input 3"
print
print
sys
.
argv
[
0
],
"relay 2"
print
def
initialize
():
for
i
in
INPUTS
.
values
():
GPIO
.
setup
(
i
,
GPIO
.
IN
)
#print i, GPIO.gpio_function(i)
#time.sleep(1)
for
i
in
RELAYS
.
values
():
GPIO
.
setup
(
i
,
GPIO
.
OUT
)
GPIO
.
output
(
i
,
GPIO
.
LOW
)
#print i, GPIO.gpio_function(i)
#time.sleep(1)
def
relay
(
rel
):
GPIO
.
output
(
RELAYS
[
rel
],
GPIO
.
HIGH
)
print
'RELAY'
,
rel
,
'IS NOW ON (ctrl+C to exit, on exit any relay will be switched off)'
while
1
:
time
.
sleep
(
1
)
def
digitalinp
(
inp
):
print
'INPUT'
,
inp
,
'IS'
,
'open'
if
GPIO
.
input
(
INPUTS
[
inp
])
else
'close'
print
print
'Waiting for a state change... (or ctrl+C to exit)'
GPIO
.
wait_for_edge
(
INPUTS
[
inp
],
GPIO
.
BOTH
)
time
.
sleep
(
.01
)
# Adafruit library needs a little time to detect right status
print
'INPUT'
,
inp
,
'IS NOW'
,
'open'
if
GPIO
.
input
(
INPUTS
[
inp
])
else
'close'
def
custom_excepthook
(
type
,
value
,
traceback
):
if
type
is
KeyboardInterrupt
:
print
'Exit.'
GPIO
.
cleanup
()
return
# do nothing
else
:
sys
.
__excepthook__
(
type
,
value
,
traceback
)
if
__name__
==
'__main__'
:
print
GPIO
.
RPI_INFO
try
:
if
(
len
(
sys
.
argv
)
>=
3
and
sys
.
argv
[
1
]
==
'relay'
and
int
(
sys
.
argv
[
2
])
in
range
(
1
,
9
)):
initialize
()
relay
(
int
(
sys
.
argv
[
2
]))
sys
.
exit
(
0
)
elif
(
len
(
sys
.
argv
)
>=
3
and
sys
.
argv
[
1
]
==
'input'
and
int
(
sys
.
argv
[
2
])
in
range
(
1
,
9
)):
initialize
()
digitalinp
(
int
(
sys
.
argv
[
2
]))
sys
.
exit
(
0
)
except
KeyboardInterrupt
:
GPIO
.
cleanup
()
sys
.
exit
(
0
)
printhelp
()
sys
.
exit
(
1
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment