Coder Social home page Coder Social logo

the-raspberry-pi-guy / lcd Goto Github PK

View Code? Open in Web Editor NEW
176.0 13.0 106.0 22.83 MB

This repository contains all of the code for interfacing with a 16x2 Character I2C LCD Display. This accompanies my YouTube tutorial here: https://www.youtube.com/watch?v=fR5XhHYzUK0

Python 86.36% Shell 13.64%
lcd raspberry-pi

lcd's Introduction

LCD

This repository contains all the code for interfacing with a 16x2 character I2C liquid-crystal display (LCD). This accompanies my Youtube tutorial: Raspberry Pi - Mini LCD Display Tutorial.

You can buy one of these great little I2C LCD on eBay or somewhere like the Pi Hut.

Table of Contents

  1. Installation
  2. Demos
  3. Implementation
  4. Contributions

Installation

  • Install git

    sudo apt install git
  • Clone the repo in your home directory

    cd /home/${USER}/
    git clone https://github.com/the-raspberry-pi-guy/lcd.git
    cd lcd/
  • Run the automatic installation script with sudo permission

    sudo ./install.sh
  • During the installation, pay attention to any messages about python and python3 usage, as they inform which version you should use to interface with the LCD driver. For example:

    [LCD] [INFO] You may use either 'python' or 'python3' to interface with the lcd.

    or alternatively,

    [LCD] [INFO] Use 'python3' to interface with the lcd.
  • At the end of the installation script, you'll be prompted to reboot the RPi to apply the changes made to /boot/config.txt and /etc/modules.

  • After rebooting, try one of the demos:

    ./home/${USER}/lcd/demo_clock.py

    or

    python /home/${USER}/lcd/demo_clock.py

    or

    python3 /home/${USER}/lcd/demo_clock.py

top ⬆️

Demos

A list of demonstration (demo) files that illustrate how to use the LCD driver. Demos are ordered alphabetically.

Backlight Control

This demo showcases the backlight control of the LCD, which is available on some hardware:

Custom characters

It is possible to define in CG RAM memory up to 8 custom characters. These characters can be prompted on LCD the same way as any characters from the characters table. Codes for the custom characters are unique and as follows:

  1. {0x00}
  2. {0x01}
  3. {0x02}
  4. {0x03}
  5. {0x04}
  6. {0x05}
  7. {0x06}
  8. {0x07}

Please, see the comments and implementation in the demo_lcd_custom_characters.py file for more details on how to use custom characters. Thanks to @Jumitti, there is also a web app you can use to generate custom characters by drawing them on a matrix.

Extended strings

This is demo showcases how extended strings could be used. Extended strings can contain special placeholders of form {0xFF}, that is, a hex code of the symbol wrapped within curly brackets. Hex codes of various symbols can be found in the following characters table:

For example, the hex code of the symbol ö is 0xEF, and so this symbol could be printed on the second row of the display by using the {0xEF} placeholder, as follows:

display.lcd_display_extended_string("{0xEF}", 2)

If you want to combine placeholder to write a symbol {0xFF} with the native Python placeholder {0} for inserting dome data into text, escape the non-native placeholders. Here is an example:

display.lcd_display_extended_string("Symbol:{{0xEF}} data:{0}".format(5), 2)

Home Automation

This implementation shows how to use the LCD to display messages from temperature sensors and services such as Spotify and Trakt (see below). The implementation also features an integration with Telegram to turn the LCD backlight on/off and send a few other commands to control the host machine (e.g., get the temperature, reboot, shutdown). @Jumitti documented the project on its own Home Automation repository, so make sure to check it out if you want to learn more about it.

IP Address

Display your Pi's IP address, which is useful for SSH access and more!

LCD demo

This demo shows how simple strings could be displayed on the LCD. For extended usage, take a look at Extended strings demo instead.

NetMonitor

This demo uses ping and nc (netcat) to monitor the network status of hosts and services, respectively. Hosts and services can be modified by editing their respective dictionaries:

hosts = {
    'Internet': '8.8.8.8',
    'Firewall': '192.168.1.1',
    'NAS': '192.168.1.2'
}
services = {
    'Cameras': {'ip': '192.168.1.2', 'port': '8000'},
    'Plex': {'ip': '192.168.1.2', 'port': '32400'}
}

