Comments on: How to Setup an I2C LCD on the Raspberry Pi http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/ Raspberry Pi, Arduino, and DIY Electronics Projects and Tutorials Fri, 20 Apr 2018 22:07:56 +0000 hourly 1 By: rhubarbdog http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-24373 Thu, 12 Apr 2018 08:44:35 +0000 http://www.circuitbasics.com/?p=420790#comment-24373 I had this problem. The i2c backpack has a variable resistor this adjusts the contrast. Write a program which displays a string on line one and immediately exits. Now with a small screw driver adjust that potentiometer. Hopefully the string is now on display.

]]>
By: beginner http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-24370 Thu, 12 Apr 2018 08:36:02 +0000 http://www.circuitbasics.com/?p=420790#comment-24370 hey guys, i tried to set up my i2c with my lcd but the problem is the string command doesn’t display on my lcd
i tried the backlight command and it works.

]]>
By: rhubarbdog http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-24263 Wed, 11 Apr 2018 16:12:14 +0000 http://www.circuitbasics.com/?p=420790#comment-24263 Line 1 has addresses beginning 0x80
Line 2 addresses begin at 0xc0
Columns are numbered 0 to 15

The following code will scroll a character from left to right on line one
[code]
import RPi_I2C_driver
from time import *

mylcd = RPi_I2C_driver.lcd()

fontdata1 = [
[ 0b000000,
0b000000,
0b000000,
0b000000,
0b000000,
0b000000,
0b000000,
0b000000 ],

[ 0b00000,
0b00100,
0b01110,
0b11111,
0b01110,
0b00100,
0b00000,
0b00000 ]
]

mylcd.lcd_load_custom_chars(fontdata1)
for column in range(16):
addr=0x80
addr+=column
#print diamond symbol at line 1 column x
mylcd.lcd_write(addr)
mylcd.lcd_write_char(1)
sleep(0.5)
#blank it out
mylcd.lcd_write(addr)
mylcd.lcd_write_char(0)
[/code]

]]>
By: DocMad http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-22382 Fri, 16 Mar 2018 16:37:56 +0000 http://www.circuitbasics.com/?p=420790#comment-22382 How do I implement my DHT22? What library is the best one to use?

]]>
By: Nick B. http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-18856 Thu, 01 Feb 2018 17:35:54 +0000 http://www.circuitbasics.com/?p=420790#comment-18856 I’m still using jessie with most recent updates. It’s the same on my Zero W and Pi 2.

]]>
By: AmigaDragon http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-18781 Wed, 31 Jan 2018 16:48:56 +0000 http://www.circuitbasics.com/?p=420790#comment-18781 Shown above in the tutorial they’re in Advanced. Is this a difference on the Zero W or a change between Raspbian Jessie and Stretch? Either way it should be updated to mention both.

]]>
By: Nick B. http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-18763 Wed, 31 Jan 2018 09:48:06 +0000 http://www.circuitbasics.com/?p=420790#comment-18763 Look under menu option 5 – Interfacing Options then you should see options P1 – P8. I2C is P5, SPI is P4, Serial is P6.

]]>
By: AmigaDragon http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-18500 Sat, 27 Jan 2018 22:16:51 +0000 http://www.circuitbasics.com/?p=420790#comment-18500 On the Raspberry Pi zero W in raspi-config Advanced settings I can’t find the I2C, SPI or Serial enables

]]>
By: freedoM http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-13006 Thu, 23 Nov 2017 20:35:44 +0000 http://www.circuitbasics.com/?p=420790#comment-13006 hallo im traying to use this scipt, whit an crius oled lcd display. but i dont get anything on the screen??
do i maybe mist something? does the module maybe have to paste into an specific folder, whit modules? or does the module have to be compiled first?

i only get this error!! ??

