RaspDAC - Tutoriel pour affichage Volumio sur ecran LCD/OLED

Ici on parle de Raspberry PI, Sparky, Odroid... avec des solutions comme Squeezelite, MPD, Max2Play... ainsi que leur DAC et accessoires dédiés
Marcellom
Messages : 14
Inscription : ven. 20 nov. 2015 19:29

Re: RaspDAC - Tutoriel pour affichage Volumio sur ecran LCD/

Message par Marcellom » ven. 20 nov. 2015 20:06

Hi to all and sorry, i dont speak french and english so so :)
I have got my new raspdac, this:
http://www.audiophonics.fr/fr/appareils ... 10369.html
Im very happy with it, is very good sounding dac and it looks beautiful.
But i've a problem with lcd display.
I have followed the tutorial (step by step),. but when i try to start the display an error message says "/home/pi/16x2_oled_volumio.py:73: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings."
Sometimes, after one or two minute, are displayed in the screen no sense ascii characters, sometime nothing.
After dac restart the display show only a black display.
What is wrong? Anyone can help me?
Dernière modification par Marcellom le ven. 20 nov. 2015 22:26, modifié 1 fois.

Marcellom
Messages : 14
Inscription : ven. 20 nov. 2015 19:29

Re: RaspDAC - Tutoriel pour affichage Volumio sur ecran LCD/

Message par Marcellom » ven. 20 nov. 2015 20:20

After 3 reinstallations of the OP and after re-run of the tutorial (again)..it works...
But i dont know why e what's wrong...
ok, thanks the some.

mc002
Messages : 4
Inscription : dim. 22 nov. 2015 23:26

Re: RaspDAC - Tutoriel pour affichage Volumio sur ecran LCD/

Message par mc002 » dim. 22 nov. 2015 23:33

Hello,

"ERROR: The certificate of `archive.raspberrypi.org' is not trusted.
The certificate has not yet been activated
root@volumio:/home/pi# ERROR: The certificate of `archive.raspberrypi.org' is not trusted."


try the following: "--no-check-certificate" option

wget -O /home/pi/python-rpi.gpio_0.5.11-1_armhf.deb --no-check-certificate

mc002
Messages : 4
Inscription : dim. 22 nov. 2015 23:26

Re: RaspDAC - Tutoriel pour affichage Volumio sur ecran LCD/

Message par mc002 » dim. 22 nov. 2015 23:54

Hello,

I´ve made some modification for the python script.

In this version you have four modes:

1. NAS Playing mode ( this has existed in the former version also)
2. Spotify Playing mode ( showing the metadata of the actual Spotify stream
3. Airplay Playing mode ( it shows only the Airplay modus -> the volumio version of shairplay gives no metadata back)
4. No Playing mode

Has anyone an idea to get metadata from shairplay?

Christian :-)

Code : Tout sélectionner

#!/usr/bin/python
# -*- coding: iso-8859-15 -*-#
#
# Author : Matt Hawkins
# Date   : 06/04/2015
# http://www.raspberrypi-spy.co.uk/
#
# Author : Robert Coward/Paul Carpenter (based on driver by Matt Hawkins/)
# https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=68055
# Date   : 02/03/2014
#
# Author : Audiophonics
# Date   : 23/09/2015 (V1.0)
# http://www.audiophonics.fr
# http://forum.audiophonics.fr/viewtopic.php?f=4&t=1492
#
# Autor : Christian Mueller
# Date  : 22/11/2015 
#
#
--------------------------------------

# The wiring for the LCD is as follows:
# 1 : GND
# 2 : 5V
# 3 : Contrast (0-5V)*
# 4 : RS (Register Select)
# 5 : R/W (Read Write)       - GROUND THIS PIN
# 6 : Enable or Strobe
# 7 : Data Bit 0             - NOT USED
# 8 : Data Bit 1             - NOT USED
# 9 : Data Bit 2             - NOT USED
# 10: Data Bit 3             - NOT USED
# 11: Data Bit 4
# 12: Data Bit 5
# 13: Data Bit 6
# 14: Data Bit 7
# 15: LCD Backlight +5V**
# 16: LCD Backlight GND

#import
import RPi.GPIO as GPIO
import time;
import subprocess;
import os;
import telnetlib;
from decimal import Decimal, ROUND_DOWN
import logging
#logging.basicConfig(filename='example2.log',level=logging.DEBUG)
#logging.debug('This message should go to the log file')
#logging.info('So should this')
#logging.warning('And this, too')
process_name= "mpdlcd"

# Define GPIO to LCD mapping
LCD_RS = 7
LCD_E  = 8
LCD_D4 = 25
LCD_D5 = 24
LCD_D6 = 23
LCD_D7 = 12


# Define some device constants
LCD_WIDTH = 16    # Maximum characters per line
LCD_CHR = True
LCD_CMD = False

LCD_LINE_1 = 0x80 # LCD RAM address for the 1st line
LCD_LINE_2 = 0xC0 # LCD RAM address for the 2nd line

# Timing constants
E_PULSE = 0.0005
E_DELAY = 0.001

