Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added feature to use LCD displays based on HD44780 connected via i2c … #859

Merged
merged 3 commits into from
May 15, 2020

Conversation

SimonChelkowski
Copy link
Contributor

…bus.

Hi all,

I created this pull request related to the open issue #498. The code has been created in collaboration with @davidfri

The pull requests adds the feature to use LCD displays based on HD44780 connected via i2c bus for this project. The following displays have been used for testing:

  • 2x16 display
  • 4x20 display (recommended as more information can be displayed)

Various informations such as artist, album, track_number, track_title, track_time and many more can be displayed see main script for more siplay options.

The added files are:

  • misc/sampleconfigs/i2c-lcd.service.default.sample
  • scripts/i2c_lcd.py
  • scripts/i2c_lcd_driver.py

The first is used as sample service file that runs the i2c_lcd.py main script at boot-up if the service is properly installed (install description can be found below.).
The second file is the main LCD script that makes use of I2C_LCD_driver.py.
The third file is the library needed to drive the LCD via i2c, originates from DenisFromHR (Denis Pleic) see http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming

Installation

  1. You need to install additional python libraries. Run the following two command in the command line:
    sudo apt-get install i2c-tools python-smbus python3-numpy python-mpdclient python-mpd
    pip install smbus numpy python-mpd2
  2. You need to know which I2C bus your Raspberry Pi has available on GPIOs:
    ls /dev/i2c-*
    It'll output "/dev/i2c-x", where x is your bus number. Note this bus number as you will need it in step 6.
  3. Now detect the adapter by using the i2cdetect command, inserting your bus number:
    sudo i2cdetect -y bus_number
    The I2C address of my LCD is 27. Take note of this number, it will be need in step 6.
  4. if i2cdetect is not found install i2c-tools
    sudo apt-get update
    sudo apt-get install i2c-tools
  5. Next we need to install SMBUS, which gives the Python library we’re going to use access to the I2C bus on the Pi. At the command prompt, enter
    sudo apt-get install python-smbus
  6. Modify "i2c_lcd_driver.py" line 19 which reads "I2CBUS = 1" and adapt it to your bus number (see step 2.) Furthermore modify line 22 which reads "ADDRESS = 0x27" and adapt it to your I2C address (see step 3.)
  7. Modify "i2c_lcd.py" to adapt it yo your specific display e.g. 2x16 or 4x20 (default). The lines 15-19 look like the following:
## Display settings                                                                     ##
n_cols = 20                 # EDIT!!!  <-- number of cols your display has              ##
n_rows = 4                  # EDIT!!!  <-- number of rows your display has              ##
val_delay = 0.4             # EDIT!!!  <-- speed of the scolling text                   ##

Check if "n_cols" and "n_rows" need to be changed and modify them if necessary. The "val_delay" constant leave for the time being. Lower values will speed up things but will make the text less visible/readable.

  1. next install and start "i2c-lcd.service"
    sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/i2c-lcd.service.default.sample /etc/systemd/system/i2c-lcd.service
  2. register service by running, it will thereby start on the next boot-up
    sudo systemctl enable i2c-lcd
  3. reboot and enjoy!
    For test purposes you can use the following command to start and stop the service without rebooting
    to start the service instantly run
    sudo systemctl start i2c-lcd
    to stop the service instantly run
    sudo systemctl stop i2c-lcd

Best regards,
Simon

SimonChelkowski and others added 2 commits March 13, 2020 21:46
…bus.

The added files are:
- misc/sampleconfigs/i2c-lcd.service.default.sample
- scripts/i2c_lcd.py
- scripts/i2c_lcd_driver.py

The first is used as sample service file that runs the i2c_lcd.py main script at boot-up if the service is properly installed.
The second file is the main LCD script that makes use of I2C_LCD_driver.py.
The third file is the library needed to drive the LCD via i2c, originates from DenisFromHR (Denis Pleic) see http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming

--- Installation ---

1. you need to install additional python libraries. Run the following two command in the command line:
	sudo apt-get install i2c-tools python-smbus python3-numpy python-mpdclient python-mpd

	pip install smbus numpy python-mpd2

2 You need to know which I2C bus your Raspberry Pi has available on GPIOs:
	ls /dev/i2c-*
It'll output "/dev/i2c-x", where x is your bus number. Note this bus number as you will need it in step 6.
3. Now detect the adapter by using the i2cdetect command, inserting your bus number:
	sudo i2cdetect -y bus_number
The I2C address of my LCD is 27. Take note of this number, it will be need in step 6.
4. if i2cdetect is not found install i2c-tools
	sudo apt-get update
	sudo apt-get install i2c-tools
5. Next we need to install SMBUS, which gives the Python library we’re going to use access to the I2C bus on the Pi. At the command prompt, enter
	sudo apt-get install python-smbus