Traceback (most recent call last):
File “lcdtest2.py”, line 3, in
mylcd = I2C_LCD_driver.lcd()
File “/home/pi/lcd_test/I2C_LCD_driver.py”, line 111, in __init__
self.lcd_write(0x03)
File “/home/pi/lcd_test/I2C_LCD_driver.py”, line 136, in lcd_write
self.lcd_write_four_bits(mode | (cmd & 0xF0))
File “/home/pi/lcd_test/I2C_LCD_driver.py”, line 131, in lcd_write_four_bits
self.lcd_device.write_cmd(data | LCD_BACKLIGHT)
File “/home/pi/lcd_test/I2C_LCD_driver.py”, line 34, in write_cmd
self.bus.write_byte(self.addr, cmd)
IOError: [Errno 110] Connection timed out

thanks allready,. greetz,freedom

]]>
By: JOE http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-12343 Sat, 11 Nov 2017 16:24:30 +0000 http://www.circuitbasics.com/?p=420790#comment-12343 I am having an issue with my LCD16x2 connected via an I2C module to the pi – the first time I run lcd_display_string and lcd_clear, the display will correctly display and remove the text, however the second (and any further times) I run the script, it does not clear the output, rather text gets added to the end of the last text.

Does anyone know how to resolve this?

]]>
By: Damjan http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-8243 Mon, 18 Sep 2017 06:38:52 +0000 http://www.circuitbasics.com/?p=420790#comment-8243 Thank you , I hope I understand, I will try

]]>
By: NEM ESIS http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-8150 Sat, 16 Sep 2017 08:25:50 +0000 http://www.circuitbasics.com/?p=420790#comment-8150 import RPi_I2C_driver, time

text = “same information”
mylcd0 = RPi_I2C_driver.lcd( ADDR = 0x3f )
mylcd0.lcd_display_string(text,1)
mylcd1 = RPi_I2C_driver.lcd( ADDR = 0x3D )
mylcd1.lcd_display_string(text,1)
time.sleep(3)
mylcd1.lcd_clear()
mylcd1.backlight(0)
time.sleep(3)
mylcd0.lcd_clear()
mylcd0.backlight(0)

but first change 2 lines in RPi_I2C_driver.py ( +/- line 25/26 )
def __init__(self, ADDR = 0x27 ):
self.lcd_device = i2c_device(ADDR)
(code not fully tested, driver changes work, check your indents)

]]>
By: nem esis http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-8149 Sat, 16 Sep 2017 08:20:07 +0000 http://www.circuitbasics.com/?p=420790#comment-8149 import RPi_I2C_driver, time

mylcd0 = RPi_I2C_driver.lcd( ADDR = 0x27 )
mylcd0.lcd_display_string(“lcd on default address.”,1)
mylcd1 = RPi_I2C_driver.lcd( ADDR = 0x28 )
mylcd1.lcd_display_string(“lcd on custom address”,1)
time.sleep(3)
mylcd1.lcd_clear()
mylcd1.backlight(0)
time.sleep(3)
mylcd0.lcd_clear()
mylcd0.backlight(0)

but first change 2 lines in RPi_I2C_driver.py ( +/- line 25/26 )
def __init__(self, ADDR = 0x27 ):
self.lcd_device = i2c_device(ADDR)
(code not fully tested, driver changes work, use i2cdetect to find i2c address of second lcd)

]]>
By: nem esis http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-8145 Sat, 16 Sep 2017 07:35:47 +0000 http://www.circuitbasics.com/?p=420790#comment-8145 want to use Python3 , then change all unichr to chr in I2C_LCD_driver.py,
this is only a demo program now, the real driver is RPi_I2C_driver.py (line 34 has the i2c address)

import RPi_I2C_driver, time
mylcd = RPi_I2C_driver.lcd()
mylcd.lcd_display_string(“Python3 rocks…”,1)
time.sleep(3)
mylcd.lcd_clear()
mylcd.backlight(0)

]]>
By: Damjan http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-6125 Thu, 17 Aug 2017 14:46:57 +0000 http://www.circuitbasics.com/?p=420790#comment-6125 I use 20×4 LCD and work fine!

]]>
By: Damjan http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-6124 Thu, 17 Aug 2017 14:46:16 +0000 http://www.circuitbasics.com/?p=420790#comment-6124 HI!
Work great!
Thankyou….
I try with two display , now i have I2C_LCD_driver.py and I2C_LCD_driver2.py with different address and in code
import I2C_LCD_driver
mylcd = I2C_LCD_driver.lcd()
import I2C_LCD_driver2
mylcd2 = I2C_LCD_driver2.lcd()

