Sonos-HDMI by Retired Guy isn't outputting graphics...

  • 11 January 2022
  • 31 replies
  • 380 views

@Chicks, thank you for the port of your touchscreen controller to a view only HDMI code.  

I’ve got your code installed on my Pi Zero W, auto login to shell, the Sonos.py script auto-running and edited to my named speaker group, and it connected to the HDMI on the big-screen.  Unfortunately, the Pi isn’t showing the artwork/music on screen, just the bash prompt after the linux boot menu.

Can you direct me to what I am missing from the auto-run or the python or the output variable for the screen? Is there one more utility to be the front end?  Maybe my systmctrl of the Sonos app isn’t running?

I needed to chmod your utility to executable, so that should be OK now…. Thoughts?


This topic has been closed for further comments. You can use the search bar to find a similar topic, or create a new one by clicking Create Topic at the top of the page.

31 replies

I don’t have this set up any more, or any Sonos products running at the moment, but a couple of things to check.

Try sudo journalctl -u sonos.service  to see if/why it fails to start.

Run sudo systemctl stop sonos.service, then start it manually from the cmd prompt:

   cd ~ 

   cd sonos

   python3 sonos.py

 

Make sure you’ve done all the steps outlined, including giving the “pi” user membership in video group:

  sudo usermod -a -G video pi

 

Around line 288 in sonos.py: fb = open(“/dev/fb0”, “wb”).  It’s possible that your pi is using fb1 for HDMI vs fb0, especially if there’s another screen installed locally.

 

Ok, thank you for the insight on the console view.  I’m getting a break at Image.py; which does exist in that directory.  I do not see libopenjp2.so.7 in the directory however.

  File "/home/pi/sonos/sonos.py", line 20, in <module>

    from PIL import Image

  File "/home/pi/.local/lib/python3.9/site-packages/PIL/Image.py", line 89, in <module>

    from . import _imaging as core

ImportError: libopenjp2.so.7: cannot open shared object file: No such file or directory

Ok, so looks like you didn’t do all the install steps from section 8 of the readme, specifically the jpg library install, which is required by PIL. 
 

Starting here:

sudo apt install libopen-jp2-7-dev

sudo apt install libtiff5

sudo apt install ttf-dejavu

pip3 install soco

pip3 install Pillow

Actually, I my have documented that incorrectly. Try:

 

sudo apt install libopenjp2-7-dev

 

That library was missing. Thank you.  So now I’m getting a crash without details.

pi@raspberrysonos:~/sonos $ python3 sonos.py

Illegal instruction

This could be because of lack of fonts.  When I add the font library, after updating Debian on the Pi I get: E: Unable to locate package ttf-dejavu

Can I use a default system font that is sans, to be more modern?  Did you pick that because it scales to large format better than system fonts?

Did you run the install step for the font?

 

sudo apt install ttf-dejavu

 

 

Yes, that was the line: When I add the font library, after updating Debian on the Pi I get: E: Unable to locate package ttf-dejavu

I performed a package update too.  It still was not found. I got another version to install with the command: 

sudo apt-get install --reinstall fonts-dejavu and fonts-dejavu-core

This put them in the folder: 

/usr/share/fonts/truetype/dejavu/

So I created /usr/share/fonts/truetype/dejavu-ttl/ and copied them all there as well.

Logs are non-detailed: Jan 12 00:33:07 raspberrysonos systemd[1]: sonos.service: Main process exited, code=killed, status=4/ILL

Jan 12 00:33:07 raspberrysonos systemd[1]: sonos.service: Failed with result 'signal'.

So that leads to my other question, can I pick another font that will scale well and be san serif/modern?

Looks like the latest version (bullseye) of Raspberry Pi OS has dejavu already installed, and the package name has been changed, as you have found.  So, the font is not your issue.

When troubleshooting, you never want to start it as a service.  Run it manually from the cmd prompt to see what errors are being thrown.  

I’ll try to do the install on a fresh build in the next day or two, if you haven’t resolved.  I suspect, as this was built originally on the previous OS version, something else has changed with the OS to cause it to fail.

 

So, the Python package managers have somehow messed up a bunch of packages, including Pillow. 

https://github.com/piwheels/packages/issues/269

So, downgrade to Pillow version 8.4.0:

   pip3 uninstall Pillow

   python3 -m pip install Pillow==8.4.0

Should work now.  Fingers crossed.

Well done! That was it.  Amazing research to debug it, considering the blank error.  Thank you!  Have a tip jar?

Resolution is huge on a 1080p Plasma in my shop, but I think I prefer the large artwork, vs small images...