Progress bar

This is a demo of a graphical progress bar created with custom characters. This bar could be used, for example, for showing the current level of battery charge.

Tiny dashboard

This is a script that shows a famous quote, a currency conversion pair of your choice and the weather of a city. It also shows the last three characters from your ip address, the date in DDMM format and the hour in HH:MM format

The script takes info from the following APIs:

  • quotable.io: Free public API that provides famous quotes from well known people. It has a public endpoint that doesn't require an API key.

  • exchangerate-api.com / free.currencyconverterapi.com: There are a lot of currency apis but these ones offer free currency exchange info. Both are used, one as main, the other as backup. Requires an API key to use.

  • openweathermap.org: Provides Weather info, forecasts, etc. Requires an API key to use.

In order to use the script, you need to get API key tokens for both exchange rate services and the weather api. Once you've done that, edit the script to put your tokens in the USER VARIABLES section.

Also set a currency exchange pair. For currency support and the currency codes you need to use, see exchangerate-api.com/docs/supported-currencies.

A city/country string is also needed to show weather info for such city. Search for your city on openweathermap.org and take note of the City,country string and put it in the script.London,gb is given as an example.

top ⬆️

Implementation

Once you are done editing a demo_*.py file or writing your own Python script, follow the instructions on this section to run the script in the background. First, however, ensure that the script (e.g., script.py) has at least permission to be executed, as follows:

sudo chmod +x script.py

Similarly, file ownership can be configured via chown. For example, to set the user ${USER} as owner of the file script.py, run the following:

sudo chown ${USER} script.py

Systemd

Use the following procedure to run any LCD Python script as a (systemd) service:

  1. Create a new unit file in /lib/systemd/system/ called rpi-lcd.service:

    sudo nano /lib/systemd/system/rpi-lcd.service
  2. Copy and paste the following in the new unit file:

    (If your user is different than pi, remember to edit the User= entry.)

    [Unit]
    Description=RPi Python script for a 16x2 LCD
    
    [Service]
    Type=simple
    ## Edit the following according to the script permissions
    User=pi
    #Group=users
    
    ## Edit the following with the full path to the compatible Python version and your script
    ExecStart=/usr/bin/python /path/to/script.py
    
    Restart=always
    RestartSec=5
    
    KillMode=process
    KillSignal=SIGINT
    
    [Install]
    WantedBy=multi-user.target
  3. Enable the service and start it:

    sudo systemctl enable rpi-lcd.service
    sudo systemctl start rpi-lcd.service
  4. Check that the LCD is displaying the correct information; otherwise, check the service status:

    systemctl status rpi-lcd.service

top ⬆️

Contributions

Thank you for you interest in learning how to contribute to this repository. We welcome contributions from novices to experts alike, so do not be afraid to give it a try if you are new to git and GitHub. First, however, take a few minutes to read our CONTRIBUTING.md guide to learn how to open Issues and the various sorts of Pull Requests (PRs) that are currently accepted.

In addition, if you've never contributed to an open source project before, please take a look at the following resources:

top ⬆️

lcd's People

Contributors

bariskisir avatar cgomesu avatar didaquis avatar jdarias avatar julianbruegger avatar jumitti avatar juvus avatar kubzelll avatar kyuchumimo avatar msneloy avatar the-raspberry-pi-guy avatar tomtom0201 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lcd's Issues

Backlight control

Is there any backlight control (e.g. on/off) available in your driver?

turn off the backlight

Is it possible to turn off the backlight of the display?
I tried modifying your class adding these methods but it didn't work:

   # backlight off
   def lcd_backlight_off(self):
       self.lcd_write(LCD_NOBACKLIGHT)

   # backlight on
   def lcd_backlight_on(self):
       self.lcd_write(LCD_BACKLIGHT)

Removal of the default 'pi' user

Describe the issue

The default "pi" user is being removed from future releases of the Raspberry Pi OS. This impacts one of our documentation files because it assumes that the user is pi instead of anything else. In README.md, for example:

  • Clone the repo in your pi home directory
cd /home/pi/
git clone https://github.com/the-raspberry-pi-guy/lcd.git
cd lcd/