How can I add in I2C_LCD_driver.py two address for two display ?
I want to show display with 0x3f and 0x3D same information ?

]]>
By: Caesar http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-5794 Thu, 10 Aug 2017 13:54:32 +0000 http://www.circuitbasics.com/?p=420790#comment-5794 it’s working? Anyone checked or have another idea how to connect two I2C LCD displays?

]]>
By: Caesar http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-5790 Thu, 10 Aug 2017 12:19:17 +0000 http://www.circuitbasics.com/?p=420790#comment-5790 It’s working? someone checked? I try but it’s fail.

]]>
By: Eduard http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-3565 Tue, 06 Jun 2017 15:02:13 +0000 http://www.circuitbasics.com/?p=420790#comment-3565 hello
if I follow this steps, I can use this code in a lcd 20×4 ?

]]>
By: George http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-3443 Tue, 30 May 2017 16:48:00 +0000 http://www.circuitbasics.com/?p=420790#comment-3443 Just thought I’d say this is a great tutorial, really covers all possible bases. 😁

]]>
By: TP http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-3244 Wed, 17 May 2017 23:09:39 +0000 http://www.circuitbasics.com/?p=420790#comment-3244 Ran into same problem today.

git clone https://github.com/szazo/DHT11_Python

Then copy dhy11.py to your directory where your files are from above. So dht11.py is in the same directory as I2C_LCD_driver.py For example,

cp /home/pi/project/DHT11_Python/dht11.py /home/project/dht11.py

]]>
By: Michal http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-3119 Thu, 11 May 2017 11:39:33 +0000 http://www.circuitbasics.com/?p=420790#comment-3119 got a problem with last python script

PRINT DATA FROM A SENSOR

when I try to run it i got this error message :

python temp.py
Traceback (most recent call last):
File “temp.py”, line 2, in
import dht11
ImportError: No module named dht11

can some one help me with this ?

]]>
By: amigadragon http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-2978 Sat, 06 May 2017 05:47:43 +0000 http://www.circuitbasics.com/?p=420790#comment-2978 While the scrolling scripts are working on their own, when I try to incorporate scrolling into my own script, I get an error:
File “/home/pi/Documents/InternetRadio/I2C_LCD_driver.py”, line 160, in lcd_display_string
self.lcd_write(ord(char), Rs)
TypeError: ord() expected string of length 1, but int found

