

 
 <?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	
	>
<channel>
	<title>
	Reacties op: LCD scherm 20&#215;4 met behulp van I2C aansturen	</title>
	<atom:link href="https://raspberrytips.nl/lcd-scherm-20x4-i2c-raspberry-pi/feed/" rel="self" type="application/rss+xml" />
	<link>https://raspberrytips.nl/lcd-scherm-20x4-i2c-raspberry-pi/</link>
	<description>Raspberry Pi en Raspbian tips</description>
	<lastBuildDate>Thu, 05 Aug 2021 20:56:01 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.1</generator>
	<item>
		<title>
		Door: Erik Schott		</title>
		<link>https://raspberrytips.nl/lcd-scherm-20x4-i2c-raspberry-pi/#comment-2451</link>

		<dc:creator><![CDATA[Erik Schott]]></dc:creator>
		<pubDate>Thu, 05 Aug 2021 20:56:01 +0000</pubDate>
		<guid isPermaLink="false">https://raspberrytips.nl/?p=1104#comment-2451</guid>

					<description><![CDATA[Ik heb de code nog wat aangepast voor de laatste versie van Buster (05082021)

#!/usr/bin/python
#  https://raspberrytips.nl/lcd-scherm-20x4-i2c-raspberry-pi/

import sys
import smbus
import time
import datetime
import subprocess

#I2C_ADDR  = 0x3F # I2C device address
I2C_ADDR  = 0x27 # I2C device address
LCD_WIDTH = 20   # Maximum characters per line

# Define some device constants
LCD_CHR = 1 # Mode - Sending data
LCD_CMD = 0 # Mode - Sending command

LCD_LINE_1 = 0x80 # LCD RAM address for the 1st line
LCD_LINE_2 = 0xC0 # LCD RAM address for the 2nd line
LCD_LINE_3 = 0x94 # LCD RAM address for the 3rd line
LCD_LINE_4 = 0xD4 # LCD RAM address for the 4th line


LCD_BACKLIGHT  = 0x08  # On 0X08 / Off 0x00

ENABLE = 0b00000100 # Enable bit

E_PULSE = 0.0005
E_DELAY = 0.0005

bus = smbus.SMBus(1) # Rev 2 Pi uses 1

def run_cmd(cmd):
    return subprocess.check_output(cmd, shell=True).decode(&#039;utf-8&#039;)

def get_my_ipwlan():
    val = run_cmd(&quot;/sbin/ifconfig wlan0 &#124; grep -w &#039;inet&#039; &#124;cut -c 14-28 &#124; awk &#039;{ print $1}&#039;&quot;)[:-1]
    if val == &quot;&quot;:
        val = &quot;No connection!&quot;
    return val

def get_my_ipeth():
    val = run_cmd(&quot;/sbin/ifconfig enxb827eb62bee2 &#124; /sbin/ifconfig enxb827eb62bee2 &#124; grep -w &#039;inet&#039; &#124;cut -c 14-28 &#124; awk &#039;{ print $1}&#039;&quot;)[:-1]
    if val == &quot;&quot;:
        val = &quot;No connection&quot;
    return val

def lcd_init():
  lcd_byte(0x33,LCD_CMD) # 110011 Initialise
  lcd_byte(0x32,LCD_CMD) # 110010 Initialise
  lcd_byte(0x06,LCD_CMD) # 000110 Cursor move direction
  lcd_byte(0x0C,LCD_CMD) # 001100 Display On,Cursor Off, Blink Off
  lcd_byte(0x28,LCD_CMD) # 101000 Data length, number of lines, font size
  lcd_byte(0x01,LCD_CMD) # 000001 Clear display
  time.sleep(E_DELAY)

def lcd_byte(bits, mode):

  bits_high = mode &#124; (bits &#038; 0xF0) &#124; LCD_BACKLIGHT
  bits_low = mode &#124; ((bits&#060;&#060;4) &#038; 0xF0) &#124; LCD_BACKLIGHT

  bus.write_byte(I2C_ADDR, bits_high)
  lcd_toggle_enable(bits_high)

  bus.write_byte(I2C_ADDR, bits_low)
  lcd_toggle_enable(bits_low)

def lcd_toggle_enable(bits):
  time.sleep(E_DELAY)
  bus.write_byte(I2C_ADDR, (bits &#124; ENABLE))
  time.sleep(E_PULSE)
  bus.write_byte(I2C_ADDR,(bits &#038; ~ENABLE))
  time.sleep(E_DELAY)

def lcd_string(message,line):

  message = message.ljust(LCD_WIDTH,&#034; &#034;)

  lcd_byte(line, LCD_CMD)

  for i in range(LCD_WIDTH):
    lcd_byte(ord(message[i]),LCD_CHR)

def main():

  lcd_init()

  while True:

    now = datetime.datetime.now()

    lcd_string(&#034;PA0ESH-10 iGate APRX&#034;,LCD_LINE_1)
    lcd_string( str(now.day)+&#039;/&#039;+str(now.month)+&#039;/&#039;+str(now.year)+&#039; &#039;+str(now.hour)+&#039;:&#039;+str(now.minute),LCD_LINE_2)
    lcd_string(&#034;W:{}&#034;.format(get_my_ipwlan()),LCD_LINE_3)
    lcd_string(&#034;E:{}&#034;.format(get_my_ipeth()),LCD_LINE_4)
    time.sleep(60)

if __name__ == &#039;__main__&#039;:

  try:
    main()
  except KeyboardInterrupt:
    pass
  finally:
    lcd_byte(0x01, LCD_CMD)
root@hampi:/home/pi# ^C
root@hampi:/home/pi# nano lcd20x4.py

  GNU nano 3.2                                                                                      lcd20x4.py                                                                                                 

  lcd_init()

  while True:

    now = datetime.datetime.now()

    lcd_string(&#034;MY OWN STRING&#034;,LCD_LINE_1)
    lcd_string( str(now.day)+&#039;/&#039;+str(now.month)+&#039;/&#039;+str(now.year)+&#039; &#039;+str(now.hour)+&#039;:&#039;+str(now.minute),LCD_LINE_2)
    lcd_string(&#034;W:{}&#034;.format(get_my_ipwlan()),LCD_LINE_3)
    lcd_string(&#034;E:{}&#034;.format(get_my_ipeth()),LCD_LINE_4)
    time.sleep(60)

if __name__ == &#039;__main__&#039;:

  try:
    main()
  except KeyboardInterrupt:
    pass
  finally:
    lcd_byte(0x01, LCD_CMD)]]></description>
			<content:encoded><![CDATA[<p>Ik heb de code nog wat aangepast voor de laatste versie van Buster (05082021)</p>
<p>#!/usr/bin/python<br />
#  <a href="https://raspberrytips.nl/lcd-scherm-20x4-i2c-raspberry-pi/" rel="ugc">https://raspberrytips.nl/lcd-scherm-20&#215;4-i2c-raspberry-pi/</a></p>
<p>import sys<br />
import smbus<br />
import time<br />
import datetime<br />
import subprocess</p>
<p>#I2C_ADDR  = 0x3F # I2C device address<br />
I2C_ADDR  = 0x27 # I2C device address<br />
LCD_WIDTH = 20   # Maximum characters per line</p>
<p># Define some device constants<br />
LCD_CHR = 1 # Mode &#8211; Sending data<br />
LCD_CMD = 0 # Mode &#8211; Sending command</p>
<p>LCD_LINE_1 = 0x80 # LCD RAM address for the 1st line<br />
LCD_LINE_2 = 0xC0 # LCD RAM address for the 2nd line<br />
LCD_LINE_3 = 0x94 # LCD RAM address for the 3rd line<br />
LCD_LINE_4 = 0xD4 # LCD RAM address for the 4th line</p>
<p>LCD_BACKLIGHT  = 0x08  # On 0X08 / Off 0x00</p>
<p>ENABLE = 0b00000100 # Enable bit</p>
<p>E_PULSE = 0.0005<br />
E_DELAY = 0.0005</p>
<p>bus = smbus.SMBus(1) # Rev 2 Pi uses 1</p>
<p>def run_cmd(cmd):<br />
    return subprocess.check_output(cmd, shell=True).decode(&#8216;utf-8&#8217;)</p>
<p>def get_my_ipwlan():<br />
    val = run_cmd(&#8220;/sbin/ifconfig wlan0 | grep -w &#8216;inet&#8217; |cut -c 14-28 | awk &#8216;{ print $1}'&#8221;)[:-1]<br />
    if val == &#8220;&#8221;:<br />
        val = &#8220;No connection!&#8221;<br />
    return val</p>
<p>def get_my_ipeth():<br />
    val = run_cmd(&#8220;/sbin/ifconfig enxb827eb62bee2 | /sbin/ifconfig enxb827eb62bee2 | grep -w &#8216;inet&#8217; |cut -c 14-28 | awk &#8216;{ print $1}'&#8221;)[:-1]<br />
    if val == &#8220;&#8221;:<br />
        val = &#8220;No connection&#8221;<br />
    return val</p>
<p>def lcd_init():<br />
  lcd_byte(0x33,LCD_CMD) # 110011 Initialise<br />
  lcd_byte(0x32,LCD_CMD) # 110010 Initialise<br />
  lcd_byte(0x06,LCD_CMD) # 000110 Cursor move direction<br />
  lcd_byte(0x0C,LCD_CMD) # 001100 Display On,Cursor Off, Blink Off<br />
  lcd_byte(0x28,LCD_CMD) # 101000 Data length, number of lines, font size<br />
  lcd_byte(0x01,LCD_CMD) # 000001 Clear display<br />
  time.sleep(E_DELAY)</p>
<p>def lcd_byte(bits, mode):</p>
<p>  bits_high = mode | (bits &amp; 0xF0) | LCD_BACKLIGHT<br />
  bits_low = mode | ((bits&lt;&lt;4) &amp; 0xF0) | LCD_BACKLIGHT</p>
<p>  bus.write_byte(I2C_ADDR, bits_high)<br />
  lcd_toggle_enable(bits_high)</p>
<p>  bus.write_byte(I2C_ADDR, bits_low)<br />
  lcd_toggle_enable(bits_low)</p>
<p>def lcd_toggle_enable(bits):<br />
  time.sleep(E_DELAY)<br />
  bus.write_byte(I2C_ADDR, (bits | ENABLE))<br />
  time.sleep(E_PULSE)<br />
  bus.write_byte(I2C_ADDR,(bits &amp; ~ENABLE))<br />
  time.sleep(E_DELAY)</p>
<p>def lcd_string(message,line):</p>
<p>  message = message.ljust(LCD_WIDTH,&quot; &quot;)</p>
<p>  lcd_byte(line, LCD_CMD)</p>
<p>  for i in range(LCD_WIDTH):<br />
    lcd_byte(ord(message[i]),LCD_CHR)</p>
<p>def main():</p>
<p>  lcd_init()</p>
<p>  while True:</p>
<p>    now = datetime.datetime.now()</p>
<p>    lcd_string(&quot;PA0ESH-10 iGate APRX&quot;,LCD_LINE_1)<br />
    lcd_string( str(now.day)+&#039;/&#039;+str(now.month)+&#039;/&#039;+str(now.year)+&#039; &#039;+str(now.hour)+&#039;:&#039;+str(now.minute),LCD_LINE_2)<br />
    lcd_string(&quot;W:{}&quot;.format(get_my_ipwlan()),LCD_LINE_3)<br />
    lcd_string(&quot;E:{}&quot;.format(get_my_ipeth()),LCD_LINE_4)<br />
    time.sleep(60)</p>
<p>if __name__ == &#039;__main__&#039;:</p>
<p>  try:<br />
    main()<br />
  except KeyboardInterrupt:<br />
    pass<br />
  finally:<br />
    lcd_byte(0x01, LCD_CMD)<br />
root@hampi:/home/pi# ^C<br />
root@hampi:/home/pi# nano lcd20x4.py</p>
<p>  GNU nano 3.2                                                                                      lcd20x4.py                                                                                                 </p>
<p>  lcd_init()</p>
<p>  while True:</p>
<p>    now = datetime.datetime.now()</p>
<p>    lcd_string(&quot;MY OWN STRING&quot;,LCD_LINE_1)<br />
    lcd_string( str(now.day)+&#039;/&#039;+str(now.month)+&#039;/&#039;+str(now.year)+&#039; &#039;+str(now.hour)+&#039;:&#039;+str(now.minute),LCD_LINE_2)<br />
    lcd_string(&quot;W:{}&quot;.format(get_my_ipwlan()),LCD_LINE_3)<br />
    lcd_string(&quot;E:{}&quot;.format(get_my_ipeth()),LCD_LINE_4)<br />
    time.sleep(60)</p>
<p>if __name__ == &#039;__main__&#039;:</p>
<p>  try:<br />
    main()<br />
  except KeyboardInterrupt:<br />
    pass<br />
  finally:<br />
    lcd_byte(0x01, LCD_CMD)</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		Door: Erik		</title>
		<link>https://raspberrytips.nl/lcd-scherm-20x4-i2c-raspberry-pi/#comment-1969</link>

		<dc:creator><![CDATA[Erik]]></dc:creator>
		<pubDate>Tue, 20 Oct 2020 22:48:37 +0000</pubDate>
		<guid isPermaLink="false">https://raspberrytips.nl/?p=1104#comment-1969</guid>

					<description><![CDATA[Het script werket niet op mijn nieuwe RPi met Buster omdat ifconfig ietwat andere output geeft. Het deel addr: is weg, vandaar dat je een stukje code moet aanpassen.


def get_my_ipwlan():
    val = run_cmd(&quot;/sbin/ifconfig wlan0 &#124; grep &#039;inet &#039; &#124; cut -d: -f2 &#124; awk &#039;{ print $2}&#039;&quot;)[:-1]
    if val == &quot;&quot;:
        val = &quot;No connection!&quot;
    return val

def get_my_ipeth():
    val = run_cmd(&quot;/sbin/ifconfig eth0 &#124; grep &#039;inet &#039; &#124; cut -d: -f2 &#124; awk &#039;{ print $2}&#039;&quot;)[:-1]
    if val == &quot;&quot;:
        val = &quot;No connection&quot;
    return val]]></description>
			<content:encoded><![CDATA[<p>Het script werket niet op mijn nieuwe RPi met Buster omdat ifconfig ietwat andere output geeft. Het deel addr: is weg, vandaar dat je een stukje code moet aanpassen.</p>
<p>def get_my_ipwlan():<br />
    val = run_cmd(&#8220;/sbin/ifconfig wlan0 | grep &#8216;inet &#8216; | cut -d: -f2 | awk &#8216;{ print $2}'&#8221;)[:-1]<br />
    if val == &#8220;&#8221;:<br />
        val = &#8220;No connection!&#8221;<br />
    return val</p>
<p>def get_my_ipeth():<br />
    val = run_cmd(&#8220;/sbin/ifconfig eth0 | grep &#8216;inet &#8216; | cut -d: -f2 | awk &#8216;{ print $2}'&#8221;)[:-1]<br />
    if val == &#8220;&#8221;:<br />
        val = &#8220;No connection&#8221;<br />
    return val</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		Door: Jeroen Maathuis		</title>
		<link>https://raspberrytips.nl/lcd-scherm-20x4-i2c-raspberry-pi/#comment-936</link>

		<dc:creator><![CDATA[Jeroen Maathuis]]></dc:creator>
		<pubDate>Wed, 29 Aug 2018 14:22:28 +0000</pubDate>
		<guid isPermaLink="false">https://raspberrytips.nl/?p=1104#comment-936</guid>

					<description><![CDATA[Er zit een foutje in de pin-tabel bij &quot;Aansluitschema 5V&quot;.
&quot;5V (PIN #3)&quot; moet denk ik &quot;5V (PIN #4)&quot; zijn, want een paar regels er boven staat al &quot;SDA (PIN #3)&quot; en pin 3 is niet voor de algemene 5V stroom.]]></description>
			<content:encoded><![CDATA[<p>Er zit een foutje in de pin-tabel bij &#8220;Aansluitschema 5V&#8221;.<br />
&#8220;5V (PIN #3)&#8221; moet denk ik &#8220;5V (PIN #4)&#8221; zijn, want een paar regels er boven staat al &#8220;SDA (PIN #3)&#8221; en pin 3 is niet voor de algemene 5V stroom.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		Door: Eskrid		</title>
		<link>https://raspberrytips.nl/lcd-scherm-20x4-i2c-raspberry-pi/#comment-727</link>

		<dc:creator><![CDATA[Eskrid]]></dc:creator>
		<pubDate>Fri, 13 Apr 2018 09:04:47 +0000</pubDate>
		<guid isPermaLink="false">https://raspberrytips.nl/?p=1104#comment-727</guid>

					<description><![CDATA[Hallo Richard,

 De module is zichtbaar (3F)  maar ik krijg geen tekst te zien op het display.  Aangezien ik 2 ic2 en 2 displays heb en deze in alle combinaties heb geprobeerd is het hoogstwaarschijnlijk geen hardware probleem. Ik heb een Raspberry Pi 3B met Jessie. Enig idee waar dit aan kan liggen? 

*Mijn eerste reactie werd trouwens niet geplaats]]></description>
			<content:encoded><![CDATA[<p>Hallo Richard,</p>
<p> De module is zichtbaar (3F)  maar ik krijg geen tekst te zien op het display.  Aangezien ik 2 ic2 en 2 displays heb en deze in alle combinaties heb geprobeerd is het hoogstwaarschijnlijk geen hardware probleem. Ik heb een Raspberry Pi 3B met Jessie. Enig idee waar dit aan kan liggen? </p>
<p>*Mijn eerste reactie werd trouwens niet geplaats</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		Door: Eskrid		</title>
		<link>https://raspberrytips.nl/lcd-scherm-20x4-i2c-raspberry-pi/#comment-726</link>

		<dc:creator><![CDATA[Eskrid]]></dc:creator>
		<pubDate>Fri, 13 Apr 2018 08:54:53 +0000</pubDate>
		<guid isPermaLink="false">https://raspberrytips.nl/?p=1104#comment-726</guid>

					<description><![CDATA[Ik heb een raspberry pi 3b met Jessie.]]></description>
			<content:encoded><![CDATA[<p>Ik heb een raspberry pi 3b met Jessie.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		Door: Raspberry Pi 2 &#38; 20&#215;4 LCD Ekran Bağlantısı &#8211; kubitokya		</title>
		<link>https://raspberrytips.nl/lcd-scherm-20x4-i2c-raspberry-pi/#comment-427</link>

		<dc:creator><![CDATA[Raspberry Pi 2 &#38; 20&#215;4 LCD Ekran Bağlantısı &#8211; kubitokya]]></dc:creator>
		<pubDate>Fri, 15 Sep 2017 21:12:31 +0000</pubDate>
		<guid isPermaLink="false">https://raspberrytips.nl/?p=1104#comment-427</guid>

					<description><![CDATA[[&#8230;] Kaynak : https://raspberrytips.nl/lcd-scherm-20&#215;4-i2c-raspberry-pi/ [&#8230;]]]></description>
			<content:encoded><![CDATA[<p>[&#8230;] Kaynak : <a href="https://raspberrytips.nl/lcd-scherm-20&#215;4-i2c-raspberry-pi/" rel="ugc">https://raspberrytips.nl/lcd-scherm-20&#215;4-i2c-raspberry-pi/</a> [&#8230;]</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
