INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Quick Start Guide for Installing LCD Matrix on rPi, reading track info  (Read 4139 times)

Wheaten

  • Guest

Updated on 26-03-2021, to include extended ASCII chars.
Changes with previous installation:

New driver:
If V2.x
Code: [Select]
sudo pip install RPLCDIf V3.x
Code: [Select]
sudo pip3 install RPLCDnew script


Installation has been performed on a fresh instance of Raspbian:


Make sure to pay attention to your python version, as mixing python 2.x and 3x might cause all kind of strange errors. Instruction to check your version are further down in this post.

It’s just a very basic of displaying track data, feel free to modify to your needs. I am sure code could be more efficient (especially the attribute reading), but I am not a python programmer. (and def. not looking to master a 7th programming language  :P)I’ve assumed that you have JRiver running, with the media network enabled and protected with a password. If you don’t use a password, you need to modify the function. See track.py below.  The script comes as is.
When Artist or track exceeds 20 chars, the line will scroll. Due to the physical properties, scrolling looks like blinking for the scrolling lines, but I do prefer this over strange shorten text.
If you see text that belongs to 1 line appearing on other lines, your LCD_WIDTH is set incorrect.

What is needed:
  • rPi board
  • A compatible LCD Matrix (I am using a GeeekPi IIC/I2C 2004 20x4 Character LCD Module Display from Amazon.)  https://www.amazon.nl/gp/product/B07QNKCLJM
  • 4 wires to connect everything
  • SSH access to the Pi, or run everything from the rPi desktop
Perform the needed setups:
-   Enable wait for boot till network is available:
Code: [Select]
sudo raspi-config







-   Create a new directory in your home folder
Code: [Select]
cd ~/
mkdir jriverapi && cd jriverapi
Place lcd_V2.0.zip in this folder.

-   Unzip the content
Code: [Select]
unzip lcd_V2.0.zipWe will execute the script: “Enable_I2C.sh”. This scipt will, if needed, enable I2C and install i2c-tools.

-   Make script executable, execute it and shutdown the rPi:
Code: [Select]
chmod a+x Enable_I2C.sh
sudo ./Enable_I2C.sh
sudo shutdown

-   Connect display
rPiDisplay
Pin3 (SDA)SDA
Pin2 (5V)VCC
Pin5 (SCL)SCL
Pin39 (GND)GND


Boot the rPi

Check your python version, important to avoid random errors. The libraries we are going to add need to be for the correct version.
Code: [Select]
python --versionIf V2.x
Code: [Select]
sudo pip install RPLCD
sudo apt-get install python-smbus
If V3.x
Code: [Select]
sudo pip3 install RPLCD
sudo apt-get install python3-smbus
Reboot the rPi

Locate the address for the display. Depending on the version of your rPi, you need to run one off the following lines:
Code: [Select]
i2cdetect -y 0
Code: [Select]
i2cdetect -y 1

-   Configure the library
Make sure to respect the indents, don’t add spaces or tabs. This will result in errors like below:


Code: [Select]
cd ~/jriverapi


-   Configure track.py
Set your display width, URL and credentials.
Code: [Select]
nano track.py

LCD_WIDTH = 20
sURL = 'http://localhost:52199/MCWS/v1/Playback/Info?Zone=-1'
sUsername = 'username'
sPassword = 'password'

Modify the address with the info taken form the previous command:
Code: [Select]
mylcd = CharLCD('PCF8574', 0x27,charmap='A00')
When done: press "CTRL + X, ENTER CTRL + O" to save it.

You can test the script by running:
Code: [Select]
cd ~/jriverapi
python track.py
If all went well, you'll see:

When JRiver is playing:


If you want the script started when the rPi boots, you can do this very easy by adding a line to the cron:
Code: [Select]
crontab -e
@reboot sleep 10 && python /home/pi/jriver_api/track.py


