多层液晶显示器覆盖i2c与覆盆子pi 2
问题描述:
每个人。我已经看了很多,并第一次尝试与两台液晶显示器通过i2c进行通信。一切工作正常,但现在我只想找到方法来初始化任何LCD上的通信,如果其中一个连接失败(接触不良,掉电等)。根据此代码,他们同时单独工作。但是,当我做一个测试试图断开主线或他们的一些电线时,一切都有问题。该程序继续工作没有问题,但在LED显示屏中显示是不可能的大多数时间,我想知道我做错了什么,因为我已经阅读,看了很多例子和问题,但仍然无法找到答案。多层液晶显示器覆盖i2c与覆盆子pi 2
这里的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但我没有成功。希望任何答案或要求更多的细节,如果你需要他们,因为这是我的第一篇文章,我正在尽力试图问。
答
经过一段时间,阅读了很多内容,我可以找到非常有用的信息和实用程序,其中使用了node-red,try和exceptions以及MQTT服务器。之后,一切运行良好,事情只是为了适应我在网络和手册中找到的一切。
你应该用Visual C++或类似的东西编写物理控制器程序,然后在MATLAB中与你的应用程序接口 – Moose