-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPKG-INFO
187 lines (132 loc) · 6.49 KB
/
PKG-INFO
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
Metadata-Version: 1.1
Name: pyA20
Version: 0.2.1
Summary: Control GPIO, I2C and SPI
Home-page: https://www.olimex.com/
Author: Stefan Mavrodiev
Author-email: support@olimex.com
License: MIT
Description: This package provide methods for controlling GPIO pins, I2C and SPI buses.
This is written for A20-OLinuXino-MICRO, but it can be used with other boards. If you do
this we cannot guarantee proper operation of the module. Before using this
package we recommend reading the article at olimex wiki:
https://www.olimex.com/wiki/A20-OLinuXino-MICRO
When using GPIO make sure that the desired gpio is not used by another periphery.
GPIO METHODS
============
init() - Make initialization of the module. Always must be called first.
getcfg() - Read current configuration of gpio.
setcfg() - Write configuration to gpio.
input() - Return current value of gpio.
output() - Set output value.
pullup() - Set pull-up/pull-down.
The available constants are:
NAME - EQUALS TO
==== =========
HIGH -> 1
LOW -> 0
INPUT -> 0
OUPTUT -> 1
PULLUP -> 1
PULLDOWN -> 2
The gpio are named two ways:
By port name: PH0, PG2, PE10, etc.
These can be imported from port module:
>>> from pyA20.gpio import port
>>> dir(port)
By connector name and pin number: gpio2p12, gpio3p8, lcdp18, uext1p3 and etc.
These can be imported from connector module:
>>> from pyA20.gpio import connector
>>> dir(connector)
Generally these constants are just an offset in the memory from the base GPIO address, so they can
be assigned to a number type variable.
>>> led = port.PH2
>>> print led
226
I2C METHODS
===========
init() - Make initialization of the module
open() - Begin communication with slave device
read() - Read from slave device
write() - Write data to slave device
close() - End communication with slave device
SPI METHODS
===========
open() - Open SPI bus with given configuration
read() - Read data from slave device without write
write() - Write data to slave device without read
xfer() - Do write and after that read
close() - Close SPI bus
Examples
========
GPIO::
#!/usr/bin/env python
from pyA20.gpio import gpio
from pyA20.gpio import port
from pyA20.gpio import connector
gpio.init() #Initialize module. Always called first
gpio.setcfg(port.PG9, gpio.OUTPUT) #Configure LED1 as output
gpio.setcfg(port.PG9, 1) #This is the same as above
gpio.setcfg(port.PE11, gpio.INPUT) #Configure PE11 as input
gpio.setcfg(port.PE11, 0) #Same as above
gpio.pullup(port.PE11, 0) #Clear pullups
gpio.pullup(port.PE11, gpio.PULLDOWN) #Enable pull-down
gpio.pullup(port.PE11, gpio.PULLUP) #Enable pull-up
while True:
if gpio.input(port.PE11) == 1:
gpio.output(port.PG9, gpio.LOW)
gpio.output(port.PG9, 0)
else:
gpio.output(port.PG9, gpio.HIGH)
gpio.output(port.PG9, 1)
I2C::
#!/usr/bin/env python
from pyA20 import i2c
i2c.init("/dev/i2c-2") #Initialize module to use /dev/i2c-2
i2c.open(0x55) #The slave device address is 0x55
#If we want to write to some register
i2c.write([0xAA, 0x20]) #Write 0x20 to register 0xAA
i2c.write([0xAA, 0x10, 0x11, 0x12]) #Do continuous write with start address 0xAA
#If we want to do write and read
i2c.write([0xAA]) #Set address at 0xAA register
value = i2c.read(1) #Read 1 byte with start address 0xAA
i2c.close() #End communication with slave device
SPI::
#!/usr/bin/env python
from pyA20 import spi
spi.open("/dev/spidev2.0")
#Open SPI device with default settings
# mode : 0
# speed : 100000kHz
# delay : 0
# bits-per-word: 8
#Different ways to open device
spi.open("/dev/spidev2.0", mode=1)
spi.open("/dev/spidev2.0", mode=2, delay=0)
spi.open("/dev/spidev2.0", mode=3, delay=0, bits_per_word=8)
spi.open("/dev/spidev2.0", mode=0, delay=0, bits_per_word=8, speed=100000)
spi.write([0x01, 0x02]) #Write 2 bytes to slave device
spi.read(2) #Read 2 bytes from slave device
spi.xfer([0x01, 0x02], 2) #Write 2 byte and then read 2 bytes.
spi.close() #Close SPI bus
It's important that you run your python script as root!
Changelog
=========
* pyA20 0.2.1 (30 JUN 2015)
* Fixed gpio1 connector constants
* Fixed issue with SPI xfer function
* pyA20 0.2.0 (02 SEP 2014)
* Updated to enable SPI and I2C control
* GPIO constant in separate modules
* Added example files
* Added support for Python3
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Education
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python
Classifier: Topic :: Home Automation
Classifier: Topic :: Software Development :: Embedded Systems