An alternative is to use ${USER} instead of pi in any existing command, which should be backwards compatible (that is, anyone running as pi will output the pi user just like before). The Implementation subsection of README.md, however, needs to be further modified to accommodate such a change.

Document

  • File: README.md

BACKLIGHT can't stay in OFF mode

Describe the bug
As soon as an LCD update is carried out, the backlight is automatically activated. So when I do lcd_backlight(0), it only works for one update.

Executed command and associated error
n.d

Host and software info

  • RPi board version: RPi 4 RPi 3

Checklist

Additional context
n.d

cc.load_custom_characters_data() not working

Describe the bug
Im trying the custom character functionality with a (not really) bitmap and also just writing it and it is giving me an error.

Executed command and associated error

cc.load_custom_characters_data()
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/flask/app.py", line 2525, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1822, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1820, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/flask/app.py", line 1796, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/panda/lcd/Bitmap editor test/Bitmap editor test/web-server.py", line 17, in get_bitmap
    cc.load_custom_characters_data()
  File "/home/panda/lcd/Bitmap editor test/Bitmap editor test/drivers/i2c_dev.py", line 284, in load_custom_characters_data
    self.lcd.lcd_write(int(binary_str_cmd, 2), Rs)
                       ^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 2: '0b000"00000", "00000", "00000", "00100", "00000", "00000", "00000", "00000"'