Reboot your Pi. If all went well it should come up with the hostname and time.
If the screen stays blank, you might need to increase “sleep 10” to a higher number.
This should not happen as we "Enable wait for boot till network is available".

Good luck.
Logged

JimH

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 72444
  • Where did I put my teeth?
Re: Quick Start Guide for Installing LCD Matrix on rPi
« Reply #1 on: March 11, 2021, 07:08:28 am »

Thanks for the nice guide!
Logged

Wheaten

  • Guest
Re: Quick Start Guide for Installing LCD Matrix on rPi
« Reply #2 on: March 11, 2021, 10:09:31 am »

OLED version is WIP (Work In Progress)

Had to gamble on the used fonts for the logo, Is there a logo available in pure black white?
Due to the lo-res of the display, I can't use the site logo.




Logged

bob

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 13874
Re: Quick Start Guide for Installing LCD Matrix on rPi
« Reply #3 on: March 16, 2021, 09:42:38 am »

I ordered a GeeekPi IIC/I2C 2004 20x4 Character LCD Module Display, really interested in trying this!
Logged

Wheaten

  • Guest
Re: Quick Start Guide for Installing LCD Matrix on rPi
« Reply #4 on: March 16, 2021, 05:37:33 pm »

Will post a tut, when ready.
Currently the screens, error handling is done.
Need to cleanup the code and document everything.

Preview:
Logged

bob

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 13874
Re: Quick Start Guide for Installing LCD Matrix on rPi
« Reply #5 on: March 22, 2021, 02:40:29 pm »

I ordered a GeeekPi IIC/I2C 2004 20x4 Character LCD Module Display, really interested in trying this!
It's working well for me.
The one concern I have is that the amount of CPU it's using seems a bit high.
Perhaps it's possible that you have a spin-wait condition in your status reading loop where there is no sleep part of the time?
Also, you might want to change the script so it doesn't quit when it can't reach the client temporarily for whatever reason (like someone restarts MC on pi).

All in all, it's a pretty cool addition!

Logged

Wheaten

  • Guest

You can add a time.sleep(0.5), but then the elapsed time will jump with weird jumps. 48, 49, 51, 53, 54,......
Logged

bob

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 13874

It doesn't appear the GeekPi LCD does utf-8? I'm getting odd looking characters for accented chars (like ä)
Logged

Wheaten

  • Guest

I think you're using Python V2.x. V2 will not automatically encode to UTF-8.
You need to add .encode('utf-8') behind every string, like:
Artist[:LCD_WIDTH].center(LCD_WIDTH," ").encode('utf-8')
Name[:LCD_WIDTH].center(LCD_WIDTH," ").encode('utf-8')

I can't test this as I have my Pi running with Python 3
Logged

bob

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 13874

I think you're using Python V2.x. V2 will not automatically encode to UTF-8.
You need to add .encode('utf-8') behind every string, like:
Artist[:LCD_WIDTH].center(LCD_WIDTH," ").encode('utf-8')
Name[:LCD_WIDTH].center(LCD_WIDTH," ").encode('utf-8')

I can't test this as I have my Pi running with Python 3
I tried this on a couple of different devices, on my pi4 running python2 and a pi0w running python3 without any luck.
The data from MC is already being sent in utf8 so I'm not sure how encoding it to utf8 again would help.

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<Response Status="OK">
<Item Name="ZoneID">0</Item>
<Item Name="State">2</Item>
<Item Name="FileKey">5247</Item>
<Item Name="NextFileKey">-1</Item>
<Item Name="PositionMS">1056502</Item>
<Item Name="DurationMS">1604307</Item>
<Item Name="ElapsedTimeDisplay">17:36</Item>
<Item Name="RemainingTimeDisplay">-9:08</Item>
<Item Name="TotalTimeDisplay">26:44</Item>
<Item Name="PositionDisplay">17:36 / 26:44</Item>
<Item Name="PlayingNowPosition">0</Item>
<Item Name="PlayingNowTracks">1</Item>
<Item Name="PlayingNowPositionDisplay">1 of 1</Item>
<Item Name="PlayingNowChangeCounter">249</Item>
<Item Name="Bitrate">5644</Item>
<Item Name="Bitdepth">64</Item>
<Item Name="SampleRate">352800</Item>
<Item Name="Channels">2</Item>
<Item Name="Chapter">0</Item>
<Item Name="Volume">1</Item>
<Item Name="VolumeDisplay">100%  (+0.0 dB)</Item>
<Item Name="ImageURL">MCWS/v1/File/GetImage?File=5247</Item>
<Item Name="Artist">Minnesota Orchestra - Osmo Vänskä</Item>
<Item Name="Album">Mahler: Symphony No. 10</Item>
<Item Name="Name">Symphony No.10: I. Adagio. Andante - Adagio</Item>
<Item Name="Status">Playing</Item>
</Response>
 
