Posts: 87
Threads: 20
Joined: Apr 2018
Reputation:
2
Hi all,
today has arrived my 16x2 LCD, and I start to scan the forums trying to understand how to "populate" it with info coming from Moode.
OK, I learned that I have to set "Metadata File = ON" and that in this way the file in the subject in updated whenever something changes in the Web UI. OK, clear.
I learned that this file should be in the /var/www folder..... but I found instead in the var/local/www folder. The location is changed in this last version or (most probably) I'm wrong?
And... I saw that in that file there are some basic elements of the currently played song. How should I retrieve, for example, the track elapsed time (it seems not present in the file structure).
Thanks a lot in advance
Andrea
Posts: 13,450
Threads: 305
Joined: Mar 2018
Reputation:
545
Hi,
Yes thats the correct location, /var/local/www/currentsong.txt
The key to determining whether to use currentsong.txt is that the file is updated within a 3 second polling loop by worker.php. If for example you want to display elapsed time in 1 second intervals, or use side-scrolling text etc then you will probably want to query MPD directly for all the information from a Python script that has its own 1 sec polling loop.
NOTE that there are some data values like the URL for the cover art that are not available by queuing MPD.
-Tim
Posts: 113
Threads: 7
Joined: Apr 2018
Reputation:
3
If you are feeling adventurous, I have been using node-red to quickly develop and deploy:
- continuous polling systems
- web sockets instead of polling to avoid unnecessary requests
- file reading
- GPIO and other PI interactions done very easy
I think it's a great place to start, and if you are more comfortable with JavaScript than Python, then it's just the icing on the cake.
Best regards,
Rafa.
Posts: 87
Threads: 20
Joined: Apr 2018
Reputation:
2
04-12-2018, 01:54 PM
(This post was last modified: 04-12-2018, 01:55 PM by mancio61.)
I'm not too adventurous, in the meantime I found a couple of nice examples. In this piece of code, depending of the status of MPD (if there's a song currently played), the code print 'system' info (e.g. IP Address, Temperature, other stuff) or song info (retrieving them from MPD, including timing and other stuff).
The only problem that I have to check, is that the example is made for a 4 lines LCD Display. I'm not sure if the LCD_Init function below is valid also for 16x2 Display ...
.......
import smbus
import time
# Define some device parameters
I2C_ADDR = 0x27 # I2C device address #this must be checked...
LCD_WIDTH = 16 # 20 Maximum characters per line (MODIFIED BY ME)
# Define some device constants
LCD_CHR = 1 # Mode - Sending data
LCD_CMD = 0 # Mode - Sending command
LCD_LINE_1 = 0x80 # LCD RAM address for the 1st line
LCD_LINE_2 = 0xC0 # LCD RAM address for the 2nd line
# LCD_LINE_3 = 0x94 # LCD RAM address for the 3rd line COMMENTED BY ME
# LCD_LINE_4 = 0xD4 # LCD RAM address for the 4th line COMMENTED BY ME
LCD_BACKLIGHT = 0x08 # On
#LCD_BACKLIGHT = 0x00 # Off
ENABLE = 0b00000100 # Enable bit
# Timing constants
E_PULSE = 0.0005
E_DELAY = 0.0005
#Open I2C interface
#bus = smbus.SMBus(0) # Rev 1 Pi uses 0
bus = smbus.SMBus(1) # Rev 2 Pi uses 1
def lcd_init():
# Initialise display
lcd_byte(0x33,LCD_CMD) # 110011 Initialise
lcd_byte(0x32,LCD_CMD) # 110010 Initialise
lcd_byte(0x06,LCD_CMD) # 000110 Cursor move direction
lcd_byte(0x0C,LCD_CMD) # 001100 Display On,Cursor Off, Blink Off
lcd_byte(0x28,LCD_CMD) # 101000 Data length, number of lines, font size
lcd_byte(0x01,LCD_CMD) # 000001 Clear display
time.sleep(E_DELAY)
.....