def main():
  # Main program block

  GPIO.setmode(GPIO.BCM)       # Use BCM GPIO numbers
  GPIO.setup(LCD_E, GPIO.OUT)  # E
  GPIO.setup(LCD_RS, GPIO.OUT) # RS
  GPIO.setup(LCD_D4, GPIO.OUT) # DB4
  GPIO.setup(LCD_D5, GPIO.OUT) # DB5
  GPIO.setup(LCD_D6, GPIO.OUT) # DB6
  GPIO.setup(LCD_D7, GPIO.OUT) # DB7


  # Initialise display
  lcd_init()

# Open Spotify server

  time.sleep(30)
  tn = telnetlib.Telnet("localhost","6602",30)
  while True:

    cmdA = "mpc | head -2 | tail -1 | awk '{print $1}'" # gets the player state ie paused playing etc
    process = subprocess.Popen(cmdA, stdout=subprocess.PIPE , shell=True)
    os.waitpid(process.pid, 0)[1]
    mpc_state = process.stdout.read().strip()
    
    cmdB = "hostname -I"  #gets the current ip
    process2 = subprocess.Popen(cmdB, stdout=subprocess.PIPE , shell=True)
    os.waitpid(process2.pid, 0)[1]
    ip_addr = process2.stdout.read().strip()

    cmdC = "netstat -t | grep rfe" #check if a user is connected via airplay
    process = subprocess.Popen(cmdC, stdout=subprocess.PIPE , shell=True)
    os.waitpid(process.pid, 0)[1]
    airplay = process.stdout.read().strip()

# Load Spotify meta data

    tn.write("status\n")
    status = tn.read_until("}")

# Airplay Section **********************

    while airplay :
      lcd_string("",LCD_LINE_2)   
      lcd_string("Airplay Active:",LCD_LINE_1)
      cmdC = "netstat -t | grep rfe" #check if a user is connected via airplay
      process = subprocess.Popen(cmdC, stdout=subprocess.PIPE , shell=True)
      os.waitpid(process.pid, 0)[1]
      airplay = process.stdout.read().strip()