Why does it work okay in the above script but not in mine? Why is it expecting string length 1 from me? (excerpt):
for i in range (0, len(currentstream)):
lcd_text = currentstream[i:(i+20)] # displayed substring width, 4×20 LCD
mylcd.lcd_display_string(lcd_text,1)
sleep(0.2)
mylcd.lcd_display_string(str_pad,1)

]]>
By: John Aiyelawo http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-2953 Fri, 05 May 2017 13:22:14 +0000 http://www.circuitbasics.com/?p=420790#comment-2953 Thanks for your post!! Very helpful. Is there anyway I can use a 4×4 matrix keypad to display characters on the lcd. Thanks in advance 🙂

]]>
By: raspirate http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-2605 Tue, 18 Apr 2017 20:24:02 +0000 http://www.circuitbasics.com/?p=420790#comment-2605 Is there a way to display more that 8 custom characters? I’m running into problems when trying to.

]]>
By: AmigaDragon http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-2458 Thu, 06 Apr 2017 03:34:03 +0000 http://www.circuitbasics.com/?p=420790#comment-2458 Oops, missed the comment in the article about connecting to “the 5V pin of the Pi if possible”, so I guess it is safe.

]]>
By: amigadragon http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-2451 Wed, 05 Apr 2017 19:26:41 +0000 http://www.circuitbasics.com/?p=420790#comment-2451 Though I may need to insert a level converter, running the LCD from 3.3v on the Pi doesn’t give enough contrast straight-on, have to view from 20 degrees below straight-on to see it. Or should it be safe for the Pi to run the LCD from 5v without converting levels on SDA1/SCL1?

]]>
By: amigadragon http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-2450 Wed, 05 Apr 2017 19:16:48 +0000 http://www.circuitbasics.com/?p=420790#comment-2450 Tested and works. Thanks.

]]>
By: danielpaulotipan http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-2270 Mon, 13 Mar 2017 09:33:51 +0000 http://www.circuitbasics.com/?p=420790#comment-2270 LCD doesn’t display the DHT11 values part but displays others like the “hello world”. It just prints the value on the terminal. Why is that?

]]>
By: Circuit Basics http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-2268 Sat, 11 Mar 2017 17:16:39 +0000 http://www.circuitbasics.com/?p=420790#comment-2268 That looks really cool, thanks for posting it

]]>
By: Circuit Basics http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-2267 Sat, 11 Mar 2017 17:12:58 +0000 http://www.circuitbasics.com/?p=420790#comment-2267 It should work on a 20×4 LCD without any changes to the library code

]]>
By: Circuit Basics http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-2266 Sat, 11 Mar 2017 17:02:24 +0000 http://www.circuitbasics.com/?p=420790#comment-2266 Hi kb06, What size resistors are you using for the contrast? It could be that the contrast resistor is too small, making the contrast too high. Also, does your LCD have an I2C backpack or are you using the PCF8574?

]]>
By: Ioannes Bracciano http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-2263 Fri, 10 Mar 2017 18:41:13 +0000 http://www.circuitbasics.com/?p=420790#comment-2263 Check out this python module that extends the functionality of the HD44780 controller:
https://github.com/IoannesBracciano/rpi-dots

]]>
By: Emanuele Fanton http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-2258 Thu, 09 Mar 2017 13:01:45 +0000 http://www.circuitbasics.com/?p=420790#comment-2258 http://lmgtfy.com/?q=linux+kill+other+script

http://askubuntu.com/questions/526886/stopping-a-running-script-though-another-script-file

]]>
By: Diego Morales (@Diego_hellyeah) http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-2257 Thu, 09 Mar 2017 03:54:35 +0000 http://www.circuitbasics.com/?p=420790#comment-2257 Hi guys! Thanks for this tuto. How can I stop the date and time script with another script? No ctrl+c. I need to stop that scrip when another script starts but I don’t know how to doit

]]>
By: Emanuele Fanton http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-2123 Tue, 14 Feb 2017 11:46:48 +0000 http://www.circuitbasics.com/?p=420790#comment-2123 I need the File “/home/pi/I2C_LCD_driver.py” where the error is located…

]]>
By: Ashkan http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-2122 Tue, 14 Feb 2017 09:39:34 +0000 http://www.circuitbasics.com/?p=420790#comment-2122 I have just changed I2CBUS = 0 to I2CBUS = 1

]]>
By: Ashkan http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-2121 Tue, 14 Feb 2017 09:38:39 +0000 http://www.circuitbasics.com/?p=420790#comment-2121 # -*- coding: utf-8 -*-
# Original code found at:
# https://gist.github.com/DenisFromHR/cc863375a6e19dce359d

“””
Compiled, mashed and generally mutilated 2014-2015 by Denis Pleic
Made available under GNU GENERAL PUBLIC LICENSE

# Modified Python I2C library for Raspberry Pi
# as found on http://www.recantha.co.uk/blog/?p=4849
# Joined existing ‘i2c_lib.py’ and ‘lcddriver.py’ into a single library
# added bits and pieces from various sources
# By DenisFromHR (Denis Pleic)
# 2015-02-10, ver 0.1

