【问题标题】:Multiple LCD displays over i2c with raspberry pi 2带有树莓派 2 的 i2c 上的多个 LCD 显示器
【发布时间】:2017-02-16 22:41:12
【问题描述】:

大家。我看了很多,第一次尝试通过 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 但没有成功。如果您需要,希望任何答案或要求提供更多详细信息,因为这是我的第一篇文章,我正在尽最大努力尝试询问。

【问题讨论】:

  • 你应该用 Visual C++ 或类似的东西编写物理控制器程序,然后在 MATLAB 中与你的应用程序接口

标签: python raspberry-pi i2c lcd


【解决方案1】:

经过一段时间和大量阅读后,我可以使用 node-red、try 和 exceptions 以及 MQTT 服务器找到非常有用的信息和实用程序。之后一切正常,只是调整了我在网络和手册上找到的所有内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-08
    • 2023-03-10
    相关资源
    最近更新 更多