Host and software info

  • RPi board version: revision 1.2
  • OS version: 12`
  • (If Python related.) Python version : 3.11.2

Checklist

  • I have watched and followed the instructions in the Youtube tutorial.
  • I have searched open and closed issues for either an identical or similar bug before reporting this new one.
  • (If Python related.) I have used Python 2.7

Additional context
It is a Flask web server program with a (lets say) bitmap editor to write custom character data.

smbus not reconized???

I followed through with your yt tutorial threough until the wnd so when I tried the demo this error showed up. Please help you are amazing for making this code.
image

ModuleNotFoundError: No module named 'i2c_dev'

Hello, I used your code last year with Python2, now i wrote a new program in Python3 and i got this error, I have searched in the network but i don't found any result to fix this problem, sorry If i made any mistake writing in this part, i recently entered in github

I followed all your steeps from your youtube video.

Traceback (most recent call last):
File "demo_clock.py", line 8, in
import drivers
File "/home/pi/lcd/drivers/init.py", line 1, in
from i2c_dev import Lcd
ModuleNotFoundError: No module named 'i2c_dev'

Thanks!

LCD Spotify Now Playing + Telegram Bot

Hello everyone

First of all, I apologize if this is not the right place to post this.

I didn't find any bugs or anything but I coded a "small" script. So I would like to know if you are interested in having it in demo or not. Besides, I think that if it interests you, you will perhaps ask me to separate it into several small demos.

Let me explain. I manage Telegram bots quite well. The advantage is that you can run these bots on a Raspberry and communicate with them to execute commands on the Raspberry (even when you are not at home and you cannot make SSH connections). I use it to know the temperature of my CPU when the Raspberry is doing complicated calculations or something else, to make it do updates and also different little things. In fact, as long as you code your bot well, you can make it do what you want on Raspberry since it's python. I then decided to add a DS18B20 thermal probe to my Raspberry (because the CPU heats up okay but in my house it's cold so I might as well know if I'm going to die of hypothermia soon or not). In addition to that, I added additional fans if the CPU temperature rises too much to cool it down.

Well and with all that, I found it stupid not to have a nice little display. So, I bought a 16x2 LCD and I made my first script for the LCD:

  • Display the date, time, CPU temperature and my house temperature.

At that time I was starting out in coding (this dates back to 2019) so the Telegram bot and the LCD script were not in one and the same script and that caused a lot of problems. I have since fixed it.

I wanted to go further so I officially implemented the Telegram bot in the LCD script and it allows you to turn the backlight on and off as you wish only via Telegram. But theoretically, you can write personalized messages (for flirting it's perfect) etc etc..

And finally, when I code I have music playing loudly. What if we added a function that allows us to display what we are listening to on Spotify? It's done too

Overall, I know that there are a lot of functions and that it goes in all directions. And that's why I prefer to see if it might interest people or not :)

Let me know what you think about it :)

Julien

Flashing cursor

I've got this working. But at the end of my text I always have a flashing cursor. Is there a way to turn that flashing cursor off?

Cannot run install.sh

Describe the bug
Cannot run install.sh

Executed command and associated error

sudo sh install.sh # i also tried using sudo install.sh
install.sh: 21: ./setup.sh: Permission denied

Host and software info

  • RPi board version: Pi 4B
  • OS version: Raspberry PI OS 64 bit released 2022-09-22
  • (If shell related.) Shell: GNU bash, version 5.1.4(1)-release (aarch64-unknown-linux-gnu)

Checklist

Additional context
I have not used the raspberry pi without ssh. The pi has never been setup. I use a Pi 4B and the official 64 bit rpi os.

initial install Errno 121

Thanks for this great project. I am in the process of running this installation on a pi 3b+ running the latest raspbian 32bit. Linux raspberrypi 5.10.17-v7+ #1414

I have used your README for setup and everything seems to install correctly. At first run of demo_clock.py though I receive an Errno121 the full error is below.

Traceback (most recent call last):
File "demo_clock.py", line 14, in
display = drivers.Lcd()
File "/home/pi/lcd/drivers/i2c_dev.py", line 103, in init
self.lcd_write(0x03)
File "/home/pi/lcd/drivers/i2c_dev.py", line 126, in lcd_write
self.lcd_write_four_bits(mode | (cmd & 0xF0))
File "/home/pi/lcd/drivers/i2c_dev.py", line 121, in lcd_write_four_bits
self.lcd.write_cmd(data | LCD_BACKLIGHT)
File "/home/pi/lcd/drivers/i2c_dev.py", line 74, in write_cmd
self.bus.write_byte(self.addr, cmd)
IOError: [Errno 121] Remote I/O error

If I run i2cdetect -y 1 I get an address of 3f, so I know the hardware is at least being seen. I used a simpler guide/setup and was able to edit the text the lcd displays with this https://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/ I did this on a second microsd as to not interfere with the pi-guy version. So I know the hw is functioning and wired correctly. Anyone have any suggestions please?

Thank you!

Displaying the IP address shows a b' in front of IP address

Describe the issue
Displaying the IP Address shows following:
b' 192.168.223.228
how can I get the b' not to be displayed?

Is there a way to display the port as well?

Demo

Executed command and associated error

python demo_clock_and_IP.py
shows: b' 192.168.223.228

Host and software info

  • RPi board version: Pi 4 B
  • OS version: 2032-02-21
  • Python version : 3

Checklist

  • I have watched and followed the instructions in the Youtube tutorial.
  • I have searched open and closed issues for either an identical or similar bug before reporting this new one.
  • I have used Python 2.7

Additional context
Add any other context about the problem here.

lcd driver implementation

@the-raspberry-pi-guy , I'm just opening this issue to highlight a few aspects of the current repo that I've already fixed in the dev branch of my fork and that will be mentioned in the PR I'll submit next.

  1. The setup.sh bash script calls Python to check for the board version and then copies one of two i2c_lib_*.py files to the repo's root. If we're using Python to check the revision, then we should be able to merge the i2c_lib_*.py files into a single one and let it automatically check the revision upon execution and set the appropriate value to SMBus().

  2. lcddriver.py always assumes that the address of the LCD is the hex literal 0x27 but as pointed out in a comment, it can sometimes be something else. To find out, the user needs to run i2cdetect (from the i2c-tools pkg) manually and change the code accordingly. We should be able to parse the output of i2cdetect -y BUS_NUMBER automatically and set the address of the LCD device accordingly.

  3. Most of the demo_*.py files are missing appropriate shebang and execute permission.

Display IP adress

@Sierra007117 Displaying the IP Address shows following:

b'[IP Address]'

how can I get the b and the '' not to be displayed?

Is there a way to display the port as well?

How to contribute?

I cloned the repo in my pi command line and created a script that I would like to publish. However I cannot push my commits, It asked me to create a personal access token to use instead of my password. I did that but it denies me access anyway.

demo_forex.py is broken because requests is blocked by cloudflare

Describe the issue
Information on the second line is not displayed, as the request for https://tr.investing.com is a content blocked page that does not have anything the script is looking for.

Demo

Executed command and associated error

python demo_forex.py
python
>>> import requests
>>> fakeheaders= {  'User-Agent': 'Google Chrome' }
>>> hr=requests.get(url="https://tr.investing.com/", headers=fakeheaders)
>>> print (hr.content)
b'<!DOCTYPE html>\n<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en-US"> <![endif]-->\n<!--[if IE 7]>    <html class="no-js ie7 oldie" lang="en-US"> <![endif]-->\n<!--[if IE 8]>    <html class="no-js ie8 oldie" lang="en-US"> <![endif]-->\n<!--[if gt IE 8]><!--> <html class="no-js" lang="en-US"> <!--<![endif]-->\n<head>\n<title>Attention Required! | Cloudflare</title>\n<meta charset="UTF-8" />\n<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\n<meta http-equiv="X-UA-Compatible" content="IE=Edge" />\n<meta name="robots" content="noindex, nofollow" />\n<meta name="viewport" content="width=device-width,initial-scale=1" />\n<link rel="stylesheet" id="cf_styles-css" href="/cdn-cgi/styles/cf.errors.css" />\n<!--[if lt IE 9]><link rel="stylesheet" id=\'cf_styles-ie-css\' href="/cdn-cgi/styles/cf.errors.ie.css" /><![endif]-->\n<style>body{margin:0;padding:0}</style>\n\n\n<!--[if gte IE 10]><!-->\n<script>\n  if (!navigator.cookieEnabled) {\n    window.addEventListener(\'DOMContentLoaded\', function () {\n      var cookieEl = document.getElementById(\'cookie-alert\');\n      cookieEl.style.display = \'block\';\n    })\n  }\n</script>\n<!--<![endif]-->\n\n\n</head>\n<body>\n  <div id="cf-wrapper">\n    <div class="cf-alert cf-alert-error cf-cookie-error" id="cookie-alert" data-translate="enable_cookies">Please enable cookies.</div>\n    <div id="cf-error-details" class="cf-error-details-wrapper">\n      <div class="cf-wrapper cf-header cf-error-overview">\n        <h1 data-translate="block_headline">Sorry, you have been blocked</h1>\n        <h2 class="cf-subheadline"><span data-translate="unable_to_access">You are unable to access</span> investing.com</h2>\n      </div><!-- /.header -->\n\n      <div class="cf-section cf-highlight">\n        <div class="cf-wrapper">\n          <div class="cf-screenshot-container cf-screenshot-full">\n            \n              <span class="cf-no-screenshot error"></span>\n            \n          </div>\n        </div>\n      </div><!-- /.captcha-container -->\n\n      <div class="cf-section cf-wrapper">\n        <div class="cf-columns two">\n          <div class="cf-column">\n            <h2 data-translate="blocked_why_headline">Why have I been blocked?</h2>\n\n            <p data-translate="blocked_why_detail">This website is using a security service to protect itself from online attacks. The action you just performed triggered the security solution. There are several actions that could trigger this block including submitting a certain word or phrase, a SQL command or malformed data.</p>\n          </div>\n\n          <div class="cf-column">\n            <h2 data-translate="blocked_resolve_headline">What can I do to resolve this?</h2>\n\n            <p data-translate="blocked_resolve_detail">You can email the site owner to let them know you were blocked. Please include what you were doing when this page came up and the Cloudflare Ray ID found at the bottom of this page.</p>\n          </div>\n        </div>\n      </div><!-- /.section -->\n\n      <div class="cf-error-footer cf-wrapper w-240 lg:w-full py-10 sm:py-4 sm:px-8 mx-auto text-center sm:text-left border-solid border-0 border-t border-gray-300">\n  <p class="text-13">\n    <span class="cf-footer-item sm:block sm:mb-1">Cloudflare Ray ID: <strong class="font-semibold">redacted</strong></span>\n    <span class="cf-footer-separator sm:hidden">&bull;</span>\n    <span id="cf-footer-item-ip" class="cf-footer-item hidden sm:block sm:mb-1">\n'

This website is using a security service to protect itself from online attacks. The action you just performed triggered the security solution. There are several actions that could trigger this block including submitting a certain word or phrase, a SQL command or malformed data.

What can I do to resolve this?

You can email the site owner to let them know you were blocked. Please include what you were doing when this page came up and the Cloudflare Ray ID found at the bottom of this page.

Additional context
I have a fix that uses cloudscraper instead of requests to bypass the restriction.

UK pound symbol

I'm trying out this library to get a 16x2 LCD to work on my Pi. I need to display the uk pound £ sign. Is this possible to do with this library?

Parameter Explanation

Hi

I am working on a small project, and I need to display an ID and a name into my LCD screen

I am using display.lcd_display_string("TEXT", 1)

I have been testing different numbers; however, the second display.lcd_display_string("TEXT2", 1) that I use does not display the text as I want.

Do you have any documentation that explains the parameters of this method?

Thanks

No module named smbus

Hey so i try running the script python demo_lcd.py and it says No module named smbus even though i have installed smbus...
How could i fix this?
Thanks.

No module named smbus (sorry if not correct label..)


name: Compatibility
about: Issues specifically related to Python 3.x usage
title: ''
labels: compatibility
assignees: ''


Describe the issue
I run the command bellow and it says that error, even though i have smbus installed...
How could i fix this?

Executed command and associated error

python demo_lcd.py
Traceback (most recent call last):
  File "demo_lcd.py", line 8, in <module>
    import drivers
  File "/home/pi/lcd/drivers/__init__.py", line 1, in <module>
    from .i2c_dev import Lcd, CustomCharacters
  File "/home/pi/lcd/drivers/i2c_dev.py", line 1, in <module>
    from smbus import SMBus
ImportError: No module named smbus

Host and software info

  • RPi board version: Raspberry Pi 4 Model B Rev 1.2
  • OS version: Raspbian GNU/Linux 11 (bullseye)
  • Python version : Python 2.7.18

Checklist

  • [ Check ] I have watched and followed the instructions in the Youtube tutorial.

  • [ Check ] I have searched open and closed issues for either an identical or similar bug before reporting this new one.

  • I have used Python 3.x

No module named smbus

Hey so i try running the script python demo_lcd.py and it says No module named smbus even though i have installed smbus...
How could i fix this?
Thanks.

smbus is not recognized

Describe the bug
When I type ‘python demo_lcd.py’ there is an error where it says that in line 1 of init or somewhere in drivers that ‘from smbus import SMBus’ smbus is not reconized or smth.

Executed command and associated error

python demo_lcd
Type error: smbus not reconized

Host and software info

  • RPi board version: latest one
  • OS version: raspian latest one
  • (If Python related.) Python version : version 3
  • (If shell related.) Shell: add name here and version

Checklist

  • I have watched and followed the instructions in the Youtube tutorial.
  • I have searched open and closed issues for either an identical or similar bug before reporting this new one.
  • (If Python related.) I have used Python 2.7

addr i2c detection, re.findall function TypeError. [pull request... *sort of]

TypeError: cannot use a string pattern on a bytes-like object.
drivers/i2c_dev.py

62 ... try:
63 ...     self.addr = int('0x{}'.format(
64 ...                       findall("[0-9a-z]{2}(?!:)", check_output(['/usr/sbin/i2cdetect', '-y', str(BUS_NUMBER)]))[0]), base=16) \
65 ...                       if exists('/usr/sbin/i2cdetect') else addr_default

This should fix the problem:

62 ... try:
63 ...     self.addr = int('0x{}'.format(
64 ...                       findall("[0-9a-z]{2}(?!:)", check_output(['/usr/sbin/i2cdetect', '-y', str(BUS_NUMBER), encoding='utf8']))[0]), base=16) \
65 ...                       if exists('/usr/sbin/i2cdetect') else addr_default

Omision on README about quotable.io quote length restrictions

Describe the issue
I forgot to add info about the quotable.io capability to limit the quote character length in the readme.
This is in regards to the demo file demo_tiny_dashboard.py

Document

  • File: README.md

I am adding this on the pull request for the demo_forex.py fix

Issue while running demo_clock.py

pi@raspberrypi:~/lcd $ python demo_clock.py
Traceback (most recent call last):
File "demo_clock.py", line 14, in
display = drivers.Lcd()
File "/home/pi/lcd/drivers/i2c_dev.py", line 103, in init
self.lcd_write(0x03)
File "/home/pi/lcd/drivers/i2c_dev.py", line 126, in lcd_write
self.lcd_write_four_bits(mode | (cmd & 0xF0))
File "/home/pi/lcd/drivers/i2c_dev.py", line 121, in lcd_write_four_bits
self.lcd.write_cmd(data | LCD_BACKLIGHT)
File "/home/pi/lcd/drivers/i2c_dev.py", line 74, in write_cmd
self.bus.write_byte(self.addr, cmd)
IOError: [Errno 121] Remote I/O error

Maintaining Python 2.7 compatibility moving forward

Issues #41 and #42 (#43, #44) are diagnostic of a growing compatibility issue, namely, the almost complete lack of Python 2.7 support--and of its modules, such as smbus--via the official package managers (either apt or pip) starting with Raspberry Pi OS bullseye. Moving forward, there are a couple of alternatives to deal with this:

  1. The RPi Foundation is still maintaining a Raspberry Pi OS Legacy version, namely buster, which is fully compatible with the current LCD driver. Users can be encouraged to use it instead.
  2. Build smbus from https://github.com/pimoroni/py-smbus. I think they are the current maintainers of the smbus pkg and it seems that there hasn't been any update in more than 5 years. I've tried to build it using the latest buster Raspberry Pi OS but ran into issues (build requirements seem outdated as well).
  3. We could change reliance from the old smbus to smbus2 (https://pypi.org/project/smbus2/) which is fully compatible with the LCD driver (just change import smbus to import smbus2) and it doesn't seem to break any demos. This module can be built from source (tested it installs just fine and the module is picked up by pip afterwards). The install from source procedure would be appended to setup.sh.
  4. Edit setup.sh to try to install both python-smbus and python3-smbus via apt and then add a note to README.md that users running the latest distro (bullseye and above) should use python3 with the LCD driver if they run into issue with python, which seems to be linked to Python 2.7 even in bullseye.

Anyway, these are the options that I can think of right now. They are not all mutually exclusive. In any case, the growing compatibility issue needs to be addressed asap. If anyone wants to chime in, please do so before Jan 14th. Otherwise, I'll merge the changes that I think are the most reasonable ones.

install.sh

on 25 line you do "cp installConfigs/modules /etc/ "
but in modules have only one new string i2c-dev
mb. write echo "i2c-dev" >> /etc/modules ?

install.sh script issues

Hey, @the-raspberry-pi-guy . I've started playing with your lcd repo files and noticed the following issues in the install.sh shell script:

  1. The script is missing proper indentation.
  2. The original /etc/modules is being overwritten with the repo's installConfigs/raspi-blacklist.conf file, instead of appending the required modules to it.
  3. Similarly, the repo's installConfigs/raspi-blacklist.conf overwrites the existing /etc/modprobe.d/raspi-blacklist.conf file. Both cases can be troublesome for users that have modified such files before (e.g., have other modules enabled or blacklisted).
  4. dtparam=i2c_arm=1 is appended to the system's /boot/config.txt without checking if it's already explicitly enabled or disabled.
  5. (Not really an issue but dtparam=i2c_arm=1 can be shortened by dtparam=i2c to indicate the RPi to enable i2c on boot. Source: device tree docs.)

The good news is that I had a bit of free time today and managed to fix all such issues myself. I'll be making a PR in a few minutes. Just wanted to give you a heads up, so you don't need worry about the issues I just mentioned at all. I'll talk about the specifics in the PR.

--CG

module not imported running python script at startup raspberry pi /etc/profiles

I created a python script using lcd. It works perfectly fine when I am testing from CLI. I have an application where I have to run the script during start up. So I have done these steps:

  1. sudo nano /etc/profile

  2. added "sudo python3 /home/pi/test_adc_1.py &" in the last line.

  3. sudo reboot now

But code didnt start, so i logged on to RPi and checked it displays below error.

**pi@raspberrypi:~ $ Traceback (most recent call last):
File "/home/pi/test_adc_1.py", line 3, in
import drivers
ModuleNotFoundError: No module named 'drivers'

[1]+ Exit 1 sudo python3 /home/pi/test_adc_1.py**

Kindly suggest me the solution.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.