0
每個人。我已經看了很多,並第一次嘗試與兩臺液晶顯示器通過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但我沒有成功。希望任何答案或要求更多的細節,如果你需要他們,因爲這是我的第一篇文章,我正在盡力試圖問。
你應該用Visual C++或類似的東西編寫物理控制器程序,然後在MATLAB中與你的應用程序接口 – Moose