Logged

Wheaten

  • Guest
Re: Quick Start Guide for Installing LCD Matrix on rPi, reading track info
« Reply #10 on: March 25, 2021, 12:55:19 pm »

Hi Bob,

The issue is not with MC, but with Python.
Python V2 default to standard ASCII, this means the char 0 till 127.
So a letter like ä is char(132) which is not covered (0..127) and therefor it displays a weird sequence.

I've spend some considerable amount of time on this, and have no solution.
Maybe we have some python programmers, who have an solution.
Logged

bob

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 13874
Re: Quick Start Guide for Installing LCD Matrix on rPi, reading track info
« Reply #11 on: March 25, 2021, 03:26:12 pm »

Hi Bob,

The issue is not with MC, but with Python.
Python V2 default to standard ASCII, this means the char 0 till 127.
So a letter like ä is char(132) which is not covered (0..127) and therefor it displays a weird sequence.

I've spend some considerable amount of time on this, and have no solution.
Maybe we have some python programmers, who have an solution.
I've been testing with python3 and it still doesn't work but the issue appears to be with the Display, not python.
If I write specific characters by just replacing the ord(char) in the I2C_LCD_driver.py routine with specific characters, it's obvious that the upper half of the character set on the device is not utf-8
Logged

Wheaten

  • Guest
Re: Quick Start Guide for Installing LCD Matrix on rPi, reading track info
« Reply #12 on: March 25, 2021, 04:57:40 pm »

It's a driver issue.
Did a small test with a different driver.

this piece of code shows a correct output, however the current driver (from the zip)  can't pass a charmap.

Code: [Select]
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os, sys
from RPLCD.i2c import CharLCD

lcd = CharLCD('PCF8574', 0x27,charmap='A00')
lcd.write_string(u'Vänskä')


Logged

Wheaten

  • Guest
Re: Quick Start Guide for Installing LCD Matrix on rPi, reading track info
« Reply #13 on: March 25, 2021, 06:10:39 pm »

Please conform if the script from the previous post is working for you. We don't have that many artists here with weird letters in their name. Only had 1 for testing. BjÖrk
If it's ok I will update my installation documentation in this topic.

Logged

bob

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 13874
Re: Quick Start Guide for Installing LCD Matrix on rPi, reading track info
« Reply #14 on: March 25, 2021, 08:25:50 pm »

It's a driver issue.
Did a small test with a different driver.

this piece of code shows a correct output, however the current driver (from the zip)  can't pass a charmap.

Code: [Select]
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os, sys
from RPLCD.i2c import CharLCD

lcd = CharLCD('PCF8574', 0x27,charmap='A00')
lcd.write_string(u'Vänskä')


Yes, that works!
Logged

bob

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 13874
Re: Quick Start Guide for Installing LCD Matrix on rPi, reading track info
« Reply #15 on: April 01, 2021, 11:45:09 am »

I'm sure there are way more efficient ways of doing this, I'm not a python coder but on my device I can use charset 'A00' and it does the best job handling extra characters if they are lower case so I translate the UC ones to LC thusly:

   
Code: [Select]
        global Artist
