LCD display and buttons in Python (tutorial and code)

Raspberry Pi related support

LCD display and buttons in Python (tutorial and code)

Postby XploD » 27 May 2015, 11:56

Attachments
schematic.jpg
schematic.jpg (204.31 KiB) Viewed 35453 times
DSC_1322.JPG
DSC_1322.JPG (138.35 KiB) Viewed 36154 times
Last edited by XploD on 05 Jul 2015, 12:21, edited 10 times in total.
Music taste:
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:
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 hondagx35 » 27 May 2015, 22:29

User avatar
hondagx35
 
Posts: 3042
Joined: 11 Sep 2014, 22:06
Location: Germany

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

Postby XploD » 27 May 2015, 23:49

Hello Frank. Thank you, you actually solved most of my problems :) I will rewrite the code as soon as find some time. I didn't know that there's a MPD library for Python. About interrupts, I know what they are and that they're mostly used for buttons, but I never tried them before on a Pi, especially in Python. It seems easy.

And this MPD library returns artist and title separated, no more problems with more than one " - " delimiter in text :) Thanks!

There's still slow RPLCD left (because it's the one that's using 20% of CPU), but AFAIK, there's Wiring Pi wrapper for Python which should be a lot faster than RPi.GPIO and RPLCD, so I will try to drive the LCD with this. The last solution is to drive LCD with a C program and then call it from Python.
Music taste:
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:
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 den_hr » 28 May 2015, 15:13

den_hr
 
Posts: 52
Joined: 06 Feb 2015, 17:10
Location: Croatia

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

Postby den_hr » 28 May 2015, 17:35

Ah, now I see that you're using an "ordinary" method of connecting LCDs... and my library and LCD use I2C - i.e. only 4 wires (power + and GND, SDA and SCL)... Lot less wires and a lot less mess :)

BTW, I2C LCDs are plentiful on ebay, and only slightly more expensive - and you get the I2C module with them, which makes it all work... with just 4 wires total (including power). Highly recommended :)
den_hr
 
Posts: 52
Joined: 06 Feb 2015, 17:10
Location: Croatia

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

Postby XploD » 28 May 2015, 17:50

Hello,

Thanks for your code. I already have scrolling but maybe I'll try yours for eventually better performance.

I tried:
- RPLCD
- 'manual' writting to LCD using RPi.GPIO
- 'manual' writting to LCD using WiringPi
- Adafruit LCD library

The lowest CPU usage is when using RPI.GPIO and manual writting but it has that problem of getting slow on song change as well. But Adafruit library works fine, so I choosed Adafruit, even it has the highest CPU usage. But, by using Adafruit, the tutorial will become more complicated since it's necessary to install the library which then gives error because it tries to use I2C and one module is missing, so I had to remove (comment) a few lines of code in Adafruit library to get it to work.

Have you tested your code with scrolling both lines, when the song changes? Does it get slow?

Yes, I use ordinary LCD with 4 data wires. I know they're not expensive, but I had this one at home so I'm experimenting with it. I was planning to get 4x20 LCD because this one is to small, I want to have current and total time as well as some other infos (like bitrate, current state etc.). So I will order one and then probably go for the I2C version. But I can't make a decision which one to get :mrgreen: I was thinking about getting an OLED version with black background and white text so I would be able to read it from higher distances but they're not cheap.

Also, this is not the final version, only testing. I will probably use Raspberry Pi 2 at my final version and surely a 4x20 LCD, because I want to have one device for movies and music so I want to make a dual-boot setup with OSMC and RuneAudio, which is currently not possible (at least, nobody succeeded at that, as far as I know) but I'm thinking about a "hardware" solution with 2 SD cards and a microcontroller to switch between SD cards.

Now I will replace button pooling with threaded interrupts, and pulling info from "mpc status" with MPD library for Python and then update the code and tutorial.

Pozdrav :)
Music taste:
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:
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 XploD » 28 May 2015, 23:22

Last edited by XploD on 05 Jul 2015, 11:43, edited 1 time in total.
Music taste:
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:
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 phuongdk » 30 May 2015, 03:46

Thanks XploD for your detail tutorial. I'll do it for mine on next week. But, in future, you'll use LCD 20x4 for more info from MPD, so can I use this LCD 20x4 for current tutorial, i still works?
Thanks ;)
User avatar
phuongdk
 
Posts: 7
Joined: 05 May 2015, 03:02

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

Postby XploD » 30 May 2015, 09:21

You're welcome.

You can try but I don't know if it will work. I guess it should work, but only first 2 lines will work and only first 16 charachters instead of 20. I will rewrite the code a little bit so that dimensions for line width are not hard coded so you can get all 20 charachters. There is currently one line at the beggining of the code where you set line width, and you can put this to 20, this is used to initialize LCD. But the part of the code for scrolling has hardcoded width 16.

And for the next two lines, I currently don't have a 20x4 LCD so I can't do this part, because I can't test. I can only do it blindly, without testing.

Let me know if something goes wrong and don't forget to make a backup if you have something that you don't want to lose.
Music taste:
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:
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 phuongdk » 17 Jun 2015, 03:06

Dear XploD,
I did all step without problem.
But when I run "python2 RA_LCD_Buttons.py" to execute your code, it has an error as images below:

Untitled.png
Untitled.png (71.6 KiB) Viewed 35735 times


I'm using Raspberry PI 2 (lastest version).
Please help me, thanks ;)
User avatar
phuongdk
 
Posts: 7
Joined: 05 May 2015, 03:02

support RuneAudio Donate with PayPal

Next

Return to Raspberry Pi

Who is online

Users browsing this forum: No registered users and 24 guests