Dave

Ok, I made some changes to get the resolution up to 800X600 to show cover art at double pixels on the 1080P Plasma TV.  Ideally this would contain a watch dog to see resolution natively and format the art properly.  I went the manual route to fix it for my display.

You can set the overscan values to drop or slide the frame a few pixels. I found if you change these by more than 1-9 then it breaks the image mapping from the memory buffer.

I set the screen type and resolution:

hdmi_group=2

hdmi_mode=9

hdmi_cvt=800 600 60 6 0 0 0

Finally, used the last post in this thread, from 2019 to clear the screen and remove the cursor at boot as my new higher resolution screen had some system messages:

https://forums.raspberrypi.com/viewtopic.php?t=60615

 

Badge

So, the Python package managers have somehow messed up a bunch of packages, including Pillow. 

https://github.com/piwheels/packages/issues/269

So, downgrade to Pillow version 8.4.0:

   pip3 uninstall Pillow

   python3 -m pip install Pillow==8.4.0

Should work now.  Fingers crossed.

Thank you so much, I was trying to install on Monday and running into trouble.

 

After fixing Pillow I now the following error message:

 


pi@raspberrypi:~/sonos $ python3 sonos.py
display_power=1
screen brightness set
Traceback (most recent call last):
  File "/home/pi/sonos/sonos.py", line 293, in <module>
    initscreen()
  File "/home/pi/sonos/sonos.py", line 76, in initscreen
    blit(img,(0,0))
  File "/home/pi/sonos/sonos.py", line 66, in blit
    fb.seek(4 * (fbw - w), 1)
OSError: [Errno 28] No space left on device
 

make sure you remove the installer for the old pillow and any other .zip files.  Your file system is full...

Badge

make sure you remove the installer for the old pillow and any other .zip files.  Your file system is full...

I went back and deleted the zip file. I tried a fresh install because things weren’t working.

I’m going to try a different SD card and see if that fixes it.

Badge

Same error message with a new SSD card:

pi@raspberrypi:~/sonos $ python3 sonos.py                                       
display_power=1
screen brightness set
Traceback (most recent call last):
  File "/home/pi/sonos/sonos.py", line 293, in <module>
    initscreen()
  File "/home/pi/sonos/sonos.py", line 76, in initscreen
    blit(img,(0,0))
  File "/home/pi/sonos/sonos.py", line 66, in blit
    fb.seek(4 * (fbw - w), 1)
OSError: [Errno 28] No space left on device

I used sudo raspi-config, advanced options, A1 expand the file system.

Unfortunately still getting the same message despite available space.


pi@raspberrypi:~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        29G  1.4G   27G   5% /
devtmpfs         87M     0   87M   0% /dev
tmpfs           215M     0  215M   0% /dev/shm
tmpfs            86M  612K   86M   1% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
/dev/mmcblk0p1  253M   49M  204M  20% /boot
tmpfs            43M     0   43M   0% /run/user/1000
pi@raspberrypi:~ $
 


 

The device causing the error is the framebuffer.  Make sure it’s configured correctly per the details. 

Badge

The device causing the error is the framebuffer.  Make sure it’s configured correctly per the details. 

I’m sorry, I believe I haven’t changed anything in the config.txt except the HDMI output. I’m not sure what you are referring to.

I actually have the Hyperpixel 4” touch en route via USPS and plan to use as you described in your original post. Just wanted to get things working on a monitor before it arrived.

Badge

The device causing the error is the framebuffer.  Make sure it’s configured correctly per the details. 

Here is my config:

 

# For more options and information see
# http://rpf.io/configtxt
# Some settings may impact device functionality. See link above for details

# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16

# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720

# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (this will force VGA)
  hdmi_group=2
  hdmi_mode=87
  hdmi_cvt=800 480 60 6 0 0 0

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
 hdmi_drive=1

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4

# uncomment for composite PAL
#sdtv_mode=2

#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800

# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on

# Uncomment this to enable infrared communication.
#dtoverlay=gpio-ir,gpio_pin=17
#dtoverlay=gpio-ir-tx,gpio_pin=18

# Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835)
dtparam=audio=on

# Automatically load overlays for detected cameras
camera_auto_detect=1

# Automatically load overlays for detected DSI displays
display_auto_detect=1

# Enable DRM VC4 V3D driver
dtoverlay=vc4-kms-v3d
max_framebuffers=2

# Disable compensation for displays with overscan
disable_overscan=1

[cm4]
# Enable host mode on the 2711 built-in XHCI USB controller.
# This line should be removed if the legacy DWC2 controller is required
# (e.g. for USB device mode) or if USB support is not required.
otg_mode=1

