first commit
This commit is contained in:
commit
b8768c3ff8
249 files changed
+38439
No files matched your search
@@ -0,0 +1,28 @@
|
||||
import sys
|
||||
import time
|
||||
import wiringpi
|
||||
from wiringpi import GPIO
|
||||
|
||||
I2C_ADDR = 0x38
|
||||
BASE = 100
|
||||
|
||||
wiringpi.wiringPiSetup()
|
||||
wiringpi.pcf8574Setup(BASE, I2C_ADDR)
|
||||
|
||||
i = 0
|
||||
while i < 8:
|
||||
wiringpi.pinMode(BASE + i, GPIO.OUTPUT)
|
||||
i += 1
|
||||
|
||||
wiringpi.pinMode(BASE + 0, GPIO.OUTPUT)
|
||||
|
||||
while True:
|
||||
try:
|
||||
wiringpi.digitalWrite(BASE + 0, GPIO.HIGH)
|
||||
time.sleep(1)
|
||||
wiringpi.digitalWrite(BASE + 0, GPIO.LOW)
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
print('\nExit')
|
||||
sys.exit(0)
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import sys
|
||||
import time
|
||||
import wiringpi
|
||||
from wiringpi import GPIO
|
||||
|
||||
I2C_ADDR = 0x48
|
||||
BASE = 64
|
||||
A0 = BASE+0
|
||||
|
||||
wiringpi.wiringPiSetup()
|
||||
wiringpi.pcf8591Setup(BASE, I2C_ADDR)
|
||||
while True:
|
||||
try:
|
||||
value = wiringpi.analogRead(A0)
|
||||
print("value: %d"%value)
|
||||
time.sleep(2)
|
||||
except KeyboardInterrupt:
|
||||
print('\nExit')
|
||||
sys.exit(0)
|
||||
@@ -0,0 +1,67 @@
|
||||
import wiringpi
|
||||
from wiringpi import GPIO
|
||||
|
||||
pin = 6
|
||||
|
||||
def getval(pin):
|
||||
tl=[]
|
||||
tb=[]
|
||||
wiringpi.wiringPiSetup()
|
||||
wiringpi.pinMode(pin, GPIO.OUTPUT)
|
||||
wiringpi.digitalWrite(pin, GPIO.HIGH)
|
||||
wiringpi.delay(1)
|
||||
wiringpi.digitalWrite(pin, GPIO.LOW)
|
||||
wiringpi.delay(25)
|
||||
wiringpi.digitalWrite(pin, GPIO.HIGH)
|
||||
wiringpi.delayMicroseconds(20)
|
||||
wiringpi.pinMode(pin, GPIO.INPUT)
|
||||
while(wiringpi.digitalRead(pin)==1): pass
|
||||
|
||||
for i in range(45):
|
||||
tc=wiringpi.micros()
|
||||
'''
|
||||
'''
|
||||
while(wiringpi.digitalRead(pin)==0): pass
|
||||
while(wiringpi.digitalRead(pin)==1):
|
||||
if wiringpi.micros()-tc>500:
|
||||
break
|
||||
if wiringpi.micros()-tc>500:
|
||||
break
|
||||
tl.append(wiringpi.micros()-tc)
|
||||
|
||||
tl=tl[1:]
|
||||
for i in tl:
|
||||
if i>100:
|
||||
tb.append(1)
|
||||
else:
|
||||
tb.append(0)
|
||||
|
||||
return tb
|
||||
|
||||
def GetResult(pin):
|
||||
for i in range(10):
|
||||
SH=0;SL=0;TH=0;TL=0;C=0
|
||||
result=getval(pin)
|
||||
|
||||
if len(result)==40:
|
||||
for i in range(8):
|
||||
SH*=2;SH+=result[i] # humi Integer
|
||||
SL*=2;SL+=result[i+8] # humi decimal
|
||||
TH*=2;TH+=result[i+16] # temp Integer
|
||||
TL*=2;TL+=result[i+24] # temp decimal
|
||||
C*=2;C+=result[i+32] # Checksum
|
||||
if ((SH+SL+TH+TL)%256)==C and C!=0:
|
||||
break
|
||||
else:
|
||||
print("Read Sucess,But checksum error! retrying")
|
||||
|
||||
else:
|
||||
print("Read failer! Retrying")
|
||||
break
|
||||
wiringpi.delay(200)
|
||||
return SH,SL,TH,TL
|
||||
|
||||
SH,SL,TH,TL=GetResult(pin)
|
||||
print("humi:",SH,SL,"temp:",TH,TL)
|
||||
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
#import sys
|
||||
import wiringpi
|
||||
from wiringpi import GPIO
|
||||
|
||||
PIN = 6
|
||||
|
||||
def oneWireReset(pin):
|
||||
wiringpi.pinMode(pin, GPIO.OUTPUT)
|
||||
wiringpi.digitalWrite(pin, GPIO.HIGH)
|
||||
wiringpi.digitalWrite(pin, GPIO.LOW)
|
||||
wiringpi.delayMicroseconds(500)
|
||||
wiringpi.digitalWrite(pin, GPIO.HIGH)
|
||||
wiringpi.delayMicroseconds(60)
|
||||
wiringpi.pinMode(pin, GPIO.INPUT)
|
||||
if not wiringpi.digitalRead(pin):
|
||||
ack = 1
|
||||
else:
|
||||
ack = 0
|
||||
wiringpi.delayMicroseconds(500)
|
||||
return ack
|
||||
|
||||
def writeBit(pin, bit):
|
||||
wiringpi.pinMode(pin, GPIO.OUTPUT)
|
||||
wiringpi.digitalWrite(pin, GPIO.LOW)
|
||||
wiringpi.delayMicroseconds(2)
|
||||
wiringpi.digitalWrite(pin, bit)
|
||||
wiringpi.delayMicroseconds(80)
|
||||
wiringpi.digitalWrite(pin, GPIO.HIGH)
|
||||
wiringpi.delayMicroseconds(1)
|
||||
|
||||
def oneWireSendComm(pin, byte):
|
||||
i = 0
|
||||
while i < 8:
|
||||
sta = byte & 0x01
|
||||
writeBit(pin, sta)
|
||||
byte >>= 1
|
||||
i += 1
|
||||
|
||||
def readBit(pin):
|
||||
wiringpi.pinMode(pin, GPIO.OUTPUT)
|
||||
wiringpi.digitalWrite(pin, GPIO.HIGH)
|
||||
wiringpi.digitalWrite(pin, GPIO.LOW)
|
||||
wiringpi.delayMicroseconds(2)
|
||||
wiringpi.digitalWrite(pin, GPIO.HIGH)
|
||||
|
||||
wiringpi.pinMode(pin, GPIO.INPUT)
|
||||
wiringpi.delayMicroseconds(2)
|
||||
|
||||
tmp = wiringpi.digitalRead(pin)
|
||||
wiringpi.delayMicroseconds(40)
|
||||
return tmp
|
||||
|
||||
def oneWireReceive(pin):
|
||||
i = 0
|
||||
k = 0
|
||||
while i < 8:
|
||||
j = readBit(pin)
|
||||
k = (j << 7) | (k >> 1)
|
||||
i += 1
|
||||
k = k & 0x00FF
|
||||
return k
|
||||
|
||||
def tempchange(lsb, msb):
|
||||
if (msb >= 0xF0):
|
||||
msb = 255 - msb
|
||||
lsb = 256 - lsb
|
||||
tem = -(msb*16*16 + lsb)
|
||||
else:
|
||||
tem = (msb*16*16 + lsb)
|
||||
temp = tem*0.0625
|
||||
print("Current Temp: %.2f"%(temp))
|
||||
|
||||
def main():
|
||||
wiringpi.wiringPiSetup()
|
||||
if oneWireReset(PIN):
|
||||
oneWireSendComm(PIN, 0xcc)
|
||||
oneWireSendComm(PIN, 0x44)
|
||||
if oneWireReset(PIN):
|
||||
oneWireSendComm(PIN, 0xcc)
|
||||
oneWireSendComm(PIN, 0xbe)
|
||||
lsb = oneWireReceive(PIN)
|
||||
msb = oneWireReceive(PIN)
|
||||
tempchange(lsb, msb)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import sys
|
||||
import time
|
||||
import wiringpi
|
||||
from wiringpi import GPIO
|
||||
|
||||
I2C_ADDR = 0x48
|
||||
BASE = 64
|
||||
A0 = BASE+0
|
||||
A1 = BASE+1
|
||||
|
||||
wiringpi.wiringPiSetup()
|
||||
wiringpi.pcf8591Setup(BASE, I2C_ADDR)
|
||||
|
||||
while True:
|
||||
try:
|
||||
i = 0
|
||||
while i < 2:
|
||||
if 0 == i:
|
||||
x = wiringpi.analogRead(A0)
|
||||
if 1 == i:
|
||||
y = wiringpi.analogRead(A1)
|
||||
i += 1
|
||||
print("X=%d Y=%d"%(x,y))
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
print('\nExit')
|
||||
sys.exit(0)
|
||||
@@ -0,0 +1,22 @@
|
||||
import sys
|
||||
import time
|
||||
import wiringpi
|
||||
from wiringpi import GPIO
|
||||
|
||||
PIN = 6
|
||||
|
||||
wiringpi.wiringPiSetup()
|
||||
wiringpi.pinMode(PIN, GPIO.OUTPUT)
|
||||
|
||||
while True:
|
||||
try:
|
||||
wiringpi.digitalWrite(PIN, GPIO.HIGH)
|
||||
print(wiringpi.digitalRead(PIN))
|
||||
time.sleep(1)
|
||||
wiringpi.digitalWrite(PIN, GPIO.LOW)
|
||||
print(wiringpi.digitalRead(PIN))
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
print("\nexit")
|
||||
sys.exit(0)
|
||||
|
||||
@@ -0,0 +1,320 @@
|
||||
import sys
|
||||
import time
|
||||
import wiringpi
|
||||
from wiringpi import GPIO
|
||||
|
||||
I2C_ADDR = 0x3c
|
||||
fd = 0
|
||||
yi = [' ',' ',' ',' ']
|
||||
zi = [
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//0
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//1
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//2
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//3
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//4
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//5
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//6
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//7
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//8
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//9
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//10
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//11
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//12
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//13
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//14
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//15
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//16
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//17
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//18
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//19
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//20
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//21
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//22
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//23
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//24
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//25
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//26
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//27
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//28
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//29
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//30
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//31
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//32
|
||||
|
||||
0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x00,0x00,0x00,0x00,#//33
|
||||
|
||||
0x00,0x10,0x0C,0x02,0x10,0x0C,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//34
|
||||
|
||||
0x00,0x40,0xC0,0x78,0x40,0xC0,0x78,0x00,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x00,#//35
|
||||
|
||||
0x00,0x70,0x88,0x88,0xFC,0x08,0x30,0x00,0x00,0x18,0x20,0x20,0xFF,0x21,0x1E,0x00,#//36
|
||||
|
||||
0xF0,0x08,0xF0,0x80,0x60,0x18,0x00,0x00,0x00,0x31,0x0C,0x03,0x1E,0x21,0x1E,0x00,#//37
|
||||
|
||||
0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x2C,0x19,0x27,0x21,0x10,#//38
|
||||
|
||||
0x00,0x12,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//39
|
||||
|
||||
0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,#//40
|
||||
|
||||
0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,#//41
|
||||
|
||||
0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,#//42
|
||||
|
||||
0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x0F,0x01,0x01,0x01,#//43
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x90,0x70,0x00,0x00,0x00,0x00,0x00,#//44
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x00,#//45
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,#//46
|
||||
|
||||
0x00,0x00,0x00,0x00,0xC0,0x38,0x04,0x00,0x00,0x60,0x18,0x07,0x00,0x00,0x00,0x00,#//47
|
||||
|
||||
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,#//48
|
||||
|
||||
0x00,0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,#//49
|
||||
|
||||
0x00,0x70,0x08,0x08,0x08,0x08,0xF0,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,#//50
|
||||
|
||||
0x00,0x30,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x18,0x20,0x21,0x21,0x22,0x1C,0x00,#//51
|
||||
|
||||
0x00,0x00,0x80,0x40,0x30,0xF8,0x00,0x00,0x00,0x06,0x05,0x24,0x24,0x3F,0x24,0x24,#//52
|
||||
|
||||
0x00,0xF8,0x88,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x20,0x20,0x20,0x11,0x0E,0x00,#//53
|
||||
|
||||
0x00,0xE0,0x10,0x88,0x88,0x90,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x20,0x1F,0x00,#//54
|
||||
|
||||
0x00,0x18,0x08,0x08,0x88,0x68,0x18,0x00,0x00,0x00,0x00,0x3E,0x01,0x00,0x00,0x00,#//55
|
||||
|
||||
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,#//56
|
||||
|
||||
0x00,0xF0,0x08,0x08,0x08,0x10,0xE0,0x00,0x00,0x01,0x12,0x22,0x22,0x11,0x0F,0x00,#//57
|
||||
|
||||
0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,#//58
|
||||
|
||||
0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,#//59
|
||||
|
||||
0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,#//60
|
||||
|
||||
0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x00,0x02,0x02,0x02,0x02,0x02,0x02,0x00,#//61
|
||||
|
||||
0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,#//62
|
||||
|
||||
0x00,0x70,0x48,0x08,0x08,0x88,0x70,0x00,0x00,0x00,0x00,0x30,0x37,0x00,0x00,0x00,#//63
|
||||
|
||||
0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x28,0x2F,0x28,0x17,0x00,#//64
|
||||
|
||||
0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,#//65
|
||||
|
||||
0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,#//66
|
||||
|
||||
0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,#//67
|
||||
|
||||
0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,#//68
|
||||
|
||||
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,#//69
|
||||
|
||||
0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,#//70
|
||||
|
||||
0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,#//71
|
||||
|
||||
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,#//72
|
||||
|
||||
0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,#//73
|
||||
|
||||
0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,#//74
|
||||
|
||||
0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,#//75
|
||||
|
||||
0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,#//76
|
||||
|
||||
0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x01,0x3E,0x01,0x3F,0x20,0x00,#//77
|
||||
|
||||
0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,#//78
|
||||
|
||||
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,#//79
|
||||
|
||||
0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,#//80
|
||||
|
||||
0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x28,0x28,0x30,0x50,0x4F,0x00,#//81
|
||||
|
||||
0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,#//82
|
||||
|
||||
0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,#//83
|
||||
|
||||
0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,#//84
|
||||
|
||||
0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,#//85
|
||||
|
||||
0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,#//86
|
||||
|
||||
0x08,0xF8,0x00,0xF8,0x00,0xF8,0x08,0x00,0x00,0x03,0x3E,0x01,0x3E,0x03,0x00,0x00,#//87
|
||||
|
||||
0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,#//88
|
||||
|
||||
0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,#//89
|
||||
|
||||
0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,#//90
|
||||
|
||||
0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,#//91
|
||||
|
||||
0x00,0x04,0x38,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,#//92
|
||||
|
||||
0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,#//93
|
||||
|
||||
0x00,0x00,0x04,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//94
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,#//95
|
||||
|
||||
0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//96
|
||||
|
||||
0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x19,0x24,0x24,0x12,0x3F,0x20,0x00,#//97
|
||||
|
||||
0x10,0xF0,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,#//98
|
||||
|
||||
0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,#//99
|
||||
|
||||
0x00,0x00,0x80,0x80,0x80,0x90,0xF0,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,#//100
|
||||
|
||||
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x24,0x24,0x24,0x24,0x17,0x00,#//101
|
||||
|
||||
0x00,0x80,0x80,0xE0,0x90,0x90,0x20,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,#//102
|
||||
|
||||
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,#//103
|
||||
|
||||
0x10,0xF0,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,#//104
|
||||
|
||||
0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,#//105
|
||||
|
||||
0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,#//106
|
||||
|
||||
0x10,0xF0,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x06,0x29,0x30,0x20,0x00,#//107
|
||||
|
||||
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,#//108
|
||||
|
||||
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,#//109
|
||||
|
||||
0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,#//110
|
||||
|
||||
0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,#//111
|
||||
|
||||
0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0x91,0x20,0x20,0x11,0x0E,0x00,#//112
|
||||
|
||||
0x00,0x00,0x00,0x80,0x80,0x00,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0x91,0xFF,0x80,#//113
|
||||
|
||||
0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,#//114
|
||||
|
||||
0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,#//115
|
||||
|
||||
0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x10,0x00,#//116
|
||||
|
||||
0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,#//117
|
||||
|
||||
0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x03,0x0C,0x30,0x0C,0x03,0x00,0x00,#//118
|
||||
|
||||
0x80,0x80,0x00,0x80,0x80,0x00,0x80,0x80,0x01,0x0E,0x30,0x0C,0x07,0x38,0x06,0x01,#//119
|
||||
|
||||
0x00,0x80,0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x20,0x31,0x0E,0x2E,0x31,0x20,0x00,#//120
|
||||
|
||||
0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x81,0x86,0x78,0x18,0x06,0x01,0x00,#//121
|
||||
|
||||
0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,#//122
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0xFC,0x02,0x02,0x00,0x00,0x00,0x00,0x01,0x3E,0x40,0x40,#//122
|
||||
|
||||
0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,#//124
|
||||
|
||||
0x02,0x02,0xFC,0x00,0x00,0x00,0x00,0x00,0x40,0x40,0x3E,0x01,0x00,0x00,0x00,0x00,#//125
|
||||
|
||||
0x00,0x02,0x01,0x02,0x02,0x04,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//126
|
||||
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,#//127
|
||||
]
|
||||
|
||||
def full_string(s):
|
||||
while len(s) < 16:
|
||||
s += ' '
|
||||
return s
|
||||
|
||||
def main():
|
||||
#init
|
||||
wiringpi.wiringPiSetup()
|
||||
fd = wiringpi.wiringPiI2CSetup(I2C_ADDR)
|
||||
if not fd:
|
||||
return False;
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xa1)
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xc8)
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0x8d)
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0x14)
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xa6)
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0x21)
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0x00)
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0x7f)
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xaf)
|
||||
|
||||
#clear oled
|
||||
for a in range(8):
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xb0 + a)
|
||||
for b in range(128):
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x40, 0x00)
|
||||
|
||||
while True:
|
||||
try:
|
||||
#get time
|
||||
yi[0] = full_string("++++OrangePi++++")
|
||||
#yi[1] = full_string(time.strftime("%m/%d %w"))
|
||||
yi[1] = full_string(time.strftime("%m/%d %a"))
|
||||
yi[2] = full_string(time.strftime("%H:%M"))
|
||||
yi[3] = full_string("SSD1306 I2C OLED")
|
||||
|
||||
#write
|
||||
for zt3 in range(4):
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xb0+(zt3*2))
|
||||
for zt4 in range(16):
|
||||
for zt in range(8):
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x40, zi[ord(yi[zt3][zt4])*16+zt])
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xb0+(zt3*2)+1)
|
||||
for zt4 in range(16):
|
||||
for zt in range(8):
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x40, zi[ord(yi[zt3][zt4])*16+zt+8])
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
print("\nexit")
|
||||
sys.exit(0)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import sys
|
||||
import time
|
||||
import wiringpi
|
||||
from wiringpi import GPIO
|
||||
|
||||
SIA = 9
|
||||
SIB= 10
|
||||
SW = 6
|
||||
|
||||
wiringpi.wiringPiSetup()
|
||||
wiringpi.pinMode(SW, GPIO.INPUT)
|
||||
wiringpi.pinMode(SIA, GPIO.INPUT)
|
||||
wiringpi.pinMode(SIB, GPIO.INPUT)
|
||||
|
||||
flag = 0
|
||||
resetflag = 0
|
||||
globalCount = 0
|
||||
|
||||
while True:
|
||||
try:
|
||||
lastSib = wiringpi.digitalRead(SIB)
|
||||
while not wiringpi.digitalRead(SW):
|
||||
resetflag = 1
|
||||
while not wiringpi.digitalRead(SIA):
|
||||
currentSib = wiringpi.digitalRead(SIB)
|
||||
flag =1
|
||||
|
||||
if resetflag:
|
||||
globalCount = 0
|
||||
resetflag = 0
|
||||
print ('Count reset\ncurrent = 0')
|
||||
continue
|
||||
if flag:
|
||||
if lastSib == 0 and currentSib == 1:
|
||||
print ('Anticlockwise rotation')
|
||||
globalCount += 1
|
||||
if lastSib == 1 and currentSib == 0:
|
||||
print ('clockwise rotation')
|
||||
globalCount -=1
|
||||
|
||||
flag =0
|
||||
print ('current = %s' % globalCount)
|
||||
except KeyboardInterrupt:
|
||||
print('\nExit')
|
||||
sys.exit(0)
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
import sys
|
||||
import time
|
||||
import wiringpi
|
||||
#from wiringpi import GPIO
|
||||
|
||||
I2C_ADDR = 0x68
|
||||
|
||||
def b2s(bcd, mask):
|
||||
bcd &= mask
|
||||
b1 = bcd & 0x0F
|
||||
b2 = ((bcd >> 4) & 0x0F)*10
|
||||
return b1 + b2
|
||||
|
||||
def decCompensation(units):
|
||||
unitsU = units%10
|
||||
if units >= 50:
|
||||
units = 0x50 + unitsU
|
||||
elif units >= 40:
|
||||
units = 0x40 + unitsU
|
||||
elif units >= 30:
|
||||
units = 0x30 + unitsU
|
||||
elif units >= 20:
|
||||
units = 0x20 + unitsU
|
||||
elif units >= 10:
|
||||
units = 0x10 + unitsU
|
||||
return units
|
||||
|
||||
def getHours():
|
||||
HH = time.strftime("%H")
|
||||
return decCompensation(int(HH))
|
||||
|
||||
def getMins():
|
||||
MM = time.strftime("%M")
|
||||
return decCompensation(int(MM))
|
||||
|
||||
def getSecs():
|
||||
SS = time.strftime("%S")
|
||||
return decCompensation(int(SS))
|
||||
|
||||
def getWeeks():
|
||||
WW = time.strftime("%w")
|
||||
return decCompensation(int(WW))
|
||||
|
||||
def getDays():
|
||||
DD = time.strftime("%d")
|
||||
return decCompensation(int(DD))
|
||||
|
||||
def getMons():
|
||||
MON = time.strftime("%m")
|
||||
return decCompensation(int(MON))
|
||||
|
||||
def getYear():
|
||||
YY = time.strftime("%Y")
|
||||
return decCompensation(int(YY))
|
||||
|
||||
def clear_register(fd):
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x02, 0b0) # hours
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x01, 0b0) # mins
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0b10000000) # secs
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x03, 0b0) # weeks
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x04, 0b0) # days
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x05, 0b0) # mons
|
||||
|
||||
def sys2rtcSet(fd):
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x02, getHours())
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x01, getMins())
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x00, getSecs()+0b10000000)
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x03, getWeeks())
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x04, getDays())
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x05, getMons())
|
||||
wiringpi.wiringPiI2CWriteReg8(fd, 0x06, getYear())
|
||||
|
||||
def read_register(fd):
|
||||
secs = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x00), 0x7F)
|
||||
mins = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x01), 0x7F)
|
||||
hours = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x02) - 0b10000000, 0x3F)
|
||||
week = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x03), 0x3F)
|
||||
day = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x04), 0x1F)
|
||||
mon = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x05), 0x07)
|
||||
year = b2s(wiringpi.wiringPiI2CReadReg8(fd, 0x06), 0xFF) + 1970
|
||||
print("week:%d mon:%d day:%d hours:%d mins:%d secs:%d year:%d"%(week,mon,day,hours,mins,secs,year))
|
||||
|
||||
def main():
|
||||
wiringpi.wiringPiSetup()
|
||||
fd = wiringpi.wiringPiI2CSetup(I2C_ADDR)
|
||||
if not fd:
|
||||
return False;
|
||||
while True:
|
||||
try:
|
||||
# clear RTC Register
|
||||
clear_register(fd)
|
||||
# set sys time to RTC Register
|
||||
sys2rtcSet(fd)
|
||||
# read RTC Register
|
||||
read_register(fd)
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
print("\nexit")
|
||||
sys.exit(0)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import sys
|
||||
import wiringpi
|
||||
from wiringpi import GPIO
|
||||
|
||||
LED = 6
|
||||
PIN = 16
|
||||
|
||||
wiringpi.wiringPiSetup()
|
||||
wiringpi.pinMode(LED, GPIO.OUTPUT)
|
||||
wiringpi.pinMode(PIN, GPIO.INPUT)
|
||||
|
||||
while True:
|
||||
try:
|
||||
if wiringpi.digitalRead(PIN):
|
||||
wiringpi.digitalWrite(LED, GPIO.LOW)
|
||||
else:
|
||||
wiringpi.digitalWrite(LED, GPIO.HIGH)
|
||||
except KeyboardInterrupt:
|
||||
print("\nexit")
|
||||
sys.exit(0)
|
||||
|
||||
Reference in new issue
Block a user