# Spotify Section ***********************

    Spotify_Zeit = "00:00"
    Zaehler = 1
    while status.find("playing") != -1:
      tn.write("status\n")
      status = tn.read_until("}")
      Spotify_Dauer = status[status.find("\"duration\"")+11:status.find("\"position\"")-4]
      Spotify_Spielzeit = status[status.find("\"position\"")+11:status.find("\"uri\"")-1]
      Spotify_Spielzeit = Spotify_Spielzeit[0:Spotify_Spielzeit.find(".")]
      Spotify_Titel = status[status.find("\"title\"")+9:status.find("\"album\"")-2]
      
      
      if Spotify_Spielzeit.isdigit(): lcd_string2("Spotify : "+str(int(Spotify_Spielzeit)//60).zfill(2)+":"+str(int(Spotify_Spielzeit)%60).zfill(2),LCD_LINE_1)
 
      if Zaehler==1: 
         lcd_string(status[status.find("\"title\"")+9:status.find("\"album\"")-2],LCD_LINE_2)
         Zaehler=2
      if Zaehler==2:
         lcd_string(status[status.find("\"artist\"")+10:status.find("\"title\"")-2],LCD_LINE_2)
         Zaehler=3
      if Zaehler==3: 
         lcd_string(status[status.find("\"album\"")+9:status.find("\"duration\"")-2],LCD_LINE_2)
         Zaehler=1

# No playing Section ***********************

    if mpc_state != "[playing]" and not airplay and status.find("playing") == -1:
      lcd_string("Volumio 1.55",LCD_LINE_1)
      lcd_string(ip_addr,LCD_LINE_2)

      time.sleep(0.1)

# Play NAS Section ***********************

    while mpc_state == "[playing]":    
      cmdA = "mpc | head -2 | tail -1 | awk '{print $1}'" # gets the player state ie paused playing etc
      process = subprocess.Popen(cmdA, stdout=subprocess.PIPE , shell=True)
      os.waitpid(process.pid, 0)[1]
      mpc_state = process.stdout.read().strip()
     
      cmd1 = "mpc | head -1"      
      process = subprocess.Popen(cmd1, stdout=subprocess.PIPE , shell=True)
      os.waitpid(process.pid, 0)[1]
      mpc_string = Umwandlung(process.stdout.read().strip())

      if mpc_string.count(" - ") == 2:
         mpc_song = mpc_string[mpc_string.find(" - ", mpc_string.find(" - ")+2)+3:mpc_string.find(" - ", mpc_string.find(" - ")+2)+50]
      if mpc_string.count(" - ") == 1:
         mpc_song = mpc_string[mpc_string.find(" - ")+3:mpc_string.find(" - ")+50]

      cmd2 = "mpc | head -2 | tail -1"  # 00:00
      process = subprocess.Popen(cmd2, stdout=subprocess.PIPE , shell=True)
      os.waitpid(process.pid, 0)[1]
      mpc_string2 = process.stdout.read().strip()
      
      mpc_time = "Volumio : "+ mpc_string2[mpc_string2.find(":")-3:mpc_string2.find(":")+3]

      lcd_string2(mpc_time,LCD_LINE_1)    
      
      if mpc_string.count(" - ") == 2:
            mpc_artist = mpc_string[0:mpc_string.find(" - ")]
            mpc_werk = mpc_string[mpc_string.find(" - ")+3:mpc_string.find(" - ", mpc_string.find(" - ")+2)]
            mpc_song = mpc_string[mpc_string.find(" - ", mpc_string.find(" - ")+2)+3:mpc_string.find(" - ", mpc_string.find(" - ")+2)+50]
      if mpc_string.count(" - ") == 1:
            mpc_artist = mpc_string[0:mpc_string.find(" - ")]
            mpc_song = mpc_string[mpc_string.find(" - ")+3:mpc_string.find(" - ")+50]
            mpc_werk = " "
      if mpc_string.count(" - ") == 0:
            mpc_artist = mpc_string[0:19]
            mpc_song = " "
            mpc_werk = " "
      if mpc_string.count(" - ") >2:
            mpc_artist = " "
            mpc_song = " "
            mpc_werk = " "

      lcd_string2(mpc_time,LCD_LINE_1)
      lcd_string(mpc_song,LCD_LINE_2)
      lcd_string(mpc_artist,LCD_LINE_2)
      lcd_string(mpc_werk,LCD_LINE_2)

  tn.write("bye\n")

def Umwandlung(mpc):
  mpc = mpc.replace("é","e")
  mpc = mpc.replace("ä","\xE1")
  mpc = mpc.replace("ü","\xF5")
  mpc = mpc.replace("ö","\xEF")
  mpc = mpc.replace("Ä","Ae")
  mpc = mpc.replace("Ü","Ue")
  mpc = mpc.replace("Ö","Oe")
  mpc = mpc.replace("ß","\xE2")
  mpc = mpc.replace("á","a") 
  return mpc 	

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(0x08,LCD_CMD) # Display off OLED ADD
  lcd_byte(0x01,LCD_CMD) # 000001 Clear display
  time.sleep(0.01)
  # extra steps required for OLED initialisation (no effect on LCD)
  lcd_byte(0x17, LCD_CMD)    # character mode, power on      OLED ADD

  # now turn on the display, ready for use - IMPORTANT!
  lcd_byte(0x0C, LCD_CMD)    # display on, cursor/blink off     OLED ADD

def lcd_byte(bits, mode):
  # Send byte to data pins
  # bits = data
  # mode = True  for character
  #        False for command

  GPIO.output(LCD_RS, mode) # RS

  # High bits
  GPIO.output(LCD_D4, False)
  GPIO.output(LCD_D5, False)
  GPIO.output(LCD_D6, False)
  GPIO.output(LCD_D7, False)
  if bits&0x10==0x10:
    GPIO.output(LCD_D4, True)
  if bits&0x20==0x20:
    GPIO.output(LCD_D5, True)
  if bits&0x40==0x40:
    GPIO.output(LCD_D6, True)
  if bits&0x80==0x80:
    GPIO.output(LCD_D7, True)

  # Toggle 'Enable' pin
  lcd_toggle_enable()

  # Low bits
  GPIO.output(LCD_D4, False)
  GPIO.output(LCD_D5, False)
  GPIO.output(LCD_D6, False)
  GPIO.output(LCD_D7, False)
  if bits&0x01==0x01:
    GPIO.output(LCD_D4, True)
  if bits&0x02==0x02:
    GPIO.output(LCD_D5, True)
  if bits&0x04==0x04:
    GPIO.output(LCD_D6, True)
  if bits&0x08==0x08:
    GPIO.output(LCD_D7, True)

  # Toggle 'Enable' pin
  lcd_toggle_enable()

def lcd_toggle_enable():
  # Toggle enable
  time.sleep(E_DELAY)
  GPIO.output(LCD_E, True)
  time.sleep(E_PULSE)
  GPIO.output(LCD_E, False)
  time.sleep(E_DELAY)

def lcd_string2(message,line):
  # Send string to display
  message = message.ljust(LCD_WIDTH," ")

  lcd_byte(line, LCD_CMD)

  for i in range(LCD_WIDTH): lcd_byte(ord(message[i]),LCD_CHR)

def lcd_string(message,line):
  # Send string to display
  message = message.center(LCD_WIDTH," ")

  lcd_byte(line, LCD_CMD)

  for i in range(LCD_WIDTH): lcd_byte(ord(message[i]),LCD_CHR)

if __name__ == '__main__':

  try:
    main()
  except KeyboardInterrupt:
    pass
  finally:
    lcd_byte(0x01, LCD_CMD)
    lcd_string("Goodbye!",LCD_LINE_1)
    GPIO.cleanup()


stormsixx
Messages : 6
Inscription : dim. 15 nov. 2015 16:45

Re: RaspDAC - Tutoriel pour affichage Volumio sur ecran LCD/

Message par stormsixx » jeu. 26 nov. 2015 13:35

Audiophonics a écrit :
Avez vous simplement placés les fichiers "en vrac" sous la racine ?

Avez vous un répertoire comme ici ? :

http://www.framboise314.fr/ma-framboise ... a_carte_SD

Êtes vous sur de la version de Berryboot utilisée ? :

http://www.berryterminal.com/doku.php/berryboot

Si vous avez un PI2.0 (quad core), c'est celle-ci qu'il vous faut :

http://downloads.sourceforge.net/projec ... 2-only.zip

Dans l'attente de vous lire.
Alors:

- Oui, j'ai copié le contenu du dossier dézippé à la racine, sur la carte SD formatée en FAT32

- J'ai un PI2, et la bonne version de Berryboot

Le PI démarre, mais rien ne se passe à l'écran... J'ai testé sur TV et PC (des fois que...), idem.
Par ailleurs, les diodes ethernet restent également éteintes.

stormsixx
Messages : 6
Inscription : dim. 15 nov. 2015 16:45

Re: RaspDAC - Tutoriel pour affichage Volumio sur ecran LCD/

Message par stormsixx » jeu. 26 nov. 2015 15:45

Je viens d'essayer d'installer un autre OS, sans passer par Berryboot: même chose. Cela peut-il être un problème hardware?

ptit_lu
Messages : 5
Inscription : jeu. 17 déc. 2015 16:00

Re: RaspDAC - Tutoriel pour affichage Volumio sur ecran LCD/

Message par ptit_lu » lun. 21 déc. 2015 01:03

Bonsoir à tous !
J'ai un écran LCD avec les mêmes caractéristiques et les mêmes sorties. Cependant, aucun signe de fonctionnement de l'écran. Je suis RPI2 et Runeaudio. J'ai un DAC ES9023 qui fonctionne correctement, je souhaite lui coller un écran LCD de ce genre...

reggieb
Messages : 2
Inscription : ven. 01 janv. 2016 16:31

Re: RaspDAC - Tutoriel pour affichage Volumio sur ecran LCD/

Message par reggieb » ven. 01 janv. 2016 16:37

My apologies for posting in English:

I think I've followed the instructions in this thread, to set up the display, but all I get are strange characters. Can you suggest what I might have done wrong?

Image

Avatar de l’utilisateur
Audiophonics
Messages : 1128
Inscription : lun. 24 janv. 2011 12:55

Re: RaspDAC - Tutoriel pour affichage Volumio sur ecran LCD/

Message par Audiophonics » lun. 04 janv. 2016 15:06

Hi,

No worries about that ;)

Have you counterchecked the display wiring ?

looking forward to hearing from you.

Best Regards
David

Marcellom
Messages : 14
Inscription : ven. 20 nov. 2015 19:29

Re: RaspDAC - Tutoriel pour affichage Volumio sur ecran LCD/

Message par Marcellom » jeu. 07 janv. 2016 15:23

Hi all!
Im a total newbie in python and i was wondering if anyone has changed the script16x2_oled_volumio.py to display the song info when is playing Spotify.
I know that for many people is so easy but for me is so hard.
Thanks in advance :)