[all]

[pi4]
# Run as fast as firmware / board allows
arm_boost=1

[all]
 

Badge

I tried a new install with Hyperpixel attached and interesting I’m getting the same result regarding frame buffering being out of space. https://github.com/retired-guy/Sonos-Remote/archive/refs/heads/master.zip

pi@raspberrypi:~/sonos $
pi@raspberrypi:~/sonos $ python3 sonos.py
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Can't connect to pigpio at localhost(8888)

Did you start the pigpio daemon? E.g. sudo pigpiod

Did you specify the correct Pi host/port in the environment
variables PIGPIO_ADDR/PIGPIO_PORT?
E.g. export PIGPIO_ADDR=soft, export PIGPIO_PORT=8888

Did you specify the correct Pi host/port in the
pigpio.pi() function? E.g. pigpio.pi('soft', 8888)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'NoneType' object has no attribute 'send'
Traceback (most recent call last):
  File "/home/pi/sonos/sonos.py", line 288, in <module>
    initscreen()
  File "/home/pi/sonos/sonos.py", line 72, in initscreen
    blit(img,(0,0))
  File "/home/pi/sonos/sonos.py", line 62, in blit
    fb.seek(4 * (fbw - w), 1)
OSError: [Errno 28] No space left on device
 

You’ll want to start up a few things at bootup, so over in file /etc/rc.local

add the following lines just before the “exit 0” line at the end (make sure pigpiod has been installed):

# Start pigpiod

/usr/bin/pigpiod

# Turn off HDMI
/usr/bin/tvservice -o

exit 0

 

Also, make sure the Hyperpixel overlay has been installed and configured (you should see the bootup process on the Hyperpixel if it’s properly configured), rotated as desired, and the touchscreen calibrated.

With the LCD screen installed, there may be two framebuffers, /dev/fb0 and /dev/fb1.  We want to make sure the Hyperpixel shows up as /dev/fb0

 

This stuff assumes some Linux and Python experience, not a cakewalk for noobs.

Badge

 

This stuff assumes some Linux and Python experience, not a cakewalk for noobs.

Yes, I’m clearly struggling.


I started from the beginning and made sure I had the Hyperpixel 4 working. Screen was working well. I began following the HDMI directions for installing packages (even though I will be using your remote master.zip). I also installed pigpio and and evdev.

I moved the SD card back to my linux laptop and edited rc.local just above exit 0 as you recommended.

I have both /dev/fb0 and /dev/fb1 and my guess is the Hyperpixel is fb1. I tried googling but don’t see a clear way to change that.

When I rebooted after making the changes you suggested to rc.local I no longer have any screen output.

Right now when I run sonos.py I get the following error (I haven’t figured out how to make this a service yet, just trying to make it work first).

 


