pi@raspberrypi:~ $ sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: – -- – -- – -- – -- – -- – -- –
10: – -- – -- – -- – -- – -- – -- – -- – --
20: – -- – -- – -- – 27 – -- – -- – -- – --
30: – -- – -- – -- – -- – -- – -- – -- – --
40: – -- – -- – -- – -- – -- – -- – -- – --
50: – -- – -- – -- – -- – -- – -- – -- – --
60: – -- – -- – -- – -- – -- – -- – -- – --
70: – -- – -- – -- – --
pi@raspberrypi:~ $
#!/user/bin/env python
import smbus2
import time
import sys
import LCD1602 as LCD
import logx
import logging
if __name__ == '__main__':
LCD.init_lcd()
time.sleep(2)
LCD.print_lcd(0,0,'Jason & dinosaur')
LCD.print_lcd(1,1,'local time')
logging.info('wait 2 seconds')
LCD.turn_light(1)
logging.info('turn on BLight')
time.sleep(5)
while True:
nowtime = time.strftime('%m-%d %H:%M:%S',time.localtime(time.time()))
hourtime = time.strftime('%H',time.localtime(time.time()))
mintime = time.strftime('%M',time.localtime(time.time()))
sectime = time.strftime('%S',time.localtime(time.time()))
LCD.print_lcd(1,1,nowtime)
if mintime == '59':
if sectime == '00':
LCD.turn_light(1)
elif sectime == '59':
LCD.turn_light(0)
time.sleep(1)
运行结果:显示正常,程序的时间输出每9-10秒跳一秒,需要调整为time.sleep(0.9),与CPU执行每条指令的速度有关,树莓派B型速度慢。