-
Notifications
You must be signed in to change notification settings - Fork 0
/
generalTest.py
157 lines (100 loc) · 2.55 KB
/
generalTest.py
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
#
#
# SIXFAB GPRS IoT Shield Test code v0.1
# Saeed Johar
# 30 Nov 2017
#
#
import serial
import SDL_Pi_HDC1000
import time
import Adafruit_ADS1x15
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
#----------------------Sheild Power & Status Test------
statusPin = 13
power_key = 12
GPIO.setup(statusPin, GPIO.IN)
GPIO.setup(power_key, GPIO.OUT)
def turnModuleOn():
GPIO.output(power_key,1)
time.sleep(2)
GPIO.output(power_key,0)
time.sleep(2)
def checkStatus():
status = GPIO.input(statusPin)
if status==0:
print "Module turned OFF"
else:
print "Module turned ON"
time.sleep(0.1)
return status
status = checkStatus()
if status==0:
turnModuleOn()
#-------------Connectivity Test-----------------------
port = "/dev/ttyS0"
ser = serial.Serial(port, baudrate=115200, timeout=0.5)
print "---------Checking SIM and Connection---------"
#time.sleep(0.5)
ser.write('AT\r')
print ser.readline()
print ser.readline()
time.sleep(1)
ser.write('AT+CPIN?\r')
print ser.readline()
print ser.readline()
ser.close()
time.sleep(0.1)
# -----------Temperature and Humidity Sensor --------------------
hdc = SDL_Pi_HDC1000.SDL_Pi_HDC1000()
print "Temperature = %3.1f C" % hdc.readTemperature()
print "Humidity = %3.1f %%" % hdc.readHumidity()
#---------------------LUX Sensor--------------------------
adc = Adafruit_ADS1x15.ADS1015(address=0x49, busnum=1)
rawLux = adc.read_adc(2, gain=1)
lux = rawLux*100/1580
print "RAW LUX : %d" %rawLux
print "LUX : %d" %lux
time.sleep(1)
#----------------------ADC (ADS1015)----------------------
print "----------Printing ADS1015 values----------"
adcValues = [0]*4
for i in range(0,4):
adcValues[i] = adc.read_adc(i, gain=1)
print "ADC Ch%d : %d" %(i,adcValues[i])
#------------------------RELAY TEST------------------------
relay1 = 21
relay2 = 26
GPIO.setup(relay1,GPIO.OUT)
GPIO.setup(relay2,GPIO.OUT)
print "----------RELAY TEST----------"
GPIO.output(relay1, True)
print "RELAY1: ON"
time.sleep(1)
GPIO.output(relay1, False)
print "RELAY1: OFF"
time.sleep(2);
GPIO.output(relay2, True)
print "RELAY2: ON"
time.sleep(1)
GPIO.output(relay2, False)
print "RELAY2: OFF"
time.sleep(2)
#---------------------OPTO TEST-----------------------------
opto1 = 20
opto2 = 19
GPIO.setup(opto1,GPIO.IN)
GPIO.setup(opto2,GPIO.IN)
print "----------OPTO TEST----------"
readOpto1 = GPIO.input(opto1)
readOpto2 = GPIO.input(opto2)
if (readOpto1 == 1):
print "INPUT1: LOW"
else:
print "INPUT1: HIGH"
if (readOpto2 == 1):
print "INPUT2: LOW"
else:
print "INPUT2: HIGH"