pi@raspberrypi:~/sonos $ python3 sonos.py
screen brightness set
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 169, in _new_conn
    conn = connection.create_connection(
  File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 96, in create_connection
    raise err
  File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 86, in create_connection
    sock.connect(sa)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 699, in urlopen
    httplib_response = self._make_request(
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 394, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 234, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "/usr/lib/python3.9/http/client.py", line 1255, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.9/http/client.py", line 1301, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.9/http/client.py", line 1250, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.9/http/client.py", line 1010, in _send_output
    self.send(msg)
  File "/usr/lib/python3.9/http/client.py", line 950, in send
    self.connect()
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 200, in connect
    conn = self._new_conn()
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 174, in _new_conn
    raise ConnectTimeoutError(
urllib3.exceptions.ConnectTimeoutError: (<urllib3.connection.HTTPConnection object at 0xb4c8ffa0>, 'Connection to 192.168.68.128 timed out. (connect timeout=3)')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 755, in urlopen
    retries = retries.increment(
  File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 574, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='192.168.68.128', port=1400): Max retries exceeded with url: /MediaRenderer/AVTransport/Event (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0xb4c8ffa0>, 'Connection to 192.168.68.128 timed out. (connect timeout=3)'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/sonos/sonos.py", line 290, in <module>
    info = zone.avTransport.subscribe(
  File "/home/pi/.local/lib/python3.9/site-packages/soco/services.py", line 609, in subscribe
    return subscription.subscribe(
  File "/home/pi/.local/lib/python3.9/site-packages/soco/events.py", line 294, in subscribe
    return self._wrap(subscribe, strict, requested_timeout, auto_renew)
  File "/home/pi/.local/lib/python3.9/site-packages/soco/events.py", line 440, in _wrap
    method(*args, **kwargs)
  File "/home/pi/.local/lib/python3.9/site-packages/soco/events_base.py", line 468, in subscribe
    return self._request(
  File "/home/pi/.local/lib/python3.9/site-packages/soco/events.py", line 392, in _request
    response = requests.request(method, url, headers=headers, timeout=3)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 504, in send
    raise ConnectTimeout(e, request=request)
requests.exceptions.ConnectTimeout: HTTPConnectionPool(host='192.168.68.128', port=1400): Max retries exceeded with url: /MediaRenderer/AVTransport/Event (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0xb4c8ffa0>, 'Connection to 192.168.68.128 timed out. (connect timeout=3)'))
pi@raspberrypi:~/sonos $
 

 

Is there a Sonos device at 192.168.68.128?  Doesn’t appear to be, soco is not finding one.  Those errors are way down in soco somewhere.

Make sure you change this in sonos.py, around line 24 to the IP address of the zone you want to monitor.

If your Hyperpixel is on fb1, change the Python script to write to /dev/fb1 instead of /dev/fb0.

 

Badge

Is there a Sonos device at 192.168.68.128?  Doesn’t appear to be, soco is not finding one.  Those errors are way down in soco somewhere.

Make sure you change this in sonos.py, around line 24 to the IP address of the zone you want to monitor.

########################################## Sonos zone to monitor -CHANGE ME! ##zone = soco.SoCo('192.168.68.128')########################################

If your Hyperpixel is on fb1, change the Python script to write to /dev/fb1 instead of /dev/fb0.

 

IP updated!

May be on fb0, when I tried fb1 it reported the fb.seek no space error.

 

Getting this error now:

pi@raspberrypi:~/sonos $ python3 sonos.py
screen brightness set
Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.9/site-packages/evdev/device.py", line 126, in __init__
    fd = os.open(dev, os.O_RDWR | os.O_NONBLOCK)
FileNotFoundError: [Errno 2] No such file or directory: '/dev/input/event1'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/sonos/sonos.py", line 294, in <module>
    dev = InputDevice('/dev/input/event1')
  File "/home/pi/.local/lib/python3.9/site-packages/evdev/device.py", line 128, in __init__
    fd = os.open(dev, os.O_RDONLY | os.O_NONBLOCK)
FileNotFoundError: [Errno 2] No such file or directory: '/dev/input/event1'
pi@raspberrypi:~/sonos $

 

 

Thank you for your help. Gonna give it a bit of a rest. May try to make the HDMI version work on the screen tomorrow.
 

 

 

That’s the input device (touchscreen).  Yours may be 0. 
 

Change this line, about line 294:

 

dev = InputDevice('/dev/input/event1')

 

Change the 1 to 0. 

Badge

That’s the input device (touchscreen).  Yours may be 0. 
 

Change this line, about line 294:

 

dev = InputDevice('/dev/input/event1')

 

Change the 1 to 0. 

Wow thanks! I’m pretty close now. The display worked initially before going through installation steps but it’s remained blank since following reboot. This is the output as I started and stopped music to the sonos device:

 


pi@raspberrypi:~/sonos $ python3 sonos.py
screen brightness set
timeout started!
timeout cancelled!
screen brightness set
timeout started!
timeout cancelled!
timeout started!
 

So seems like things are working I just need to figure out why my display stopped working (light’s up but remains blank). I wonder if it’s pigpio related. I tried undoing these /etc/rc.local settings but the display didn’t turn on. IE I made these changes (and then changed them back when it didn’t solve my problem).

# Start pigpiod

# /usr/bin/pigpiod

# Turn off HDMI
# /usr/bin/tvservice -o

 

I also tried turning off the pigpiod service but screen didn’t turn on- I haven’t tried figuring out how to stop the service from running at boot.

 

Edit: seems like there is an issue starting the service:


pi@raspberrypi:~ $ systemctl start hyperpixel-init
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to start 'hyperpixel-init.service'.
Authenticating as: ,,, (pi)
Password:
==== AUTHENTICATION COMPLETE ===
Failed to start hyperpixel-init.service: Unit hyperpixel-init.service not found.
pi@raspberrypi:~ $
 

I’m going to try and install again via “curl -sSL https://get.pimoroni.com/hyperpixel4 | bash”.

 

Might be an issue after running sudo apt-get update. I’m going to try to go to an older stable install.

 

This didn’t work:

sudo apt-get update; sudo apt-get install --reinstall raspberrypi-bootloader raspberrypi-kernel

 

I’m going to do give more try at rolling back the kernel and then start from scratch.