“””

# i2c bus (0 — original Pi, 1 — Rev 2 Pi)
I2CBUS = 0

# LCD Address
ADDRESS = 0x27

import smbus
from time import sleep

class i2c_device:
def __init__(self, addr, port=I2CBUS):

]]>
By: Ashkan http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-2120 Tue, 14 Feb 2017 09:35:41 +0000 http://www.circuitbasics.com/?p=420790#comment-2120 import I2C_LCD_driver
from time import *
mylcd = I2C_LCD_driver.lcd()
mylcd.lcd_display_string(“Hello World!”, 1)

——————————————————————

]]>
By: Emanuele Fanton http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-2119 Mon, 13 Feb 2017 19:09:46 +0000 http://www.circuitbasics.com/?p=420790#comment-2119 copy your full code.

]]>
By: Ashkan http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-2118 Mon, 13 Feb 2017 17:45:09 +0000 http://www.circuitbasics.com/?p=420790#comment-2118 I get the following error on RasPi3

Traceback (most recent call last):
File “hello.py”, line 1, in
import I2C_LCD_driver
File “/home/pi/I2C_LCD_driver.py”, line 21
def __init__(self, addr, port=I2CBUS):
^
IndentationError: expected an indented block

Would you please provide me with a solution?

]]>
By: amigadragon http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-2108 Tue, 07 Feb 2017 05:00:07 +0000 http://www.circuitbasics.com/?p=420790#comment-2108 Do I need to change or add something (lines 91-97 or anywhere else of the driver) for a 20×4 display?

]]>
By: amigadragon http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-2107 Tue, 07 Feb 2017 04:50:31 +0000 http://www.circuitbasics.com/?p=420790#comment-2107 Did you change I2C bus 0 in line 20 of the driver to 1?

]]>
By: Emanuele Fanton http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-2047 Fri, 20 Jan 2017 11:23:20 +0000 http://www.circuitbasics.com/?p=420790#comment-2047 We need the code! Perhaps you are inside a loop? try using threads or handlers for gpio.

]]>
By: Ryan http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-2046 Fri, 20 Jan 2017 03:05:47 +0000 http://www.circuitbasics.com/?p=420790#comment-2046 Glad I found this page, helpd me a lot with my internet radio. I have used the clock as the second line on my screen, but by haivng this clock running on there it makes the next and previous buttons unresponsive. Does anyone know how to solve this please?

]]>
By: JimBeamer http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-1965 Sat, 17 Dec 2016 15:50:32 +0000 http://www.circuitbasics.com/?p=420790#comment-1965 Thank you now it looks beautiful 🙂

]]>
By: Emanuele Fanton http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-1964 Sat, 17 Dec 2016 05:03:31 +0000 http://www.circuitbasics.com/?p=420790#comment-1964 \n is the return carriage…strip will do the trick!

]]>
By: Emanuele Fanton http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-1963 Sat, 17 Dec 2016 05:02:29 +0000 http://www.circuitbasics.com/?p=420790#comment-1963 You can try title[:-1] or title.strip()

]]>
By: JimBeamer http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-1962 Sat, 17 Dec 2016 02:34:29 +0000 http://www.circuitbasics.com/?p=420790#comment-1962 Hello, i use mpd and output the information from mpc current to the display.
This is the command that i use it for output
title = os.popen(‘mpc current -f %title%’).read()
mylcd.lcd_display_string(title, 1)
it works fine but on the end of the string there is a bad character.
On the end of the string from titel there is a “\n” and this is the bad character on the lcd.
How i delete this sign in the output?

Sorry for my bad english

]]>
By: Emanuele Fanton http://www.circuitbasics.com/raspberry-pi-i2c-lcd-set-up-and-programming/#comment-1960 Fri, 16 Dec 2016 07:42:35 +0000 http://www.circuitbasics.com/?p=420790#comment-1960 take a look at https://metacpan.org/pod/Device::SMBus.
From there you had to adapt the examples in python

]]>