LCD display and buttons in Python (tutorial and code)

Raspberry Pi related support

Re: LCD display and buttons in Python (tutorial and code)

Postby matock » 09 Dec 2015, 23:07

Hi all,

Now, I would like to run automatically the RA_LCD_Buttons.py script at boot. I read that you failed, so I also try.
Following several post in that topic, and also the systemd documentation, I created a new service:

/usr/lib/systemd/system/ra-lcd-buttons.service

Code: Select all
[Unit]
Description=RA_LCD_Buttons service
After=system-modules-load.services

[Service]
Type=simple
ExecStart=/usr/bin/python2 /root/RA_LCD_Buttons.py >/dev/null 2>&1

[Install]
WantedBy=multi-user.target

then I enable the service by
Code: Select all
systemctl enable ra-lcd-buttons.service

If I launch it manually, it works perfectly
Code: Select all
systemctl start ra-lcd-buttons.service

but after reboot the script is not launched. It failed. When I check the status I have
Code: Select all
systemctl status ra-lcd-buttons.service

* ra-lcd-buttons.service - RA_LCD_Buttons service
   Loaded: loaded (/usr/lib/systemd/system/ra-lcd-buttons.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 1970-01-01 01:00:10 CET; 45 years 11 months ago
 Main PID: 180 (code=exited, status=1/FAILURE)

If I check with
Code: Select all
 systemctl list-unit-files

it appears correctly in the list with the satus enabled.

I guess there is a dependancy error and that the Python script is starting too early, i.e. before MPD. I tried several solution:
1/ After=mpd.service
2/ Type=idle
3/ ExecStart in /etc/, in /root/, Python file, Bash file...
but without any succes.

What's going wrong?
I would appreciate any help. Thank you.

Matock
matock
 
Posts: 10
Joined: 22 Nov 2015, 18:43

Re: LCD display and buttons in Python (tutorial and code)

Postby XploD » 10 Dec 2015, 00:35

I managed to solve this problem by delaying the start, here is my .service file:

Code: Select all
[Unit]
Description=Test
After=network.target

[Service]
ExecStartPre=/usr/bin/sh -c "sleep 20"
ExecStart=/usr/bin/python2 /root/RuneAudioLCD/start.py
TimeoutSec=0
Restart=on-failure

[Install]
WantedBy=multi-user.target


Just be careful, my ExecStart is different because now I'm using a different script.
Music taste: xplodmusic @ Last.fm
Audio source: Raspberry Pi 2 + Sabre ES9023 DAC + WD 500 GB HDD + TP-Link TL-WN722N Wi-Fi + D-LINK Dub H7 USB hub
Hi-Fi: Phillips DCD-7010
Mixer: Nady Audio MM-242
Misc: Tube Stereo Vumeter (Magic Eye)
User avatar
XploD
 
Posts: 77
Joined: 24 Mar 2015, 18:32
Location: Croatia

Re: LCD display and buttons in Python (tutorial and code)

Postby matock » 11 Dec 2015, 09:06

Fantastic XploD !

The combination of "After=network.target" and "sleep" is the good one (in my case 2s is enough). And the Restart=on-failure offers a guarantie that anyway it will be started.

Thank you very much for your help.
matock
 
Posts: 10
Joined: 22 Nov 2015, 18:43

Re: LCD display and buttons in Python (tutorial and code)

Postby XploD » 11 Dec 2015, 12:40

You're welcome ;)

Sent from my Sony Xperia Z1 using Tapatalk
Music taste: xplodmusic @ Last.fm
Audio source: Raspberry Pi 2 + Sabre ES9023 DAC + WD 500 GB HDD + TP-Link TL-WN722N Wi-Fi + D-LINK Dub H7 USB hub
Hi-Fi: Phillips DCD-7010
Mixer: Nady Audio MM-242
Misc: Tube Stereo Vumeter (Magic Eye)
User avatar
XploD
 
Posts: 77
Joined: 24 Mar 2015, 18:32
Location: Croatia

Re: LCD display and buttons in Python (tutorial and code)

Postby zzeromin » 14 Feb 2016, 11:06

XploD wrote:And more (due to only 3 files per post):


Thanks for making 'RuneAudioLCD' to XploD.

Now I'm using your code (https://github.com/RandyCupic/RuneAudioLCD).

I have one question. I want to show [CPU temp, ram, clock, uptime] information and eth0 or wlan0 IP address on my 16*02(20*04) lcd.
I found that related codes in 'display.py'. but I dont know how to show information.
Would you like to give some tips?

XploD. Thanks again.
zzeromin
 
Posts: 7
Joined: 22 Jan 2016, 00:39
Location: South Korea

Re: LCD display and buttons in Python (tutorial and code)

Postby XploD » 14 Feb 2016, 11:21

zzeromin wrote:
XploD wrote:And more (due to only 3 files per post):


Thanks for making 'RuneAudioLCD' to XploD.

Now I'm using your code (https://github.com/RandyCupic/RuneAudioLCD).

I have one question. I want to show [CPU temp, ram, clock, uptime] information and eth0 or wlan0 IP address on my 16*02(20*04) lcd.
I found that related codes in 'display.py'. but I dont know how to show information.
Would you like to give some tips?

XploD. Thanks again.


Hi zzeromin,

You're welcome! Are you using an IR remote on your system? Currently, there are few screens to choose. On 20x4 LCD, there are 3 screens and on 16x2 there are 6 of them:
1) artist and song
2) elapsed and total time, bitrate, type (RADIO, FILE)
3) eth0 and wlan0 ip addresses
4) uptime and playtime
5) date and time
6) cpu temp, used/available RAM

