OpenSprinkler › Forums › Hardware Questions › OpenSprinkler Pi (OSPi) › Does anyone have a working I2C LCD working?
Tagged: I2C, LCD, raspberry pi
- This topic has 6 replies, 2 voices, and was last updated 3 months ago by RonRN18.
-
AuthorPosts
-
May 4, 2023 at 8:08 am #75524
Vernon GranerParticipantHey Folks!
I am new to Open Sprinkler Pi. I have the pi installed and working and I can get the OpenSprinkler web site. So far, so good ππ Next, I am trying to get the 2×16 LCD I2C display to work. I started by following the steps listed on this web site:
https://github.com/stanoba/ospiLCD
And it was a bumpy ride ΰ² _ΰ² – Specifically, the commands as listed don’t work anymore due to changes in the raspberry PI OS. Then, when I finally got the install to work, when I run the script, I get this error:
pi@ospi:~ $ ./ospiLCD.py
Traceback (most recent call last):
File “/home/pi/./ospiLCD.py”, line 50, in <module>
ja = get_data(api_url)
File “/home/pi/./ospiLCD.py”, line 46, in get_data
variables = json.loads(data, object_hook=lambda d: namedtuple(‘X’, d.keys())(*d.values()))
File “/usr/lib/python3.9/json/__init__.py”, line 359, in loads
return cls(**kw).decode(s)
File “/usr/lib/python3.9/json/decoder.py”, line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “/usr/lib/python3.9/json/decoder.py”, line 353, in raw_decode
obj, end = self.scan_once(s, idx)
File “/home/pi/./ospiLCD.py”, line 46, in <lambda>
variables = json.loads(data, object_hook=lambda d: namedtuple(‘X’, d.keys())(*d.values()))
File “/usr/lib/python3.9/collections/__init__.py”, line 393, in namedtuple
raise ValueError(‘Type names and field names cannot be a ‘
ValueError: Type names and field names cannot be a keyword: ‘pass’
pi@ospi:~ $So, I then followed the steps shown on the mqtt version of the script with is located here:
https://github.com/sirkus7/ospiLCD-mqtt
This was also quite a bumpy ride. When, again, I *finally* got the script to run, it did actually update the LCD display to say:
Connecting to
MQTT broker…But then it displays the following error:
pi@ospi:~ $ ./ospiLCD-mqtt.py
Traceback (most recent call last):
File “/home/pi/./ospiLCD-mqtt.py”, line 257, in <module>
client.connect(mqttAddress, mqttPort, 60)
File “/usr/local/lib/python3.9/dist-packages/paho/mqtt/client.py”, line 912, in connect
self.connect_async(host, port, keepalive,
File “/usr/local/lib/python3.9/dist-packages/paho/mqtt/client.py”, line 979, in connect_async
if port <= 0:
TypeError: ‘<=’ not supported between instances of ‘str’ and ‘int’
pi@ospi:~ $So, it seems that changes in the versions of Python have made it so neither of these scripts work anymore. Unfortunately, I’m not a python programmer so I don’t have the debugging skills necessary to diagnose these errors, but I sure would like to have a working LCD. Does anyone have any pointers they can share on how I might be able to make this work..?
May 16, 2024 at 11:08 am #78873
RonRN18ParticipantI realize the original posting was a year ago and I too am not very good at Python but I’m muddling through with altering the code of the original “ospiLCD.py” code to address changes from what I believe was Python2 to Python3. I’ve made a few changes that were fairly easy, such as the requirement that a print command have the line to be printed within parenthesis. For example, you used to be able to say { print “Hello World” } but it now must be { print(“Hello World”) }. Another fix was a change in a variable name… at the moment, I forgot it but I saw it discussed in another thread. My current issue I’m trying to figure out is about obtaining the device’s IP address. Somehow, there are issues about the format and type of data that is stored in the variable. I believe that the original variable calls for the IP address and verifies that it is at least 7 characters long, to determine if it is a real IP address or not. Then it needs to put that number in a print command but the number must be converted from I believe an integer to a string so that it can be concatenated on a line of text with other characters. I will be using the 20-character/4-line display (2004a).
May 16, 2024 at 11:40 am #78875
Vernon GranerParticipantThanks for making an update to t his thread! I would love to test out the changes but I ended up removing the LCD and mounting the unit without it. If you do get this to work, please update this thread as it Might be worth it to revisit this in the future! ππ
May 23, 2024 at 12:38 am #78943
RonRN18ParticipantI have finished my enclosure that includes the LCD, https://www.thingiverse.com/thing:6632131, so now I’m trying to focus on getting the display to actually work. I see that “Sirkus7” made a correction in the MQTT version of his Python code, which is line #75, which reads:
data = data.replace("\"pass\":", "\"password\":") # Replace protected keyword "pass" with acceptable term "password"
I have inserted this in between lines #45 & #46. If you were to export your OpenSprinkler settings to file, you will see that it is a JSON file and in that file, there are the MQTT server username and password. Instead of using the word “password”, it is shortened to “pass”, which is a protected word. In line 45 of “ospiLCD.py”, it basically loads that JSON into a variable called “data”. This line does a “find & replace” of the word “pass:” with the word “password:” so that it does not create the ValueError. Unfortunately, inserting that line doesn’t solve everything. I now get at TypeError.
TypeError: a bytes-like object is required, not 'str'
Despite changing the word “pass:” to “password:” something within the JSON appears as a string when it should be a “byte-like object”. I am currently at a loss as to how to fix this.
May 26, 2024 at 6:56 pm #78978
RonRN18ParticipantI’ve made a baby step forward in getting
ospiLCD-mqtt.py
to work. It still doesn’t work but I’ve gotten it to move forward to the next problem. TheTypeError: a bytes-like object is required, not 'str'
issue is related to the variable namedmqttPort
. On line #32, the script uses quotations around the port number, which makes the value a string-type variable as opposed to a number. so changing line 32 from reading:mqttPort = "1883"
tomqttPort = 1883
gets rid of the error. Unfortunately, it still does not work. I now get:`
/home/bigron/./ospiLCD-mqtt.py:256: DeprecationWarning: Callback API version 1 is deprecated, update to latest version
client = mqtt.Client()
[Connected with result code 5]
[Connected with result code 5]
`
The LCD display has changed from:
`
Connecting to
MQTT brokerβ¦
`
to:
`
MQTT Connected
Requesting Info
`
As you can see from the error now seen,
[Connected with result code 5]
, it is a connection refused error. I believe that it is related to it trying to use MQTT version 1, which has been deprecated. I am learning how to fix this issue now. I just thought I’d share the progress I’ve made.June 12, 2024 at 3:19 pm #79179
RonRN18ParticipantI ***finally*** have a working LCD that automatically updates itself (every 30 seconds) with the latest status of OpenSprinkler. You can see my work at [github](https://github.com/RonRN18/ospiLCD-mqtt). My software may not be the most elegant and I found that I got MUCH better help from ChatGPT than from the Python forums. I found that I was met with rude attitudes when asking for help on the Python forums and people assumed I had more knowledge than I do. ChatGPT has its issues too. It was adding irrelevant variables while removing important variables but I could tell, in context, how to accomplish what I was trying to do. In my
get_data
function, I named many more variables than I needed because I have a plan to change my code to show other information in the future. The current display is equivalent to the microcontroller version and many of the items on the display are drastically shortened so that it all fits on the display, all the time. My thought is to change it up a bit and allow for lines that scroll. For example, instead of the line saying something like “MC:1_________”, I could have it say: “Front Yard is running”. That is greater than 20 characters long, so the line will be buffered and scrolled along the line. It would determine which station is running and instead of just showing the station number, it would show the station name… however long it may be. One of my favorite features of OpenSprinkler in general is the departure of needing to know what each station number is and continue referring to it as a number and instead, using logical names for each zone. -
AuthorPosts
- You must be logged in to reply to this topic.
OpenSprinkler › Forums › Hardware Questions › OpenSprinkler Pi (OSPi) › Does anyone have a working I2C LCD working?