Artist = " "
Artist = readattrval(root,"./Item[@Name='Artist']")
Artist=Artist.replace(chr(196),chr(228))
Artist=Artist.replace(chr(209),chr(241))
Artist=Artist.replace(chr(214),chr(246))
Artist=Artist.replace(chr(220),chr(252))
global Album
Album = " "
Album = readattrval(root,"./Item[@Name='Album']")
Album=Album.replace(chr(196),chr(228))
Album=Album.replace(chr(209),chr(241))
Album=Album.replace(chr(214),chr(246))
Album=Album.replace(chr(220),chr(252))
global Name
Name = " "
Name = readattrval(root,"./Item[@Name='Name']")
Name=Name.replace(chr(196),chr(228))
Name=Name.replace(chr(209),chr(241))
Name=Name.replace(chr(214),chr(246))
Name=Name.replace(chr(220),chr(252))

Picture of my pi0w running this querying one of my Id's  :)
Logged

Wheaten

  • Guest
Re: Quick Start Guide for Installing LCD Matrix on rPi, reading track info
« Reply #16 on: April 01, 2021, 12:59:47 pm »

glad it's working.

To make it a bit more maintainable, you can declare a function, which will save a lot of double code lines, like:
Code: [Select]
def replacechar(sourcestr):
sourcestr = sourcestr.replace(chr(196),chr(228))
sourcestr = sourcestr.replace(chr(209),chr(241))
sourcestr = sourcestr.replace(chr(214),chr(246))
sourcestr = sourcestr.replace(chr(220),chr(252))
return sourcestr

so then you need to only call it like:
Code: [Select]
Album = replacechar(Album)
Name = replacechar(Name)

haven't been able to test it yet, as All Pi's are in use for other purposes.
Logged

bob

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 13874
Re: Quick Start Guide for Installing LCD Matrix on rPi, reading track info
« Reply #17 on: April 08, 2021, 06:25:45 pm »

glad it's working.

To make it a bit more maintainable, you can declare a function, which will save a lot of double code lines, like:
Code: [Select]
def replacechar(sourcestr):
sourcestr = sourcestr.replace(chr(196),chr(228))
sourcestr = sourcestr.replace(chr(209),chr(241))
sourcestr = sourcestr.replace(chr(214),chr(246))
sourcestr = sourcestr.replace(chr(220),chr(252))
return sourcestr

so then you need to only call it like:
Code: [Select]
Album = replacechar(Album)
Name = replacechar(Name)

haven't been able to test it yet, as All Pi's are in use for other purposes.
I found that if one of the fields are empty it errors out so like this works:
Code: [Select]
if bool(Album):
    replacechar(Album)
fixes that.
I also compiled daemontools-encore on TinyCoreLinux for this app and use that to restart it when it dies (MC is offline or the network connection drops).
I can provide that if anyone is interested.
Logged

Wheaten

  • Guest
Re: Quick Start Guide for Installing LCD Matrix on rPi, reading track info
« Reply #18 on: April 10, 2021, 06:06:55 am »

Since you're the admin, you can add it to my starting topic. So we everything in one place
Logged

bmunroe

  • Regular Member
  • Junior Woodchuck
  • **
  • Posts: 90
  • Where ever you go, there you are
Re: Quick Start Guide for Installing LCD Matrix on rPi
« Reply #19 on: April 10, 2021, 10:44:29 am »

OLED version is WIP (Work In Progress)

looking forward to seeing your code for the OLED.  I managed to smash together your code with a CPU stats display code for my OLED to get it to work.  Took me a bit to figure it all out (n00b to linux and python) but it is working well now, although just putting out text info.
Logged

bmunroe

  • Regular Member
  • Junior Woodchuck
  • **
  • Posts: 90
  • Where ever you go, there you are
Logged
Pages: [1]   Go Up