Marcellom
Messages : 14
Inscription : ven. 20 nov. 2015 19:29

Re: RaspDAC - Tutoriel pour affichage Volumio sur ecran LCD/

Message par Marcellom » ven. 08 janv. 2016 12:23

No one can help me?

LeMax
Messages : 1
Inscription : mar. 12 janv. 2016 12:22

Re: RaspDAC - Tutoriel pour affichage Volumio sur ecran LCD/

Message par LeMax » mar. 12 janv. 2016 12:57

Bonjour à tous et meilleurs vœux pour 2016.

Je voulais savoir où en était la version du DAC avec gestion de l'alimentation incluse.
Auriez vous une date de sortie?
Et quid des évolutions (pin header plus grand, carte d’amélioration de l'écran).

Le boulot que vous faite est formidable. Je connais depuis peux mais je crois que je vais me lancer bientôt!

mc002
Messages : 4
Inscription : dim. 22 nov. 2015 23:26

Re: RaspDAC - Tutoriel pour affichage Volumio sur ecran LCD/

Message par mc002 » mar. 19 janv. 2016 23:35

Hi Marcello,

please use my modified script from my post 22.11.2015.

mc002

Avatar de l’utilisateur
Nicko
Administrateur - Site Admin
Messages : 450
Inscription : mer. 26 juil. 2006 12:21
Localisation : Bordeaux
Contact :

Re: RaspDAC - Tutoriel pour affichage Volumio sur ecran LCD/

Message par Nicko » mer. 20 janv. 2016 18:51

Thanks for sharing your updated script mc002 ! 8)

Avatar de l’utilisateur
Nicko
Administrateur - Site Admin
Messages : 450
Inscription : mer. 26 juil. 2006 12:21
Localisation : Bordeaux
Contact :

Re: RaspDAC - Tutoriel pour affichage Volumio sur ecran LCD/

Message par Nicko » mer. 20 janv. 2016 18:54

LeMax a écrit :Bonjour à tous et meilleurs vœux pour 2016.

Je voulais savoir où en était la version du DAC avec gestion de l'alimentation incluse.
Auriez vous une date de sortie?
Et quid des évolutions (pin header plus grand, carte d’amélioration de l'écran).
La production de la carte avec régulation et gestion du power est en cours, ça devait être prêt pour le 15 Janvier mais c'est en retard (normal)
J'espère début Février.

Quand à la carte qui gère mieux l'écran elle est basé sur un Arduino, et permet d'accompagner le Pi dès la mise sous tension.
On est encore en train de peaufiner le proto...

beradenga
Messages : 3
Inscription : dim. 24 janv. 2016 22:05

Re: RaspDAC - Tutoriel pour affichage Volumio sur ecran LCD/

Message par beradenga » mar. 26 janv. 2016 22:13

mc002 a écrit :Hello,
I´ve made some modification for the python script.
...
The script did not work for me (black screen)
I got the script running only after a comparison with the initial script:
mc002 changed LCD_D7 from GPIO15 to GPIO12 ...
LCD_D7 = 12
... and as I did not change the cabling as shown in the initial posts of this thread I reverted it back to read
LCD_D7 = 15

Then, the script from mc002 worked fine.
I suggest to add this comment to the first post of mc002, if possible.

--- beradenga

mc002
Messages : 4
Inscription : dim. 22 nov. 2015 23:26

Re: RaspDAC - Tutoriel pour affichage Volumio sur ecran LCD/

Message par mc002 » mer. 27 janv. 2016 00:00

Hi Beradenga,

sorry for the cable mess :-)

