Jump to content

Recommended Posts

Posted (edited)

Hi there, recently I bought an Orange Pi Zero3 with 1GB RAM. I want to connect a 20*4 character LCD display(https://www.tinytronics.nl/en/displays/lcd/lcd-display-20*4-characters-with-white-text-and-blue-backlight-with-i2c-backpack) to it. I have previously used this display with Arduino UNO, which worked great. Now I want to use it with the Orange Pi Zero3 (Ubuntu 24.04). I have no experience with the Orange Pi or single-board computers in general. I followed some tutorials, but I couldn't make it work. 

I did this:

 

Wiring:
 

I2C Backpack Orange Pi Zero3
VCC Pin 2
GND Pin 6
SCL Pin 5
SDA Pin 3

 

 

Terminal:

sudo apt-get install -y python-smbus i2c-tools

user@orangepizero3:~$ sudo i2cdetect -y 0

0 1 2 3 4 5 6 7 8 9 a b c d e f

00: -- -- -- -- -- -- -- -- -- -- -- -- --

10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

40: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --

50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

70: -- -- -- -- -- -- -- --

 

user@orangepizero3:~$ sudo i2cdetect -y 1

0 1 2 3 4 5 6 7 8 9 a b c d e f

00: -- -- -- -- -- -- -- -- -- -- -- -- --

10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

30: 30 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

40: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --

50: 50 -- -- -- 54 -- -- -- -- -- -- -- -- -- -- --

60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

70: -- -- -- -- -- -- -- --

 

 

It seems like the display cannot be found. How can I fix this?

Edited by bjan04
Added wiring details
Posted (edited)

I currently have OrangePi3 LTS and I use the firmware provided by OrangePi and there you had to install wiringOP and also run during system startup: i2c0
in the file: orangepiEnv.txt
That is, add the entry: overlays= i2c0 i2c1 i2c2
In Armbian firmware it is probably easier, you have to run the configuration from the terminal: armbian-config
and there find the section: I2C and enable: i2c0 / system restart
then proceed as you previously provided on the forum.

 

How to connect LCD to your model ... probably like I did to my OPi 3-LTS according to this tutorial. Of course the board is different but you have to find the same pins on your OrangePiZero3 model. I managed to do it so you should too.

for me it is: 3f

sudo i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 3f 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --  

I also use the lcdproc program to display the current time + install drivers for: hd44780

sudo apt-get install lcdproc lcdproc-extra-drivers

Find in your system where you have the file: hd44780.so

cd /

find -name hd44780.so

e.g. ./usr/lib/aarch64-linux-gnu/lcdproc/hd44780.so

and add change the path to the file in the configuration : DriverPath=/usr/lib/aarch64-linux-gnu/lcdproc/

Example lcdproc configuration: file: LCDd.conf
 

## Server section with all kinds of settings for the LCDd server ##
[server]

DriverPath=/usr/lib/aarch64-linux-gnu/lcdproc/
Driver=hd44780
Bind=127.0.0.1
Port=13666
ReportLevel=3
User=root
Foreground=no
Hello="Welcome to"
Hello="Armbian"
GoodBye="Internet Radio"
GoodBye="OrangePi3 LTS"
WaitTime=5
ServerScreen=off
Backlight=off
Heartbeat=off
TitleSpeed=4
ToggleRotateKey=Enter
PrevScreenKey=Left
NextScreenKey=Right


## The menu section. The menu is an internal LCDproc client. ##
[menu]

## Hitachi HD44780 driver ##
[HD44780]
ConnectionType=i2c
Device=/dev/i2c-0
Port=0x3f
Backlight=no
Size=16x2
DelayBus=false
DelayMult=1
Keypad=no
Speed=0
i2c_line_RS=0x01
i2c_line_RW=0x02
i2c_line_EN=0x04
i2c_line_BL=0x08

i2c_line_D4=0x10
i2c_line_D5=0x20
i2c_line_D6=0x40
i2c_line_D7=0x80
BacklightInvert=no

# EOF

 

in file lcdproc.conf

# LCDproc client configuration file

## general options ##
[lcdproc]
# address of the LCDd server to connect to
Server=localhost

# Port of the server to connect to
Port=13666

# set reporting level
ReportLevel=2

# report to to syslog ?
ReportToSyslog=false

# run in foreground [default: false; legal: true, false]
#Foreground=true

# PidFile location when running as daemon [default: /var/run/lcdproc.pid]
#PidFile=/var/run/lcdproc.pid

# slow down initial announcement of modes (in 1/100s)
#delay=2

# display name for the main menu [default: LCDproc HOST]
#DisplayName=lcdproc


## screen specific configuration options ##

[CPU]
# Show screen
Active=True
OnTime=1
OffTime=2
ShowInvisible=false


[Iface]
# Show screen
Active=True

# Show stats for Interface0
Interface0=eth0
# Interface alias name to display [default: <interface name>]
Alias0=LAN

# Show stats for Interface1
#Interface1=eth1
#Alias1=WAN

# Show stats for Interface2
#Interface2=eth2
#Alias2=MGMT

# for more than 3 interfaces change MAX_INTERFACES in iface.h and rebuild

# Units to display [default: byte; legal: byte, bit, packet]
unit=bit

# add screen with transferred traffic
#transfer=TRUE


[Memory]
# Show screen
Active=True


[Load]
# Show screen
Active=True
# Min Load Avg at which the backlight will be turned off [default: 0.05]
LowLoad=0.05
# Max Load Avg at which the backlight will start blinking [default: 1.3]
HighLoad=1.3


[TimeDate]
# Show screen
Active=True
# time format [default: %H:%M:%S; legal: see strftime(3)]
TimeFormat="%H:%M:%S"
# date format [default: %x; legal: see strftime(3)]
DateFormat="%x"


[About]
# Show screen
Active=false


[SMP-CPU]
# Show screen
Active=false


[OldTime]
# Show screen
Active=false
# time format [default: %H:%M:%S; legal: see strftime(3)]
TimeFormat="%H:%M:%S"
# date format [default: %x; legal: see strftime(3)]
DateFormat="%x"
# Display the title bar in two-line mode. Note that with four lines or more
# the title is always shown. [default: true; legal: true, false]
#ShowTitle=false


[BigClock]
# Show screen
Active=false


[Uptime]
# Show screen
Active=false


[Battery]
# Show screen
Active=false


[CPUGraph]
# Show screen
Active=false


[ProcSize]
# Show screen
Active=false


[Disk]
# Show screen
Active=false


[MiniClock]
# Show screen
Active=True
# time format [default: %H:%M; legal: see strftime(3)]
TimeFormat="%H:%M"


# EOF

But this is an example configuration for OrangePi3 LTS and the Python scripts that are on the forum refer to Python 2 which is already old and in the systems there is only Python 3 and these scripts may be outdated and not work correctly

Maybe there is some programmer who will convert it to Python 3 ๐Ÿ™‚

My configuration also has a fix for Polish diacritics that are displayed incorrectly on the LCD... as slashes and strange characters or question marks???? ๐Ÿ™‚

And the script supports mpd / mpc programs for internet radio

#!/usr/bin/python
# -*- coding: utf-8 -*-

import smbus
import time
import subprocess

from time       import sleep, strftime
from datetime   import datetime
from subprocess import *

# Define some device parameters
I2C_ADDR  = 0x3f # I2C device address
LCD_WIDTH = 16   # Maximum characters per line
LCD_HEIGHT = 2

# 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
#LCD_BACKLIGHT = 0x0C  # Off


ENABLE = 0b00000100 # Enable bit

# Timing constants
E_PULSE = 0.005
E_DELAY = 0.005

#Open I2C interface
bus = smbus.SMBus(0)  # Rev 1 Pi uses 0 (and Orange PI PC, for pins 3 and 5)
#bus = smbus.SMBus(1) # Rev 2 Pi uses 1


def lcd_byte(bits, mode):
  # Send byte to data pins
  # bits = the data
  # mode = 1 for data
  #        0 for command

  bits_high = mode | (bits & 0xF0) | LCD_BACKLIGHT
  bits_low = mode | ((bits<<4) & 0xF0) | LCD_BACKLIGHT

  # High bits
  bus.write_byte(I2C_ADDR, bits_high)
  lcd_toggle_enable(bits_high)

  # Low bits
  bus.write_byte(I2C_ADDR, bits_low)
  lcd_toggle_enable(bits_low)

def lcd_toggle_enable(bits):
  # Toggle enable
  time.sleep(E_DELAY)
  bus.write_byte(I2C_ADDR, (bits | ENABLE))
  time.sleep(E_PULSE)
  bus.write_byte(I2C_ADDR,(bits & ~ENABLE))
  time.sleep(E_DELAY)

def lcd_string(message,line):
  # Send string to display

  message = message.ljust(LCD_WIDTH," ")

  lcd_byte(line, LCD_CMD)

  for i in range(LCD_WIDTH):
    lcd_byte(ord(message[i]),LCD_CHR)

def replace_pl(chars):
  pl = {  'ฤ…': 'a',
          'ฤ‡': 'c',
          'ฤ™': 'e',
          'ล‚': 'l',
          'ล„': 'n',
          'รณ': 'o',
          'ล›': 's',
          'ลบ': 'z',
          'ลผ': 'z',
          'ฤ„': 'A',
          'ฤ†': 'C',
          'ฤ˜': 'E',
          'ล': 'L',
          'ลƒ': 'N',
          'ร“': 'O',
          'ลš': 'S',
          'ลน': 'Z',
          'ลป': 'Z',
  }
  for f, t in pl.items():
    chars = chars.replace(f,t)
  return chars

def main():

  counter = 0

  while True:

  # Get current status and playtime
    process = subprocess.Popen('sudo mpc -v', shell=True, stdout=subprocess.PIPE)
    ekran1 = process.communicate()[0]
    ekran1 = replace_pl(ekran1)
    statusLines = ekran1.split('\n')
    ekran1 = statusLines[1]
    if ekran1 <> '':
      ekran1L1 = ekran1.split(' ',1)[0].strip()
      ekran1L2temp = ekran1.split(' ',1)[1].strip()
      ekran1L2 = ekran1L2temp.split(' ',1)[0].strip()

    process = subprocess.Popen('sudo mpc -f %name%', shell=True, stdout=subprocess.PIPE)
    ekran2 = process.communicate()[0]
    ekran2 = replace_pl(ekran2)
    statusLines = ekran2.split('\n')
    ekran2 = statusLines[0]
    ekran2L1 = ekran2[0:16]
    ekran2L2 = ekran2[16:31]

    process = subprocess.Popen('sudo mpc -f %artist%', shell=True, stdout=subprocess.PIPE)
    ekran3 = process.communicate()[0]
    ekran3 = replace_pl(ekran3)
    statusLines = ekran3.split('\n')
    ekran3 = statusLines[0]
    ekran3L1 = ekran3[0:16]
    ekran3L2 = ekran3[16:31]

    process = subprocess.Popen('sudo mpc -f %title%', shell=True, stdout=subprocess.PIPE)
    ekran4 = process.communicate()[0]
    ekran4 = replace_pl(ekran4)
    statusLines = ekran4.split('\n')
    ekran4 = statusLines[0]
    ekran4L1 = ekran4[0:16]
    ekran4L2 = ekran4[16:31]

    if counter == 1:
      if ekran1 == "":
        counter = 7
      else:
        lcd_string(ekran1L1,LCD_LINE_1)
        lcd_string(ekran1L2,LCD_LINE_2)
    if counter == 7:
      if ekran2 == "":
        counter = 14
      else:
        lcd_string(ekran2L1,LCD_LINE_1)
        lcd_string(ekran2L2,LCD_LINE_2)
    if counter == 14:
      if ekran3 == "":
        counter = 25
      else:
        lcd_string(ekran3L1,LCD_LINE_1)
        lcd_string(ekran3L2,LCD_LINE_2)
    if counter == 25:
      if ekran4 == "":
        counter = 35
      else:
        lcd_string(ekran4L1,LCD_LINE_1)
        lcd_string(ekran4L2,LCD_LINE_2)

    sleep(0.1)
    counter = counter + 1
    if counter == 40:
      counter = 1


if __name__ == '__main__':

  try:
    main()
  except KeyboardInterrupt:
    pass
  finally:
    lcd_byte(0x00, LCD_CMD)
    lcd_byte(0x01, LCD_CMD)
    lcd_byte(0x08, LCD_CMD)

 

Edited by kris777

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

ร—   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

ร—   Your link has been automatically embedded.   Display as a link instead

ร—   Your previous content has been restored.   Clear editor

ร—   You cannot paste images directly. Upload or insert images from URL.

ร—
ร—
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines