Guide for setting up touchscreen + backlight control

Hi,

It’s the standard KY040 encoder that you see sold at most of the Pi vendors:

modmypi.com/raspberry-pi/se … der-module

It has a push button switch so the rotary control could be used to do track/favourite previous and next with some logic added to the code.

Many thanks for your Guideline!

Unfortunatly the keyboard thing doesn’t work for me. I would expect a touch keyboard popping up whenever I set the cursor to a field requiring text input. But nothing happens. I checked the changes multiple times and didn’t find an error.

:-/

Thanks, glad it was (somewhat!) useful :slight_smile:

With the keyboard. You are right, it should pop up when you touch a text input field. A couple of thoughts (although I am no expert as I have only copied these from other sources) first is making sure the ‘#’ is infront of ‘#openbox-session &’. The only other thought is that there is an issue in the config for the keyboard.xml file.

Many thx for your detailed guide which helped me a lot.
Actually I have setup a new system (Pi3+, HifiBerry Amp2 and a 7" Touch-TFT (the Raspi one).
I added a button and a LED to control the TFT backlight together with your latest version of the Python script.
At principal all is working fine except one thing:
In case Volumio is in PLAY state and I press the button for more than 2 secs Volumio changes the state to PAUSE properly and the backlight is turned off. When I press the button once again the backlight is turned on again but Volumio keeps in state PAUSE and is not resuming to PLAY.

Is it possible that the script do have a kind of bug regarding this?
I’m not yet a good Python coder so it would be very nice if you can review this issue?
Anyone out there having the same issue?

Kind regards

Appreciate the tips on getting a keyboard to work on Volumio/Chromium that suits. May consider a backlight switch at some point for now happy for screen to blank.

Excellent work, thank you from Down Under, Perth/Australia

Thank you, glad it was helpful!

I missed that one! To correct for it delete (or comment out) line 78 lastStatus = "" # clear lastStatus so as to stop calling this and that will resume the correct behaviour of resuming playback if it was playing when turned off.

For a quick explanation of what the issue was (and I apologise if this is hard to read, I struggle to write what is clear in my head!!). That line was clearing the varible lastStatus when the button was pressed to restore the backlight. This meant that when later in the code (line 122) it reacted to the stateChange of resume the lastStatus was already clear and thus ‘not play’ and so didn’t resume playback. Removing the above line means that lastStatus is cleared AFTER the resume command has happened.

Hope that explains a bit! Maybe?! :laughing:

Thank you for the kind words, glad it was useful!

Of course! It was already a bit late while trying to understand your code. While looking into the script this morning I thought already that this line is causing it. Removing that line solved the issue perfectly. It now resumes playing. Thx!

Due to the fact that I’m using a Hifiberry AMP2 I liked to mute / unmute the volume as well while switching BL off so I modified the script a bit (adding additional lines with mute / unmute commands…

Mute in case of stateChange == blOff:

      if (stateChange == "blOff"):
         os.system("volumio volume mute")               #mute volume 
         if (status["status"] == "play"):                  #check if currently playing
            os.system("volumio pause")                     #pause playback
            lastStatus = "play"                           #store that the unit was playing when backlight turned off

Unmute in case of stateChange == “resume”:

         elif (stateChange == "resume"):                     #restore bl level and start playing (if paused when turning off bl)
            os.system("volumio volume unmute")               #unmute volume
            blState = lastBlState
            if (lastStatus == "play"):
               os.system("volumio play")
               lastStatus = ""

Of course! It was already a bit late while trying to understand your code. While looking into the script this morning I thought already that this line is causing it. Removing that line solved the issue perfectly. It now resumes playing. Thx!

Due to the fact that I’m using a Hifiberry AMP2 I liked to mute / unmute the volume as well while switching BL off so I modified the script a bit (adding additional lines with mute / unmute commands…

Mute in case of stateChange == blOff:

      if (stateChange == "blOff"):
         os.system("volumio volume mute")               #mute volume 
         if (status["status"] == "play"):                  #check if currently playing
            os.system("volumio pause")                     #pause playback
            lastStatus = "play"                           #store that the unit was playing when backlight turned off

Unmute in case of stateChange == “resume”:

         elif (stateChange == "resume"):                     #restore bl level and start playing (if paused when turning off bl)
            os.system("volumio volume unmute")               #unmute volume
            blState = lastBlState
            if (lastStatus == "play"):
               os.system("volumio play")
               lastStatus = ""

Thanks for those suggestions, I’ve added them in to the main code now :slight_smile:

About reading my code, I am a hobby coder so anyone who knows how to code professionally is probably cringing at my listing LOL

I’m still struggling getting the onscreen keyboard running. I checked the changes to be made back and forth and coudn’t find any error. The keyboard is still not displayed when setting the cursor in a field requiring input.

Could anyone guide me in solving the issue? What files, logs etc. do I have to check to find the problem?

BTW: I’m using the waveshare 7inch display connected by HDMI and USB, not the original Pi.

https://www.waveshare.com/product/7inch-hdmi-lcd-c.htm

Finally I wonder if we will have smartroads modifications as option in Volumio. Maybe not the Phyton stuff suppurting the button. That might be to special.

Great documentation making us all near “experts”. Appreciate the effort and enjoying the product

I wish there was a way to change the colours without it wrecking the updates - there must be a way to have a CSS file that can be referenced to the colours and then in the web interface have the ability to pick colours for different elements.

:blush: thank you! However I still want to say that I have only collated most of the info (other than my python script!). Kudos must go to the original authors :smiley:

@fm-maniac
BTW: I’m using the waveshare 7inch display connected by HDMI and USB, not the original Pi.

waveshare.com/product/7inch-hdmi-lcd-c.htm

Note that this requires additional drivers, software et al related to the wave share. Which may be a challenge to get going on Volumio as you will need to manually update for this each time an upgrade comes out (Educated guess).

Note on the Wave Share site:
waveshare.com/wiki/7inch_HDMI_LCD_(B_(Firmware_Rev_1.1)_User_Manual

Seems to cover requirements.

@gordont

At least for the standard Volumio stuff (having the web-interface displayed and controlling the UI by the capacitive touch display) it works without any modifications!

It’s just that I didn’t get the onscreen keyboard displayed.

Am assuming you tried the matchbox package as mentioned in the guide? This did not work?

Think you have to read and work on the as mentioned waveshare page, here
waveshare.com/wiki/7inch_HDMI_LCD_(B_(Firmware_Rev_1.1)_User_Manual#Virtual_keyboard_of_Raspberry_Pi

Seems closer to what you are looking for. Though that one suggests to me you have at least a Raspbian Lite installed which Volumio image is cut down from that. Seems to imply matchbox works though setting it is through an X server display command.

Hello
Is this function already working?

“screenDelay = 30 # number of minutes before turning off the screen”

For me, the screen is always on and does not go out after 30 minutes.
Thank you

Hi yes it is working fine for me, which screen are you using?

Official LCD 7 Rapsberry Pi. The function works, but then when the music stops playing. I thought that this function also turns the LCD off when playing music.

No, as it is at the moment, the screen will stay on while it is playing and then when music stops/pauses then it will wait before turning the screen off. I thought it would be best to keep the screen on when playing as it is the only way to interact with the player for me :slight_smile: