[SOLVED] Help to attach a LCD 20x4 I2C to a Raspy A+ with Pi-DAC+

Hi all
My A+ and Pi-DAC work well together but now I want assemble a little audio multiplayer in a little aluminum case with a LCD. I googled many time to find information on how to connect all my stuff together over the Pi-DAC and which python libraries to use for compatibility with I2C.
I didn’t believe that I was thinking something strange but the mix of hardware that I’ve perhaps isn’t so common…
Could someone help me with link or instructions or tips?
Thanks a lot in advance

Just noticed this while looking for something else - the set up might offer some help https://volumio.org/forum/display-mpd-info-20x4-lcd-t1187.html

Hi Steve. Thanks for your help. I known that discussion but the library used RPLCD has a setting for 4 bit and 8 bit connection. I’ve I2C circuitry.
I’m trying to modify the setting but with no good results…
I’ll try again.

Ciao,
Massimo

There are a couple of threads on here already about attaching displays. I
don’t think they used that particular sound card so you’d have to find out
what header pins you have available and compare.

I’m trying to follow one of the most similar to my hardware and now I’m stuck on this problem:

Traceback (most recent call last):
File “main.py”, line 6, in
from LineController import *
File “/home/pi/raspi-mpd-lcd/LineController.py”, line 184, in class MPDLine(TextLine):
File “/home/pi/raspi-mpd-lcd/LineController.py”, line 185, in MPDLine from mpd import MPDClient
ImportError: No module named ‘mpd’

How can I manage the ‘mpd’ import?
This should be the last thing to fix before the final result.

I was thinking along the same lines and just this morning asked Wouter Van Wijk if he knows who put this little beauty together - not had a reply as yet…

https://pypi.python.org/pypi/python-mpd/ ?

This is the thread I was originally referring to: Anyone use the Mopidy Touchscreen Front end?

No because I’ve already MPD installed.
When I type mpd I receive an error for the log file not accessible, but the program is present.
I think that my problem is only when I try to import mpd library in the python program: ImportError: No module named ‘mpd’

The package I linked above is python-mpd, not MPD.

Sorry…
This should be the reason why I can’t reference mpd library :smile:
I’ll try it this evening and I’ll post an update here.
Thanks

GREAT! It worked for me but with some tricks
Now I’ve to write down all the steps and then I’ll upload a guide.
Thanks a lot kingosticks

As promised, the complete solution

########################

Started from the following post on raspberrypi.org by ‘arginine’ to display MPD information on a 20x4 LCD
https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=76326&p=545076#p545076

Then there is a link to a github project named “Raspberry Pi LCD library for the widely used Hitachi HD44780 controller, written in Python”:

That library is useful only to connect the LCD pin2pin by 4 or 8 bit and I have the I2C interface…

So I googled for I2C and founded this link: http://www.recantha.co.uk/blog/?p=4849#comment-547431 with explanation on how to use
20×4 LCD character display on a RaspberryPi with I2C interface. This is a generic discussion and not focused on MPD but many
comments down… bingo! User ‘supra’ posted a link very focused on MPD and I2C: https://github.com/speendo/raspi-mpd-lcd
This is a project not very well documented, but with some help in forums and googling I finally obtained the necessary information
to show MPD info on my LCD!
Download the zip and put it in a local directory on your Raspberry. This will be the start source path for the whole project and the main.py will be used to test the MPD2LCD.