Here I´ve another version of the script. Have fun :-)

Code : Tout sélectionner

-----------------------------------------------------------------------
#!/usr/bin/python
# -*- coding: latin-1 -*-

#import
import RPi.GPIO as GPIO
import time;
import subprocess;
import os, sys;
import telnetlib;
from decimal import Decimal, ROUND_DOWN
process_name= "mpdlcd"

# Define GPIO to LCD mapping
LCD_RS = 7
LCD_E  = 8
LCD_D4 = 25
LCD_D5 = 24
LCD_D6 = 23
LCD_D7 = 15

# Define some device constants

LCD_WIDTH = 16    # Maximum characters per line
LCD_CHR = True
LCD_CMD = False

LCD_LINE_1 = 0x80 # LCD RAM address for the 1st line
LCD_LINE_2 = 0xC0 # LCD RAM address for the 2nd line

# Timing constants
E_PULSE = 0.0005
E_DELAY = 0.001

def main():
  # Main program block

  GPIO.setmode(GPIO.BCM)       # Use BCM GPIO numbers
  GPIO.setup(LCD_E, GPIO.OUT)  # E
  GPIO.setup(LCD_RS, GPIO.OUT) # RS
  GPIO.setup(LCD_D4, GPIO.OUT) # DB4
  GPIO.setup(LCD_D5, GPIO.OUT) # DB5
  GPIO.setup(LCD_D6, GPIO.OUT) # DB6
  GPIO.setup(LCD_D7, GPIO.OUT) # DB7  
  
  time.sleep(30)
  tn = telnetlib.Telnet("localhost","6602",30)

  # Initialise display
  lcd_init()

  while True:

    cmdA = "mpc | head -2 | tail -1 | awk '{print $1}'" # gets the player state ie paused playing etc
    process = subprocess.Popen(cmdA, stdout=subprocess.PIPE , shell=True)
    os.waitpid(process.pid, 0)[1]
    mpc_state = process.stdout.read().strip()
    
    cmdB = "hostname -I"  #gets the current ip
    process2 = subprocess.Popen(cmdB, stdout=subprocess.PIPE , shell=True)
    os.waitpid(process2.pid, 0)[1]
    ip_addr = process2.stdout.read().strip()

    cmdC = "netstat -t | grep rfe" #check if a user is connected via airplay
    process = subprocess.Popen(cmdC, stdout=subprocess.PIPE , shell=True)
    os.waitpid(process.pid, 0)[1]
    airplay = process.stdout.read().strip()

    tn.write("status\n")
    status = tn.read_until("}")

    while airplay :
      lcd_string("Airplay Active",LCD_LINE_1)
      lcd_string("",LCD_LINE_2)
      cmdC = "netstat -t | grep rfe" #check if a user is connected via airplay
      process = subprocess.Popen(cmdC, stdout=subprocess.PIPE , shell=True)
      os.waitpid(process.pid, 0)[1]
      airplay = process.stdout.read().strip()

    Spotify_Titel2 = ""
    Spotify_Titel = " "
    Spotify_Zeit = "Spotify :  "

    while status.find("playing") != -1:
      tn.write("status\n")
      status = tn.read_until("}")
      Spotify_Dauer = status[status.find("\"duration\"")+11:status.find("\"position\"")-4]
      Spotify_Spielzeit = status[status.find("\"position\"")+11:status.find("\"uri\"")-1]
      Spotify_Spielzeit = Spotify_Spielzeit[0:Spotify_Spielzeit.find(".")]
      Spotify_Titel = status[status.find("\"title\"")+9:status.find("\"album\"")-2]
      
      if Spotify_Spielzeit.isdigit(): Spotify_Zeit = "Spotify :  "+str(int(Spotify_Spielzeit)//60).zfill(2)+":"+str(int(Spotify_Spielzeit)%60).zfill(2)

      if Spotify_Titel2 != Spotify_Titel and status.find("playing") != -1:
	
        Spotify_Artist = status[status.find("\"artist\"")+10:status.find("\"title\"")-2]
    	Spotify_Titel = status[status.find("\"title\"")+9:status.find("\"album\"")-2]
	Spotify_Album = status[status.find("\"album\"")+9:status.find("\"duration\"")-2]
	
        lcd_string2(Spotify_Zeit,LCD_LINE_1)
        lcd_string(Spotify_Titel,LCD_LINE_2)
        lcd_string(Spotify_Artist ,LCD_LINE_1)   
        lcd_string(Spotify_Album ,LCD_LINE_2)
        Spotify_Titel2=Spotify_Titel
  
      if status.find("playing") != -1: 
        lcd_string2(Spotify_Zeit,LCD_LINE_1)
        lcd_string(Spotify_Titel,LCD_LINE_2)
        lcd_string(Spotify_Artist ,LCD_LINE_1)
        lcd_string(Spotify_Album ,LCD_LINE_2)

    if mpc_state != "[playing]" and not airplay and status.find("playing") == -1:
      lcd_string("Volumio 1.55",LCD_LINE_1)
      lcd_string(ip_addr,LCD_LINE_2)


    mpc_song1 ="!"
    mpc_song =" "
    mpc_artist = " "
    mpc_werk = " "

    while mpc_state == "[playing]":    
      cmdA = "mpc | head -2 | tail -1 | awk '{print $1}'" # gets the player state ie paused playing etc
      process = subprocess.Popen(cmdA, stdout=subprocess.PIPE , shell=True)
      os.waitpid(process.pid, 0)[1]
      mpc_state = process.stdout.read().strip()
     
      cmd1 = "mpc | head -1"      
      process = subprocess.Popen(cmd1, stdout=subprocess.PIPE , shell=True)
      os.waitpid(process.pid, 0)[1]
      mpc_string = Umwandlung(process.stdout.read().strip())
      if mpc_string.count(" - ") == 3:
         mpc_song = mpc_string[FindKo(mpc_string," - ",3):FindKo(mpc_string," - ",3)+20]      
         mpc_artist = mpc_string[0:FindKo(mpc_string," - ",1)-3]
         mpc_werk = mpc_string[FindKo(mpc_string," - ",1):FindKo(mpc_string," - ",2)-3]
      if mpc_string.count(" - ") == 2:
         mpc_song = mpc_string[FindKo(mpc_string," - ",2):FindKo(mpc_string," - ",2)+20]
         mpc_artist = mpc_string[0:FindKo(mpc_string," - ",1)-3]
         mpc_werk = mpc_string[FindKo(mpc_string," - ",1):FindKo(mpc_string," - ",2)-3]
      if mpc_string.count(" - ") == 1:
         mpc_song = mpc_string[FindKo(mpc_string," - ",1):FindKo(mpc_string," - ",1)+20]
         mpc_artist = mpc_string[0:FindKo(mpc_string," - ",1)-3]
         mpc_werk = " "
      if mpc_string.count(" - ") == 0:
         mpc_artist = mpc_string[0:19]
         mpc_song = " "
         mpc_werk = " "
      if mpc_string.count(" - ") >3:
         mpc_song = mpc_string[FindKo(mpc_string," - ",mpc_string.count(" - ")):FindKo(mpc_string," - ",mpc_string.count(" - "))+20]
         mpc_artist = mpc_string[0:FindKo(mpc_string," - ",1)-3]
         mpc_werk = mpc_string[FindKo(mpc_string," - ",1):FindKo(mpc_string," - ",2)-3]
      cmd2 = "mpc | head -2 | tail -1"  # 00:00
      process = subprocess.Popen(cmd2, stdout=subprocess.PIPE , shell=True)
      os.waitpid(process.pid, 0)[1]
      mpc_string2 = process.stdout.read().strip()
      
      mpc_time = "Volumio:  "+ mpc_string2[mpc_string2.find(":")-3:mpc_string2.find(":")+3]

      lcd_string2(mpc_time,LCD_LINE_1)
      lcd_string(mpc_artist,LCD_LINE_2)
      lcd_string(mpc_werk,LCD_LINE_1)
      lcd_string(mpc_song,LCD_LINE_2)
      time.sleep(1.0)
  tn.write("bye\n")

def Umwandlung(mpc):

  mpc = mpc.replace("é","e")
  mpc = mpc.replace("ä","\xE1")
  mpc = mpc.replace("ü","\xF5")
  mpc = mpc.replace("ö","\xEF")
  mpc = mpc.replace("Ä","Ae")
  mpc = mpc.replace("Ü","Ue")
  mpc = mpc.replace("Ö","Oe")
  mpc = mpc.replace("ß","\xE2")
  mpc = mpc.replace("à","a")
  mpc = mpc.replace("á","a")
  mpc = mpc.replace("è","a") 
  return mpc 

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(0x08,LCD_CMD) # Display off OLED ADD
  lcd_byte(0x01,LCD_CMD) # 000001 Clear display
  time.sleep(0.01)
  # extra steps required for OLED initialisation (no effect on LCD)
  lcd_byte(0x17, LCD_CMD)    # character mode, power on      OLED ADD

  # now turn on the display, ready for use - IMPORTANT!
  lcd_byte(0x0C, LCD_CMD)    # display on, cursor/blink off     OLED ADD	
def lcd_byte(bits, mode):
  # Send byte to data pins
  # bits = data
  # mode = True  for character
  #        False for command

  GPIO.output(LCD_RS, mode) # RS

  # High bits
  GPIO.output(LCD_D4, False)
  GPIO.output(LCD_D5, False)
  GPIO.output(LCD_D6, False)
  GPIO.output(LCD_D7, False)
  if bits&0x10==0x10:
    GPIO.output(LCD_D4, True)
  if bits&0x20==0x20:
    GPIO.output(LCD_D5, True)
  if bits&0x40==0x40:
    GPIO.output(LCD_D6, True)
  if bits&0x80==0x80:
    GPIO.output(LCD_D7, True)

  # Toggle 'Enable' pin
  lcd_toggle_enable()

  # Low bits
  GPIO.output(LCD_D4, False)
  GPIO.output(LCD_D5, False)
  GPIO.output(LCD_D6, False)
  GPIO.output(LCD_D7, False)
  if bits&0x01==0x01:
    GPIO.output(LCD_D4, True)
  if bits&0x02==0x02:
    GPIO.output(LCD_D5, True)
  if bits&0x04==0x04:
    GPIO.output(LCD_D6, True)
  if bits&0x08==0x08:
    GPIO.output(LCD_D7, True)

  # Toggle 'Enable' pin
  lcd_toggle_enable()

def lcd_toggle_enable():
  # Toggle enable
  time.sleep(E_DELAY)
  GPIO.output(LCD_E, True)
  time.sleep(E_PULSE)
  GPIO.output(LCD_E, False)
  time.sleep(E_DELAY)

def lcd_string(message,line):
  # Send string to display

  message = message.center(LCD_WIDTH," ")

  lcd_byte(line, LCD_CMD)

  for i in range(LCD_WIDTH):
    lcd_byte(ord(message[i]),LCD_CHR)

def lcd_string2(message,line):
  #Send string to display

  message = message.ljust(LCD_WIDTH," ")

  lcd_byte(line, LCD_CMD)

  for i in range(LCD_WIDTH):
    lcd_byte(ord(message[i]),LCD_CHR)

def FindKo(text,suchstring,anzahl):
  start=0
  for i in range(0,anzahl):
    start=text.find(suchstring,start)+3
  return start

if __name__ == '__main__':

  try:
    main()
  except KeyboardInterrupt:
    pass
  finally:
    lcd_byte(0x01, LCD_CMD)
    lcd_string("Goodbye!",LCD_LINE_1)
    GPIO.cleanup()

Marcellom
Messages : 14
Inscription : ven. 20 nov. 2015 19:29

Re: RaspDAC - Tutoriel pour affichage Volumio sur ecran LCD/

Message par Marcellom » ven. 12 févr. 2016 09:55

@Mc002:
I thank you very verymuch for your answer..
This. w. e. i'll try the script.. :)

beradenga
Messages : 3
Inscription : dim. 24 janv. 2016 22:05

Re: RaspDAC - Tutoriel pour affichage Volumio sur ecran LCD/

Message par beradenga » sam. 13 févr. 2016 22:49

Hello,

I am playing around with the Python script to control the OLED and have further modified it. Overall I am not yet fully satisfied, as

- the reaction of the display is slow. With the current display method I could not realize to scroll the text in the display, as I would like to (consider long album or song titles, right now it is cut in pieces and only partly displayed). I hope it is not the display that is slow, but the way the OLED driver is currently working.
- the code does not exploit the potential of the OLED display, as custom characters can be defined to e.g. define play, stop and pause symbols for display which would be very useful to use the little display space. The display also supports 4 character sets.
- the code does not separate the OLED driver part from the display logic - this is not sustainable if somebody wants to change one part, but not the other
- the code uses expensive subprocess calls and does frequent polling to get song infos. Isn't there a more intelligent way?
- the display is not turned of when the system is shutdown, as there is no event handling for SIGTERM in the script
- the code from mc002 in his mos recent posting may be cpu intensive, as there are while-loops without any sleep command


Some thoughts after a bit of Internet research:

- The Python code example on https://learn.adafruit.com/character-lc ... k/overview shows well written code for a similar display which is also compatible to the HD44780 controller which is used in the Winstar OLED display. However it is far more complex than the existing one. It should be possible to adapt the Adafruit examples to the Winstar OLED display and use the functions defined there. E.g. the Adafruit library allows to define those custom characters - see e.g. https://github.com/adafruit/Adafruit_Py ... d_plate.py - and to scroll a message - see https://github.com/adafruit/Adafruit_Py ... har_lcd.py.
-- I have noticed that the credits of the initial script published by nicko from Audiophonics refer to pages like https://www.raspberrypi.org/forums/view ... 63&t=68055 which contain scripts that are also derived from the Adafruit code. What was the reason to simplify the current code so dramatically compared to the links in the credits?

- The current code gets the info for the display from the mpc and the Airplay status from the process listing. Unfortunately shairport does not provide easily song infos in the main release, so Volumio does also not display anything, when Airplay is used. But if it would: Would it not be more intelligent to get all the song infos from Volumio system, from the same calls as the webinterface I see from the browser? If volumio would have a special HTTP page to return a simple HTML file to parse with all current song infos, then the code for the display would not need to mimic what Volumio is doing as well (and probably more efficiently). A webpage can be called every second - this is not an expensive operation in contrast to initiate a complete subprocess.

- There are also ways to get Airplay info, see e.g. https://www.raspberrypi.org/forums/view ... 28&t=93928 or https://github.com/celeryclub/smartie-client or https://github.com/luckydonald/shairport-decoder or https://volumio.org/forum/get-spotify-a ... t2420.html. But again it would be better to integrate this tighter into Volumio and then get the info from there.
- For Runeaudio there is a discussion how to get the song / status info directly and then call Python code, see http://www.runeaudio.com/forum/lcd-in-r ... -t763.html. For Volumio I have not found something similar. Volumio 2 is being rewritten in node.js, so the existing PHP will disappear anyhow ...

- A specification of the controller of the OLED display can be found at https://www.adafruit.com/datasheets/WS0010.pdf

- A good introduction on how to work with LCD displays can be found at http://sprut.de/electronic/lcd/index.htm (in German).

- Can callbacks in the Shairplay Python binding https://github.com/juhovh/shairplay/blo ... airplay.py be used to get the Song info ?

Conclusion:
I can read / understand code reasonably well but have never done serious programming. I think that enough bits and pieces are there to get the OLED display to the next level. Eventually I will try out some things in the coming weeks. Please comment on the ideas / suggestions, maybe you can also contribute existing or new code.

Question to Audiophonics: I have read that there will be a new version of case + Pi + Sabre DAC plus OLED in the near future ? If yes, will you also provide an updated script? So eventually you are already working on something improved?

---- UPDATE Feb 15th -----

I managed to write an OLED python driver based on the references above, with
- faster speed
- scrolling
- clearing the display when shutdown signal is received (SIGTERM)
- custom chararcters (e.g. play, stop, Airplay, ...)

I will continue to work on this the next weekend and post the results are ready. Then I will look at better retrieval of information from MPC, Spotify and Airplay.


--- beradenga

Avatar de l’utilisateur
Nicko
Administrateur - Site Admin
Messages : 450
Inscription : mer. 26 juil. 2006 12:21
Localisation : Bordeaux
Contact :

Re: RaspDAC - Tutoriel pour affichage Volumio sur ecran LCD/

Message par Nicko » jeu. 18 févr. 2016 14:41

Beradenga,

Thanks for your feedback.

Like you said, it's sure that direct Oled control with python can be improved.
Our python code give a slow result because it don't manage OLED screen with R/W pin.

We didn't found Python drivers that include R/W pin processing.

So we done a new product based on adafruit Arduino OLED library that control OLED with full speed.
We will offer this board for sale soon. It will control power too.

Yes Volumio could have a PHP process that pickup song info and Spotify / Airplay song.
It would be simpler for us to show data on screen... but I think it's not for tomorrow :)


If you succeed to write something that can make OLED fast direct from Python it would be nice.
We will be pleased to offer you a gift if you share it.

Archeon
Messages : 22
Inscription : lun. 16 nov. 2015 22:49

Re: RaspDAC - Tutoriel pour affichage Volumio sur ecran LCD/

Message par Archeon » jeu. 25 févr. 2016 14:18

La carte dont vous parler est-elle le I-Sabre V3 ?

Possédant la V3 et dans l'optique de faire fonctionner l'écran avec une autre distrib que Volumio (openELEC ou OSMC...), pourriez-vous me fournir le schéma de câblage des pins du DAC V3 sur le GPIO ?

Merci

Avatar de l’utilisateur
Nicko
Administrateur - Site Admin
Messages : 450
Inscription : mer. 26 juil. 2006 12:21
Localisation : Bordeaux
Contact :

Re: RaspDAC - Tutoriel pour affichage Volumio sur ecran LCD/

Message par Nicko » jeu. 25 févr. 2016 18:51

Voici la relation entre le connecteur de l'écran et le GPIO.
GPIO 14 et 15 serviront pour le contrôleur série, ils ne sont pas utilisés sur l'écran directement adressé.

Vous avez également le détail des pins utilisés dans le script python que nous avons fourni.
Pièces jointes
sch_LCD.jpg
I-Sabre V3 LCD
sch_LCD.jpg (60.78 Kio) Consulté 12190 fois

Archeon
Messages : 22
Inscription : lun. 16 nov. 2015 22:49

Re: RaspDAC - Tutoriel pour affichage Volumio sur ecran LCD/

Message par Archeon » ven. 26 févr. 2016 16:01

Ok merci ! c'est exactement ce qui me fallait.

Maintenant il me faut attendre que mon DAC parte et revienne de SAV :'(

dhrone
Messages : 39
Inscription : sam. 27 févr. 2016 20:51

Re: RaspDAC - Tutoriel pour affichage Volumio sur ecran LCD/

Message par dhrone » sam. 27 févr. 2016 21:07

For anyone who may be interested, I've coded an alternative python program to drive the display. It sounds like beradenga and I have been pursuing similar goals. This version specifically addresses several of the same challenges he noted include...

* Much faster display updates
* Scrolling of song and artist information when longer than the display width
* Support for both MPD and Spotify
* Direct polling of song metadata
* Display shutdown on program exit

The code is still somewhat buggy with a rare but annoying display corruption issue that I haven't been able to track down yet. Exiting and restarting the program normally restores the display though.

I hope this community will find the code useful. It is located up on Github at https://github.com/dhrone/Raspdac-Display.git" onclick="window.open(this.href);return false;. Of course any help improving the code or tracking down any bugs would be gratefully appreciated.

Best regards,
Dhrone

Avatar de l’utilisateur
Nicko
Administrateur - Site Admin
Messages : 450
Inscription : mer. 26 juil. 2006 12:21
Localisation : Bordeaux
Contact :

Re: RaspDAC - Tutoriel pour affichage Volumio sur ecran LCD/

Message par Nicko » jeu. 03 mars 2016 17:35

Hello Dhrone,

Thanks you much for your work.
We will try it ASAP and maybe include it as standard script for our product using OLED1602

Répondre