raspberry pi 2 通过 i2c 的多个 LCD 显示器
Multiple LCD displays over i2c with raspberry pi 2
各位。我看了很多,第一次尝试通过 i2c 与两个 LCD 显示器进行通信。一切正常,但现在我只想找到在任何 LCD 连接失败(接触不良、断电等)时初始化通信的方法。根据此代码,它们同时单独工作。但是,当我尝试断开与主线或他们的一些电线的连接时,一切都会出现问题。该程序继续正常工作,但大多数时候无法在 LED 显示屏上显示,我想知道我做错了什么,因为我已经阅读并查看了许多示例和问题,但仍然找不到答案.
这是 python 代码:
import lcddriver
from time import *
import sys
a=0
b=0
#https://www.youtube.com/watch?v=YUII39FzUb4 my reference
lcd = lcddriver.lcd(0x27) #Address firs display
print ("Display 1 done")
lcd2 = lcddriver.lcd(0x23) #Address second display
print ("Display 2 done")
sleep(1)
lcd.lcd_display_string(" ElectroMESH ", 1)
lcd.lcd_display_string("Prueba Raspberry y", 2)
#One part in the first display
lcd2.lcd_display_string("LCD 20x4 via i2c ", 3)
lcd2.lcd_display_string(" via I2C", 4)
#The other part in the second display
sleep(1)
for i in range(1,86400):
try:
a=1
b=0 #Here I'm trying to make an idea of display status flag
lcd.lcd_display_string(str(i), 4, 1)
a=0
b=1
lcd2.lcd_display_string(str(i+8), 2, 1) #i+8 to ensure differents texts
b=0
#Activate flag after indication
except IOError: #The action that runs after display is lost
print ("sistema desconectado a y b")
if a and b:
lcd = lcddriver.lcd(0x27)
print ("Sistema 0x27 inicializado if a y b")
a = 0
lcd2 = lcddriver.lcd(0x23)
print ("Sistema 0x23 inicializado if a y b")
b = 0
sys.exc_clear()
elif a==1 and b==0:
lcd = lcddriver.lcd(0x27)
print ("Sistema 0x27 inicializado if a")
a = 0
sys.exc_clear()
elif a==0 and b==1:
lcd2 = lcddriver.lcd(0x23)
print ("Sistema 0x23 inicializado if b")
b = 0
else:
print ("OK...conexion recuperada")
sys.exc_clear()
sleep(1) #Each second prints in the terminal to show results
print(i)
我试过 timeout_exceptions 但我没有成功。如果您需要,希望得到任何答案或要求提供更多详细信息,因为这是我的第一个 post,我正在尽最大努力尝试询问。
经过一段时间并大量阅读,我可以找到非常有用的信息和使用 node-red 的实用程序、尝试和异常以及 MQTT 服务器。在那之后一切正常,只是适应我在网络和手册上找到的所有内容。
各位。我看了很多,第一次尝试通过 i2c 与两个 LCD 显示器进行通信。一切正常,但现在我只想找到在任何 LCD 连接失败(接触不良、断电等)时初始化通信的方法。根据此代码,它们同时单独工作。但是,当我尝试断开与主线或他们的一些电线的连接时,一切都会出现问题。该程序继续正常工作,但大多数时候无法在 LED 显示屏上显示,我想知道我做错了什么,因为我已经阅读并查看了许多示例和问题,但仍然找不到答案.
这是 python 代码:
import lcddriver
from time import *
import sys
a=0
b=0
#https://www.youtube.com/watch?v=YUII39FzUb4 my reference
lcd = lcddriver.lcd(0x27) #Address firs display
print ("Display 1 done")
lcd2 = lcddriver.lcd(0x23) #Address second display
print ("Display 2 done")
sleep(1)
lcd.lcd_display_string(" ElectroMESH ", 1)
lcd.lcd_display_string("Prueba Raspberry y", 2)
#One part in the first display
lcd2.lcd_display_string("LCD 20x4 via i2c ", 3)
lcd2.lcd_display_string(" via I2C", 4)
#The other part in the second display
sleep(1)
for i in range(1,86400):
try:
a=1
b=0 #Here I'm trying to make an idea of display status flag
lcd.lcd_display_string(str(i), 4, 1)
a=0
b=1
lcd2.lcd_display_string(str(i+8), 2, 1) #i+8 to ensure differents texts
b=0
#Activate flag after indication
except IOError: #The action that runs after display is lost
print ("sistema desconectado a y b")
if a and b:
lcd = lcddriver.lcd(0x27)
print ("Sistema 0x27 inicializado if a y b")
a = 0
lcd2 = lcddriver.lcd(0x23)
print ("Sistema 0x23 inicializado if a y b")
b = 0
sys.exc_clear()
elif a==1 and b==0:
lcd = lcddriver.lcd(0x27)
print ("Sistema 0x27 inicializado if a")
a = 0
sys.exc_clear()
elif a==0 and b==1:
lcd2 = lcddriver.lcd(0x23)
print ("Sistema 0x23 inicializado if b")
b = 0
else:
print ("OK...conexion recuperada")
sys.exc_clear()
sleep(1) #Each second prints in the terminal to show results
print(i)
我试过 timeout_exceptions 但我没有成功。如果您需要,希望得到任何答案或要求提供更多详细信息,因为这是我的第一个 post,我正在尽最大努力尝试询问。
经过一段时间并大量阅读,我可以找到非常有用的信息和使用 node-red 的实用程序、尝试和异常以及 MQTT 服务器。在那之后一切正常,只是适应我在网络和手册上找到的所有内容。