Now, the instructions step by step:

  1. Enabling I2C in Raspbian - The I2C ports need to be enabled in Raspbian before they can be used.
    Edit the modules file
    sudo nano /etc/modules
    Add these lines:
    i2c-bcm2708
    i2c-dev
    Exit and save the file
    Now edit the modules blacklist file:
    sudo nano /etc/modprobe.d/raspi-blacklist.conf
    Add a ‘#’ character to this line so it commented out (ignore if your file is empty):
    #blacklist i2c-bcm2708
    Exit and save the file.
    ​Finally install the I2C utilities:
    sudo apt-get install python-smbus i2c-tools
    Enter “sudo reboot” to restart the pi and now the I2C pins will be available to use.

  2. Checking for connected devices
    At the command prompt type one of these depending on whether you are using the I2C0 or I2C1 port:
    sudo i2cdetect -y 0
    or
    sudo i2cdetect -y 1

  3. Could be necessary to setup the I2C environment on your Raspberry. Instructions for Raspbian are here.
    Create a folder for the project and change directory to it. To create one in your home folder:
    mkdir ~/myproject
    cd ~/myproject
    Install the Quick2Wire libraries and setup the environment.
    git clone https://github.com/quick2wire/quick2wire-python-api.git
    The following two steps will have to be done every time you login:
    export QUICK2WIRE_API_HOME=~/myproject/quick2wire-python-api ### ATTENTION: Replace myproject with your real directory ###
    export PYTHONPATH=$PYTHONPATH:$QUICK2WIRE_API_HOME
    To easily setup the environment every time without a login shell, put the two export lines above at the end of /etc/rc.local:
    sudo nano /etc/rc.local
    Install now the i2c libraries. Move into the directory you are going to create your python code and type:
    git clone https://bitbucket.org/thinkbowl/i2clibraries.git
    The Think Bowl I2CLibraries require python3. If python3 is not installed, perform the following
    sudo apt-get install python3

  4. Install the python setuptools
    sudo apt-get install python3-setuptools

  5. Install the python libraries to interface with MPD. The new version of python-mpd libraries is located on github and remember that it’s not backward compatibles with the original python-mpd packages, but this isn’t a problem for us:
    git clone git://github.com/Mic92/python-mpd2.git
    Install it
    python setup.py install

  6. Adding the “pi” user to i2c group
    sudo adduser pi i2c

  7. Finally, run the script to show info on LCD
    python3 main.py

  8. To run the script automatically without opening any shell, put the above command into the rc.local below the previous two export commands
    sudo nano /etc/rc.local
    # Start MPD 2 LCD
    export QUICK2WIRE_API_HOME=/home/pi/raspi-mpd-lcd/quick2wire-python-api
    export PYTHONPATH=$PYTHONPATH:$QUICK2WIRE_API_HOME
    (sleep 10; python3 /home/pi/raspi-mpd-lcd/main.py)&

Hi, I´m trying to get my 20x04 working and I go along the guide from Smemo1024.
I think I have done everything like described. But if I start main.py I get stuck on this problem:

Traceback (most recent call last):
File “main.py”, line 6, in
from lcd_controller import *
File “/root/myproject/lcd_controller.py”, line 4, in
from . import lcd_driver
ValueError: Attempted relative import in non-package

Can some one help me?

Hi, I’m getting exactly the same issue as Sonnen_Tau:

“Traceback (most recent call last):
File “main.py”, line 6, in
from lcd_controller import *
File “/root/myproject/lcd_controller.py”, line 4, in
from . import lcd_driver
ValueError: Attempted relative import in non-package”

Could someone point me in the right direction please?

Excited to get this working and finish my PiMusicBox project completed.

Thanks.

second google result gives me https://www.quora.com/What-is-the-core-reason-for-this-error-Attempted-relative-import-in-non-package-in-Python which looks like a good read.

Hey, thanks for the quick reply!

Yeah I read a couple of Google results, but they far exceed my noobness I’m afraid.

Had hoped I’d simply installed incorrectly from the directions, afraid that kind of coding is way beyond my skill level.

Ah well, works fine without the LCD, would have been a nice to have.

Cheers.

Checked there was a __init__.py present in the folder and tried running with “python3 -m”

Solution #1: You can do a simple package import instead of relative. That is, instead of:
from . import jpg
You can do just:
import jpg

So edit /root/myproject/lcd_controller.py from

from . import lcd_driver

to be

import lcd_driver

And probably similarly for other places e.g. /root/myproject/lcd_driver.py

However, the instructions you are following here are really old. Raspbian has changed and this might not even work anymore. I’m pretty sure that’s not how i2c is enabled these days, perhaps it still works.

Hi, thanks, I really appreciate this.

Updated the various .py files using 'from . import", executes a little further.

It now states “ImportError: No module named smbus”

Python smbus is installed though.

I may need to go back to hunting for a more up to date solution…

Cheers

Installing Python3 smbus fixed that, now get: “No module named mpd”

but had already installed python-mpd2 from the above instructions