Thursday, February 22, 2018

How to: Installing Kodi / LibreELEC on a Raspberry Pi with a 5-inch LCD display

I bought an Elecrow 5-inch LCD display on Amazon.com in December 2016, on one of their Lightning Deals, to install on a Raspberry Pi 2 Model B.

I finally got around to installing it on the Raspberry Pi. It works great. In fact, it works so well that I also installed it on a brand-new Raspberry Pi Zero W. (You want pictures? I'll add pictures. But the words are really important right now.) On both the Pi 2 B and the Pi Zero W, I was running the Raspbian OS. I'm sure it works just fine with Noobs, but I like Raspbian better.

I'll bet it works on a Raspberry Pi 3 as well.

But what I really wanted to do with it was run a home theatre system, specifically XBMC. XBMC is a wildly successful home theatre operating system. Actually, what used to be called XBMC is now called Kodi, and it's still wildly successful.

The Elecrow display and the Pi liked each other right from the start. I connected them, turned them on, and they played nicely together. Getting the software to run flawlessly on the combination took a bit more work.

Here are the steps to follow to get either Raspbian or the home theatre system working flawlessly with Raspberry Pi 2 Model B and an Elecrow display. These steps are also applicable to other Elecrow displays and other Raspberry Pi computers.

Installation on Raspbian OS


Under "Product Description" on the Amazon page, you will find these instructions:

  1. Download the Raspbian Stretch with Desktop image from the official Raspberry Pi downloads page. Don't bother with the Lite version. You want the real thing.
  2. If you use Etcher to write the image to your micro SD card, you won't even need to unzip the image. Etcher handles ZIP files, IMG files, TAR files, all of 'em. Etcher is the slickest program I've seen for SD cards and USB drives. It works on Mac, Linux or Windows PCs. You can get it from https://etcher.io/. (UPDATE: It's now https://www.balena.io/etcher/ .)
  3. Insert the micro SD card into your Pi.
  4. Plug the display into the Pi and power it up. Which "it" do I mean? Well, if you're using the Pi 2 or Pi 3, connecting power to either the display or the Pi will power up both of them. If you're using the Pi Zero, you'll need to connect power to the display first, and then to the Pi Zero.
  5. You will see the boot splash on the display, and the Pi will power up and run, but you will see that it only uses a 640 x 480 section of the display. Now you're going to teach it to use the full 800 x 480.
  6. Open a terminal window. Make sure git is installed on your Pi. If it isn't, use the command
    sudo apt-get install git
    to install it.
  7. Then use the command
    git clone https://github.com/Elecrow-keen/Elecrow-LCD5.git
    to download the driver.
  8. To install the driver, use these two commands:
    cd Elecrow-LCD5
    sudo ./Elecrow-LCD5
  9. You may need to reboot to make the change effective. I don't remember. I hope you don't. To reboot safely, use this command:
    sudo shutdown -r now
    (The "-r" means "just reboot, don't power off". The "now" means "don't wait; do it now".)
  10. To (optionally) calibrate the touchscreen, execute these two commands:
    sudo apt-get install xinput-calibrator
    xinput-calibrator
  11. Using the stylus supplied with the display, poke the four crosshairs as they appear on the screen.

Installation on Kodi / LibreELEC

First came XBMC. It was so wildly successful that it turned into Kodi. It was so wildly successful that it turned into OpenELEC. (Actually, OpenELEC is a tiny Linux OS made specifically to run Kodi, but let's not quibble over details, okay?) Then, because of "creative differences", a lot of developers abandoned OpenELEC and that's where LibreELEC came from. LibreELEC is a fork of OpenELEC.

OpenELEC was last updated in April 2017, and support for it is deteriorating. LibreElec was updated a few weeks ago. LibreELEC is alive and lovingly cared for. But it's still XBMC, Kodi, and OpenELEC deep in its bones.

  1. Follow the excellent instructions on LIbreELEC's own wiki to download and install the LibreELEC USB-SD Creator on your system: Mac, Linux, Windows, we don't care.
  2. Again, following the excellent instructions on that page, run the Creator program to download the appropriate version of LibreELEC onto your micro SD card.
  3. Insert the micro SD card into your Pi.
  4. Plug the display into the Pi and power it up. If you're using the Pi 2 or Pi 3, connecting power to either the display or the Pi will power up both of them. If you're using the Pi Zero, you'll need to connect power to the display first, and then to the Pi Zero.
  5. You will see the boot splash on the display, and the Pi will power up and run, but it only uses a 640 x 480 section of the display. Now things get tricky.
  6. At the top of the left-side menu are three icons: an on-off icon, a gear icon, and a search icon. Click the gear icon to bring up the Settings menu.
  7. Click the LibreELEC icon. It's probably in the lower left corner.
  8. In the LibreELEC menu, select Services. On the right-hand side, select Enable SSH. Make sure it's enabled.
  9. Still in the LibreELEC menu, select Connections. Write down the Address of your device. It will be something like "192.168.0.77".
  10. Leave the Pi alone for a while. Go to another computer and open an SSH connection to the Pi.
  11. If you're on Windows, use  Putty.
    Hostname: 192.68.0.77 (or whatever it says in the Connections menu)
    Port: 22
    Connection type: SSH
  12. When you click Open, Putty will give you a scary message. Select Yes.
    login as: root
    root@192.168.0.77's password: libreelec
  13. If you're on Linux, use a regular terminal window.
    ssh root@192.168.0.77
  14. If Linux gives you a scary message, follow the instructions. If it asks you a question, type "yes".
    root@192.168.0.77's password: libreelec
  15. Sorry, Mac users. You're on your own. But I'll bet it's a lot like the Linux instructions.
  16. Once you're in the SSH session:The files inside libreelec are read-only. Write protected. A simple "chmod +w" isn't going to do it for you. Again, follow the excellent instructions on this page of LibreELEC's wiki to unlock the config.txt file for editing.
  17. It occurs to me that that page may one day disappear. So here's what it says. Type this command to unlock the partition on the SD card:
    mount -o remount,rw /flash
  18. Then type one of these two commands to edit the file, depending on which editor you want to use. If you don't know what vi is, then choose nano.
    vi /flash/config.txt
    or
    nano /flash/config.txt
  19. Look for the line that says "hdmi_ignore_cec_init=1". 
  20. Copy and paste these lines into the config.txt file, just below that "hdmi_ignore..." line:

    #increase HDMI signal strength
    config_hdmi_boost=4
    #remove black borders
    disable_overscan=1
    #set specific CVT mode
    hdmi_cvt 800 480 60 6 0 0 0
    #set CVT as default
    hdmi_group=2
    hdmi_mode=87

    dtoverlay=ads7846,cs=1,penirq=25,penirq_pull=2,speed=50000,keep_vref_on=0,swapxy=0,pmax=255,xohms=150,xmin=200,xmax=3900,ymin=200,ymax=3900

    dtoverlay=w1-gpio-pullup,gpiopin=4,extpullup=1
  21. SPECIAL NOTE: That "dtoverlay" line is all one long, long line! Don't break it up like Blogspot did!
  22. Save the file and exit the editor.
  23. Lock the partition:
    mount -o remount,ro /flash
  24. Reboot the system:
    reboot
  25. You should see the boot splash screen centered in the display, and when LibreELEC comes up, you should see it fill the entire display.

Thanks to:

  • Elecrow, for putting the instructions right on the product page at Amazon.com.
  • Amazon.com, of course.
  • @Auvy and the other commenters on the product page at Amazon.com, who added their technical advice. I had to choose one, and @Auvy's worked.
  • LibreELEC for the excellent instructions on their wiki, and for their SD Creator program.
  • Etcher.io, for their SD creator program.
  • RaspberryPi.org, of course.

3 comments:

Unknown said...

Great article. The one question how to make Libreelec with Kodi recognize touch gestures. For now I can use only my mouse or keyboard. Any advice?

Anonymous said...

2 years later lol, I believe it's in Settings > System > Input > Enable mouse and touchscreen support

It was enabled in Libreelec by default for me

Zyzmog said...

Good catch, @Anonymous! Thank you for replying to that. This article still gets read frequently, so I appreciate the update.