6. Modify "i2c_lcd_driver.py" line 19 which reads "I2CBUS = 1" and adapt it to your bus number (see step 2.) Furthermore modify line 22 which reads "ADDRESS = 0x27" and adapt it to your I2C address (see step 3.)
7. Modify "i2c_lcd.py" to adapt it yo your specific display e.g. 2x16 or 4x20 (default). The lines 15-19 look like the following:
	################# CHANGE YOUR SETTINGS HERE!!! ###########################################
	## Display settings                                                                     ##
	n_cols = 20                 # EDIT!!!  <-- number of cols your display has              ##
	n_rows = 4                  # EDIT!!!  <-- number of rows your display has              ##
	val_delay = 0.4             # EDIT!!!  <-- speed of the scolling text                   ##
Check if "n_cols" and "n_rows" need to be changed and modify them if necessary. The "val_delay" constant leave for the time being. Lower values will speed up things but will make the text less visible/readable.

8. next install and start "i2c-lcd.service"
	sudo cp /home/pi/RPi-Jukebox-RFID/misc/sampleconfigs/i2c-lcd.service.default.sample /etc/systemd/system/i2c-lcd.service
9. register service by running, it will thereby start on the next boot-up
	sudo systemctl enable i2c-lcd
10. reboot and enjoy!
For test purposes you can use the following command to start and stop the service without rebooting
to start the service instantly run
	sudo systemctl start i2c-lcd
to stop the service instantly run
	sudo systemctl stop i2c-lcd
…" and "stop" state. It now makes use of the "pause_string" and teh "stop_string".
@s-martin
Copy link
Collaborator

Thanks very much for your PR!

A few minor suggestions:

If you have any questions, please post them here. Thank you.


"""
Compiled, mashed and generally mutilated 2014-2015 by Denis Pleic
Made available under GNU GENERAL PUBLIC LICENSE
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need t check, if the GPL license has any implications.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refert to FAQ about the GNU Licenses.

Under WhyUseGPL? is stated that

Using the GNU GPL will require that all the released improved versions be free software.

First, it states that GPL is a free software licence. Second even modifications are allowed but we even did not this, we just use the lcd_driver code in a non-modified version.

Last but not least we distribute the source code openly which is requested by GPL according to GPLRequireSourcePostedPublic.

if you release the modified version to the public

and again, we did not modify the code, we just use the code (the lcd_driver) here.

In conclusion, it is fine.

Best regards,
Simon

Copy link
Collaborator

@s-martin s-martin Mar 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disclaimer: I’m not a lawyer

Phoniebox code is licensed under MIT license, which is a permissive open source license. That means for example that you can relicense the code with very few restrictions. So you could integrate MIT licensed code in proprietary code.

In contrast GPL is a copyleft open source license, which expects that all code distributed together grants same degrees of freedom, i.e. not used in proprietary code.

So from my point of view we cannot integrate GPL code in the Phoniebox code base.
I think we need opinions from @MiczFlor here of course.
One possibility would be to ask the original author of the code, if this code could be relicensed under a permissive open source license.

Anybody else with more knowledge here than me is of course welcome. ;-)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @s-martin @SimonChelkowski
I fear that @s-martin is right, actually, well, I know that this is the case.
Which is a real shame... We can add this to the wiki. And refer to the wiki via the components folder. Should I do that?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the only solution I'm afraid. We could ask the author of that code, too.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will contact the author and ask for permission. In the meantime the wiki page is a very good idea and compromise. Thanks @MiczFlor for creating the wiki page.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I contacted the author and ask him for help in resolving this issue link. Let's wait and see how it develops.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @SimonChelkowski
I don't really mind if you or anybody else uses my code in any way - except in purely commercial projects.
So, as long as my code is used in Open Source projects (non-commercial), I'm OK with it.
Since RPi-Jukebox-RFID is free software (non-commercial), you have my explicit permission for using my 'RPi_I2C_driver.py' code.
Rgds,
Denis Pleic (DenisFromHR)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DenisFromHR thanks for the permission!

@MiczFlor, I guess we could merge it, when the other comments are resolved.

…o commits in the pull request MiczFlor#859 discussion.

- moved all files into teh components directory into the sub-dircetory /components/displays/HD44780-i2c/
- added shebang for Python3 for the driver and the main script
- removed the path to the executable (python3) from the sample service file
- added README.md file which describes the features, usage and installation of the code.

1. You need to install additional python libraries. Run the following two command in the command line:
`sudo apt-get install i2c-tools python-smbus python3-numpy python-mpdclient python-mpd`
`pip install smbus numpy python-mpd2`
Copy link
Collaborator

@s-martin s-martin Mar 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a requirements.txt file with all necessary pip packages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do so, soon.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimonChelkowski, isn't this redundant to install the apt packages and one line later the same(?) pip packages?

Copy link
Collaborator

@s-martin s-martin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Please add a requirements.txt file for the python dependencies

@MiczFlor
Copy link
Owner

MiczFlor commented May 3, 2020

Hi @SimonChelkowski
I would really like to merge this to develop. There is one request from @s-martin regarding the requirements.txt
#859 (review)
Could you provide this?

@MiczFlor MiczFlor merged commit 4fd2efa into MiczFlor:develop May 15, 2020
MiczFlor added a commit that referenced this pull request May 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhancement: Implementation of HD44780 LCD display (with and without I2C)
4 participants