Sunday, October 16, 2016

3.5" SPI LCD experiments on Raspberry Pi Zero

A while back my local MicroCenter got some Pi Zeros in stock. I bought several, along with a couple microSD cards. I ordered a micro-HDMI adapter and an OTG USB hub, and I was in business.

I was poking around on Amazon and found that a number of vendors are selling low cost TFT LCDs that work over the hardware SPI port. A number of developers have written kernel drivers for them, including the very popular Notro FBTFT drivers  and SWKim01's Waveshare drivers. Prices range from $11 on up, with plenty being available for around $20.

I didn't have a project in mind, but it seemed like a neat thing to be able to do with a $5 computer, so I selected this one, a 3.5" LCD that uses the Waveshare driver. This unit is designed to plug right on top of the headers on the Pi Zero. This is convenient, but blocks a lot of the IO pins. The vendor provides a customized distribution of Rasbian for download, but I preferred to work on the standard one. Luckily, one of the reviewers left an outstanding review with all the details needed to get it going on a standard Raspian machine.

The Zero doesn't have any IO pin headers installed, so I added enough to plug in the LCD.

The LCD plugs in and stands off a good distance from the Pi. If I wanted a thinner setup, I'd probably buy an LCD that does not plug into the headers and hand wire the connections.

When you next start up the Pi, don't expect video yet. You need to do some configuration to have it use the correct driver for the framebuffer and direct the console there. All of this information came from the terrific writeup in an Amazon review here. I'm not breaking any new ground at all, but wanted to duplicate it in case the review goes away.

1) Edit /boot/cmdline.txt to have the following arguments:

dwc_otg.lpm_enable=0 console=tty1 console=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait fbcon=map:10 fbcon=font:ProFont6x11 logo.nologo
2) Add the following to the end of /boot/config.txt:


3) Download a copy of waveshare35a.dtb from swkim01's waveshare github site and copy it to /boot/overlays/waveshare35a.dtbo:

cp waveshare35a-overlay.dtb /boot/overlays/waveshare35a.dtbo

If, like me, you have a minimal installation without X Windows installed, you can reboot now - you're done. The framebuffer console should scroll on the LCD. I have not tested the section below yet, but the Amazon comment goes into the detail for configuring X Windows:

(update: I have tested X, and it works great. Notes on preventing screen blanking are below)

"4. edit /usr/share/X11/xorg.conf.d/99-fbturbo.conf to contain:

Section "Device"
Identifier "Allwinner A10/A13 FBDEV"
Driver "fbturbo"
Option "fbdev" "/dev/fb1"

Option "SwapbuffersWait" "true"

5. create a file named 99-calibration.conf under /etc/X11/xorg.conf.d to contain:

Section "InputClass"
Identifier "calibration"
MatchProduct "ADS7846 Touchscreen"
Option "Calibration" "3932 300 294 3801"
Option "SwapAxes" "1"

6. reboot and enjoy!" - Amazon Commenter Willie

Further useful stuff:

To disable screen blanking (framebuffer console only):

Add the following argument in /boot/cmdline.txt


Mine now looks like this, all on one line:

dwc_otg.lpm_enable=0 console=tty1 console=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait fbcon=map:10 fbcon=font:ProFont6x11 consoleblank=0

To disable X Windows screen blanking:

add the following to /etc/lightdm/lightdm.conf in the section [SeatDefaults]

xserver-command=X -s 0 -dpms

Framebuffer Console Tools

With the framebuffer working, you can use programs like fbi to display images, or other utilities to play video. I found that video did work, but was limited by the SPI throughput to a couple of frames per second, so I'm not convinced that's very useful. For displaying images in a slide show, this command works well:

sudo fbi -T 2 -d /dev/fb1 -a -t 5 -noverbose /home/pi/images/*

It will display all the images in the passed directory in an infinite loop with delay of 5 seconds.

No comments:

Post a Comment