You have to switch between those screens, which is currently implemented so it must be invoked with the IR remote. For IR remote, a pipeline is used. Open "start.py" and on line 103 you will find this:

Code: Select all
IR_PIPELINE = '/tmp/irpipe'


Here you can see irpipe path (default is 'tmp/irpipe' if you haven't changed it). Now open "ir_remote.py" and here you will find this (from line 31):

Code: Select all
# Change display mode
if (message == 'KEY_ENTER'):
   if (self.display != False):
      self.display.change_screen()


Here you can see which key name is for changing screen (default is 'KEY_ENTER'). Then, while RA_LCD program is running, try to enter this into console (if you're running RA_LCD directly from console, the console will be busy so open another console/ssh):

Code: Select all
echo "KEY_ENTER" > /tmp/irpipe


And the screen should be changed. You can enter this command again to pass to third screen etc. If you're using an IR remote, just pust this command on one of the keys and you will be able to change screens with your remote. For example:

Code: Select all
begin
prog = irexec
button = KEY_ENTER
config = echo "KEY_ENTER" > /tmp/irpipe
repeat = 0


If you're not using an remote, you will have to use a physical button or something. You have to call 'change_screen()' method from display.py class and the screen will get changed.
Music taste: xplodmusic @ Last.fm
Audio source: Raspberry Pi 2 + Sabre ES9023 DAC + WD 500 GB HDD + TP-Link TL-WN722N Wi-Fi + D-LINK Dub H7 USB hub
Hi-Fi: Phillips DCD-7010
Mixer: Nady Audio MM-242
Misc: Tube Stereo Vumeter (Magic Eye)
User avatar
XploD
 
Posts: 77
Joined: 24 Mar 2015, 18:32
Location: Croatia

Re: LCD display and buttons in Python (tutorial and code)

Postby zzeromin » 15 Feb 2016, 07:58

Thanks for great explanation to xplod.
It's really fantastic awesome!
Now I can do it. :)
I refered to this installation. http://buzzthisnow.com/ir-remote-with-lirc-on-raspberry-pi-2-running-runeaudio-archlinux/
[youtube] https://youtu.be/NwBvX7HlNc4 [/youtube]
[youtube] https://youtu.be/OynFcQH7uLw [/youtube]

I'd like to show you one homepage. This site name is 'Raspberry-Pi Village'.
I'm member of Raspberry-Pi Village. Every members thanks to you because of your awesome codes.
We made mini-project using your code. http://www.rasplay.org/?p=24077
maybe you can't understand because language is Korean. sorry... plz see some photos and youtube.

XploD. Thank you so much.
Last edited by zzeromin on 16 Feb 2016, 01:27, edited 2 times in total.
zzeromin
 
Posts: 7
Joined: 22 Jan 2016, 00:39
Location: South Korea

Re: LCD display and buttons in Python (tutorial and code)

Postby XploD » 15 Feb 2016, 17:06

Hi,

Good to hear that you got it to work, you're welcome. I'll take a look when I come home. If I understood it right, are you using RuneAudio and RetroPie in dual boot or you use multiple SD cards?

Sent from my Sony Xperia Z1 using Tapatalk
Music taste: xplodmusic @ Last.fm
Audio source: Raspberry Pi 2 + Sabre ES9023 DAC + WD 500 GB HDD + TP-Link TL-WN722N Wi-Fi + D-LINK Dub H7 USB hub
Hi-Fi: Phillips DCD-7010
Mixer: Nady Audio MM-242
Misc: Tube Stereo Vumeter (Magic Eye)
User avatar
XploD
 
Posts: 77
Joined: 24 Mar 2015, 18:32
Location: Croatia

Re: LCD display and buttons in Python (tutorial and code)

Postby zzeromin » 16 Feb 2016, 01:33

Hi XploD.

That is a good idea. But we are using OSMC with RetroPie dual boot.
As you said before I hope to make dual booting between RuneAudio and RetroPie in one SD card next time.

Thank you for great supporting.
zzeromin
 
Posts: 7
Joined: 22 Jan 2016, 00:39
Location: South Korea

Re: LCD display and buttons in Python (tutorial and code)

Postby Cirrhosis » 17 Mar 2016, 19:15

Hello!
I have Raspberi Pi B rev.2 and 2B. Also, there is a simple display 16X2 and 16X2 bus i2c. I tried to do by steps as described XPLOD. But a lot of links does not work. Linux for me to complete darkness. Does anyone have a working image of what would be written on the SD, connect the display and that everything would work? Controls not necessary.
Sorry for the English. This is Google Translate.
Cirrhosis
 
Posts: 4
Joined: 17 Mar 2016, 18:41

support RuneAudio Donate with PayPal

PreviousNext

Return to Raspberry Pi

Who is online

Users browsing this forum: No registered users and 4 guests