SERIAL PERIPHERAL INTERFACE: Driving SPI displays
Linux Format|December 2021
Let’s go on an adventure into the SPI protocol, LCD displays and model trains with Sean Conway toot-tooting away!
Sean Conway

YOU NEED

Raspberry Pi Model 3B+

SD card 8GB or more

Pimoroni 1.3-inch SPI colour LCD (240x240) BR (Digi-Key PIM476)

Raspberry Pi OS Lite (4 Mar 21+)

Python ST7789 library to control an ST7789 TFT LCD display

Pillow Python Imaging Library

SPI is a synchronous serial communication interface specification that was developed by Motorola in the mid-1980s to provide full duplex (transmit/receive data in both directions) synchronous serial communication between controller and peripheral devices. Synchronous in protocols means that the communication is controlled by a controller (the Raspberry Pi) that talks to the peripheral – in this case an LCD device.

The SPI protocol defines no special bits to manage data. Limiting this overhead allows for high-speed data streaming. To provide some flexibility in communication, the serial clock has two options – Clock Polarity (CPOL) and Clock Phase (CPHA) – which, when configured, establish one of four modes.

In mode 0, data input/output occurs at the rising edge of the clock signal, where the clock polarity is low. For mode 1, data input/output occurs at the falling edge of the clock signal, where the clock polarity is low. To engage mode 2, data input/output occurs at the falling edge of the clock signal, where the clock polarity is high. In mode 3, data input/output occurs at the rising edge of the clock signal, where the clock polarity is high. CPOL and CPHA values are specified as ‘0’ or ‘1’ to form the four unique modes.

Some display boards have no chip select (CS) pin. We must set the SPI mode to 3 for these boards to work. Other boards work with SPI mode set to 0, which is the default for the Pimoroni ST7789 Python driver we will deploy later in the tutorial.

Continue reading your story on the app

Continue reading your story in the magazine

MORE STORIES FROM LINUX FORMATView All

THE GUIX SYSTEM

Guix takes a novel approach to its package management. Mats Tage Axelsson guides you around it.

10+ mins read
Linux Format
February 2022

CLOUD SOVEREIGNTY

Jonni Bidwell reveals how Nextcloud has become the poster-child not just for self-hosting, but for how to be a sustainable, successful FOSS project.

6 mins read
Linux Format
February 2022

4MLinux 38.0

Any distro that’s survived for over a decade must be doing something right, but Mayank Sharma wasn’t prepared for what he saw inside this one…

3 mins read
Linux Format
February 2022

Calculate Linux 22

Jonni Bidwell was dubious about making Gentoo easy, but after careful calculation of this KDE Edition he’s all for the idea…

3 mins read
Linux Format
February 2022

COMBAT MALWARE!

Jonni Bidwell wants to turn the tide on ransomware in 2022. It appears he has his work cut out for him…

10+ mins read
Linux Format
February 2022

Display HAT Mini

Les Pounder thinks that Pimoroni’s latest display was designed for ants, or at least younger people with better eyesight than him.

3 mins read
Linux Format
February 2022

Easyspace web hosting

Mike Williams assesses a skilled UK host famous for its speed…

3 mins read
Linux Format
February 2022

DUAL-BOOT+ Booting multiple operating systems

Christian Cawley examines the various ways you can boot your Raspberry Pi, from installing an OS to multibooting.

10+ mins read
Linux Format
February 2022

Endless OS 4.0

Five minutes with the latest version of this distro and Mayank Sharma is reminded of the old adage: “The whole is greater than the sum of its parts.”

3 mins read
Linux Format
February 2022

Stellaris

Management hates anyone going anywhere, boldly or otherwise, so Phil Savage is in a space pickle as he’s only gone and taken over the galaxy.

3 mins read
Linux Format
February 2022
RELATED STORIES

How to buy a budget laptop without getting ripped off

Even the cheapest laptops are expensive. Shop smart with this guide.

5 mins read
PCWorld
January 2022

Surface Go 3: A lateral upgrade for Microsoft's uniquely affordable tablet

If you’re in the market for Microsoft’s Surface Go 3, consider the Surface Go 2, too.

10+ mins read
PCWorld
January 2022

Humankind

Human kind. Bear ferocious. Egyptian chariot terrifying.

5 mins read
Maximum PC
November 2021

AMD Radeon RX 6600 XT

Mainstream with a high-end price

3 mins read
Maximum PC
November 2021

THE BEST PREBUILT PCS WITH AMD'S RYZEN 5300G, 5600G, OR 5700G APUS

BEAT THE GRAPHICS CARD CRUNCH WITH ONE OF THESE PREBUILT PCS POWERED BY AMD’S 5000-SERIES APUS.

5 mins read
PCWorld
September 2021

Nvidia GeForce RTX 3070 Ti

8GB of GDDR6X isn’t enough

3 mins read
Maximum PC
September 2021

CURSE CORRECTION

CURSE OF THE DEAD GODS is a sharp and atmospheric roguelike dungeon crawler.

4 mins read
PC Gamer US Edition
June 2021

Gigabyte Aorus 17G

Strong, mean, desktop rivaling machine?

3 mins read
Maximum PC
May 2021

Nvidia GeForce RTX 3070 Founders Edition

RTX 2080 Ti performance at half the price?

3 mins read
Maximum PC
January 2021

Tips to Boost Your Android Phone's Battery Life

A number of factors contribute to poor battery life on your Android phone. Thinner bodies, brighter screens, faster processors, more background software, and speedier internet connections all take their toll on phone batteries, though manufacturers are incorporating more powerful batteries to compensate. The Motorola Moto G Power has a 5,000mAh battery that can last for over 18 hours. Samsung’s Galaxy S phones, the most popular Android devices, can now last anywhere between 11 and 13 hours, depending on the model. Still, there are ways to get more out of any phone.

6 mins read
PC Magazine
January 2021