Subversion Repositories yaws

Rev

Rev 3 | Rev 10 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3 Rev 9
Line 17... Line 17...
17
#  
17
#  
18
#  You should have received a copy of the GNU General Public License
18
#  You should have received a copy of the GNU General Public License
19
#  along with this program; if not, write to the Free Software
19
#  along with this program; if not, write to the Free Software
20
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
#  MA 02110-1301, USA.
21
#  MA 02110-1301, USA.
22
#  
22
#
23
#  
23
#
-
 
24
import re, smbus
-
 
25
i2cbus = None
-
 
26
 
-
 
27
debug = true
-
 
28
 
-
 
29
# find out which revision of RPi we are running on
-
 
30
info = open('/proc/cpuinfo')
-
 
31
for line in info:
-
 
32
    line = line.rstrip()
-
 
33
    if re.search('Revision', line)
-
 
34
        x, x, rev = line.split()
-
 
35
        if rev = '0002':
-
 
36
            i2cbus = 0
-
 
37
        else:
-
 
38
            i2cbus = 1
-
 
39
 
-
 
40
# BME280 Temperature, Pressure & Humidity sensor
-
 
41
_bme280_probe_ = [0x76, 0x77]
-
 
42
bme280_address = None
-
 
43
 
-
 
44
# BH1750 Ambient light level sensor
-
 
45
_bh1750_probe_ = [0x5c, 0x23]
-
 
46
bh1750_address = None
-
 
47
 
-
 
48
# PCF8574 8 pin I/O device (wind direction sensor)
-
 
49
_pcf8574_probe_ = [0x20, 0x21, 0x22, 0x24, 0x25, 0x26, 0x27]
-
 
50
pcf8574_address = None
-
 
51
 
-
 
52
if i2cbus is not None:
-
 
53
    bus = smbus.SMBus(i2cbus)
-
 
54
 
-
 
55
    for device in _bme280_probe_:
-
 
56
        try:
-
 
57
            bus.read_byte(device)
-
 
58
            bme280_address = device
-
 
59
        except: # exception if read_byte fails
-
 
60
            pass
-
 
61
    for device in _bh1750_probe_:
-
 
62
        try:
-
 
63
            bus.read_byte(device)
-
 
64
            bh1750_address = device
-
 
65
        except: # exception if read_byte fails
-
 
66
            pass
-
 
67
    for device in _pcf8574_probe_:
-
 
68
        try:
-
 
69
            bus.read_byte(device)
-
 
70
            pcf8574_address = device
-
 
71
        except: # exception if read_byte fails
-
 
72
            pass
-
 
73
 
-
 
74
if debug:
-
 
75
    if i2cbus is not None:
-
 
76
        print('i2cbus=',i2cbus)
-
 
77
        if bme280_address is not None:
-
 
78
            print('bme280=', hex(bme280_address)) 
-
 
79
        else:
-
 
80
            print('bme280 not found')
-
 
81
        if bh1750_address is not None:
-
 
82
            print('bh1750=', hex(bh1750_address)) 
-
 
83
        else:
-
 
84
            print('bh1750 not found')
-
 
85
        if pcf8574_address is not None:
-
 
86
            print('pcf8574=', hex(pcf8574_address))
-
 
87
        else:
-
 
88
            print('pcf8574 not found')
-
 
89
    else:
-
 
90
        print('i2cbus not found, sensors not availabe')
-
 
91
# end of if debug