Moode Forum
I2C LCD display? differences from old 3.8? - Printable Version

+- Moode Forum (https://moodeaudio.org/forum)
+-- Forum: Community (https://moodeaudio.org/forum/forumdisplay.php?fid=18)
+--- Forum: General Discussion (https://moodeaudio.org/forum/forumdisplay.php?fid=21)
+--- Thread: I2C LCD display? differences from old 3.8? (/showthread.php?tid=7191)



I2C LCD display? differences from old 3.8? - lcipher3 - 12-11-2024

Hi!  I've been using MoodeAudio at version 3.8 and now I'm trying to update to version 9.1.5

I successfully created the USB (I previously enabled USB boot) with the image and the player boots and I can access the IP address and SSH into the Raspberry Pi 3B that it's running on.  Great.

My help is needed to get my LCD I2C display working.

I had an IC2 2x40 display running on the 3.8 version.  I had some python lcd code that was provided by Matt Hawkins (i2c-40x2-lcd.py I think).  To get it to run I had to first enable the I2C in the PI
  • sudo raspi-config
  • “I2C Enable/Disable automatic loading”
then install I2C tools and SMBUS
  • sudo apt-get install i2c-tools
  • sudo apt-get install python-smbus
Then edit rc.local (sudo nano /etc/rc.local) to add the python command to run the script just before the line that is "exit 0"
  • sudo python /home/pi/i2c-40x2-lcd.py
  • change permissions to rwxr-xr-x
This starts the script at boot and then it will update using "currentsong.txt"

works great...

----------------------------

So is that still the process on version 9 or is there a more streamlined way to get the I2C display to update?  Do I still need SMBUS and i2c-tools and are they still out there for this version (3.11?) of python?

Pointers to any setups or previous info would be appreciated.  I looked but not too much on the older LCD type displays.  I know its quite a leap from 3 to 9 versions so trying to avoid missing the simple way to do things!

Any help appreciated.


RE: I2C LCD display? differences from old 3.8? - Tim Curtis - 12-11-2024

Below is the default 9.1.5 /boot/firmware/config.txt
It shows I2C bus enabled: dtparam=i2c_arm=on

Code:
#########################################
# This file is managed by moOde
#########################################

# Device filters
[cm4]
otg_mode=1
[pi4]
hdmi_force_hotplug:0=1
hdmi_force_hotplug:1=1
hdmi_enable_4kp60=0
[all]
dtoverlay=vc4-kms-v3d
max_framebuffers=2
display_auto_detect=1
disable_fw_kms_setup=1
arm_64bit=1

# General settings
arm_boost=0
disable_splash=1
disable_overscan=1
hdmi_drive=2
hdmi_blanking=1
hdmi_force_edid_audio=1
hdmi_force_hotplug=1
hdmi_group=0
dtparam=i2c_arm=on
dtparam=i2s=on
dtparam=audio=on

# Do not alter this section
# Integrated adapters
#dtoverlay=disable-bt
#dtoverlay=disable-wifi
# Audio overlays
#dtoverlay=none
#dtoverlay=force_eeprom_read=0
# PCI Express
#dtparam=pciex1
#dtparam=pciex1_gen=3
# Pi Touch1
#dtoverlay=rpi-backlight
#dtoverlay=vc4-kms-dsi-7inch,invx,invy
# Fan speed
#dtparam=fan_temp0=50000,fan_temp0_hyst=5000,fan_temp0_speed=75

And it looks like the python3-smbus and i2c-tools packages are already present

Code:
pi@moode9:~ $ dpkg -l | grep python3-smbus
pi@moode9:~ $ dpkg -l | grep python3-smbus
ii  python3-smbus:arm64                  4.3-2+b3                               arm64        Python 3 bindings for Linux SMBus access through i2c-dev
ii  python3-smbus2                       0.4.2-1                                arm64        another pure Python implementation of the python-smbus package
pi@moode9:~ $

pi@moode9:~ $ dpkg -l | grep i2c-tools
ii  i2c-tools                            4.3-2+b3                               arm64        heterogeneous set of I2C tools for Linux
pi@moode9:~ $



RE: I2C LCD display? differences from old 3.8? - lcipher3 - 12-11-2024

thanks ! - so looks like I should be able to add the line (sudo python /home/pi/i2c-40x2-lcd.py) to the rc.local and run my i2c-40x2-lcd.py

How does the moode config for "other peripherals" "lcd updated" and the "starter scrip" in /var/local/www/commandw/ directory work?  Is this another way to do it?


RE: I2C LCD display? differences from old 3.8? - Tim Curtis - 12-11-2024

As long as i2c-40x2-lcd.py runs under python 3 you should be ok.

The LCD updater and its companion script can be used to update an LCD but you would need to figure out whats needed in the companion script. This script can't contain any while(true) loops since its being executed by an upstream system-level while (condition) process (inotifywait).

/var/www/daemon/lcd-updater.sh
Code:
#!/bin/bash
#
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright 2014 The moOde audio player project / Tim Curtis
#

eval "/var/local/www/commandw/lcd_updater.py"

while true; do
    inotifywait -e close_write /var/local/www/currentsong.txt
    eval "/var/local/www/commandw/lcd_updater.py"
done > /dev/null 2>&1 &



RE: I2C LCD display? differences from old 3.8? - lcipher3 - 12-12-2024

Thanks again - I have it working as before with my current script - had to update a few commands for current python (looks like the previous was python 2).

I'll probably see if I can write my own version and use the companion script just for fun.  The code you just posted answers what I was wondering on how the lcd_updater.py gets triggered.

The new moode version has quite a bit more!  Looking forward to exploring all the new features


RE: I2C LCD display? differences from old 3.8? - lcipher3 - 12-13-2024

Curious - what's the difference between using:

/var/local/www/currentsong.txt
/home/pi/lcd.txt


RE: I2C LCD display? differences from old 3.8? - Tim Curtis - 12-13-2024

Its just a file created by the stub script
/var/local/www/comandw/lcd_updater.py

You would put your own code that parses currentsong.txt and writes to your display in this script file
Code:
#!/usr/bin/python3
#
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright 2014 The moOde audio player project / Tim Curtis
#

#
# Stub script for lcd-updater.sh daemon
#

import subprocess

homeDir = subprocess.run(['ls', '/home/'], stdout=subprocess.PIPE).stdout.decode('utf-8').strip()
with open("/var/local/www/currentsong.txt") as file1:
   with open("/home/" + homeDir + "/lcd.txt", "w") as file2:
       for line in file1:
           file2.write(line)



RE: I2C LCD display? differences from old 3.8? - Nutul - 12-13-2024

(12-13-2024, 03:14 PM)Tim Curtis Wrote: Its just a file created by the stub script
/var/local/www/comandw/lcd_updater.py

You would put your own code that parses currentsong.txt and writes to your display in this script file
Code:
#!/usr/bin/python3
#
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright 2014 The moOde audio player project / Tim Curtis
#

#
# Stub script for lcd-updater.sh daemon
#

import subprocess

homeDir = subprocess.run(['ls', '/home/'], stdout=subprocess.PIPE).stdout.decode('utf-8').strip()
with open("/var/local/www/currentsong.txt") as file1:
   with open("/home/" + homeDir + "/lcd.txt", "w") as file2:
       for line in file1:
           file2.write(line)

I do admit that Python is not my strength, but...
why copy a file line by line, when a cp would suffice???
Or indeed the culprit is "replace the line-copy cycle with your own code"...?


RE: I2C LCD display? differences from old 3.8? - lcipher3 - 12-13-2024

Ah got it - it's just using currentsong.txt and showing an example.

>>why copy a file line by line
because you would need to process the currentsong.txt line by line to extract whatever you want to display, so read a line, strip whitespace, the = sign, fix "special characters" like ã etc depending on your display, etc

For my 2x40 display I just use the artist (album) and title. And I check "state" to display if stopped, pause, etd

The currentsong.txt looks like this:
Code:
file=USB/Elements/John Coltrane/Atlantic Recordings/disc4/4-01 Village Blues.flac
artist=John Coltrane
album=The Heavyweight Champion: The Complete Atlantic Recordings
title=Village Blues
coverurl=/coverart.php/USB%2FElements%2FJohn%20Coltrane%2FAtlantic%20Recordings%2Fdisc4%2F4-01%20Village%20Blues.flac
track=1
date=199500
composer=
encoded=FLAC 16/44.1 kHz, 2ch
bitrate=791 kbps
outrate=PCM 24/44.1 kHz, 2ch
volume=0
mute=0
state=play



RE: I2C LCD display? differences from old 3.8? - Tim Curtis - 12-13-2024

(12-13-2024, 05:33 PM)lcipher3 Wrote: Ah got it - it's just using currentsong.txt and showing an example.

>>why copy a file line by line
because you would need to process the currentsong.txt line by line to extract whatever you want to display, so read a line, strip whitespace, the = sign, fix "special characters" like ã etc depending on your display, etc

For my 2x40 display I just use the artist (album) and title.  And I check "state" to display if stopped, pause, etd

The currentsong.txt looks like this:
Code:
file=USB/Elements/John Coltrane/Atlantic Recordings/disc4/4-01 Village Blues.flac
artist=John Coltrane
album=The Heavyweight Champion: The Complete Atlantic Recordings
title=Village Blues
coverurl=/coverart.php/USB%2FElements%2FJohn%20Coltrane%2FAtlantic%20Recordings%2Fdisc4%2F4-01%20Village%20Blues.flac
track=1
date=199500
composer=
encoded=FLAC 16/44.1 kHz, 2ch
bitrate=791 kbps
outrate=PCM 24/44.1 kHz, 2ch
volume=0
mute=0
state=play

Correct. The example shows a basic method to read each line of currentsong.txt