🛠 Activer le bus SPI0 et piloter un petit écran TFT
Objectives
The 40-pin connector on the BPI-M2 Zero exposes the SPI0 controller on pins 19/21/23/24 (signals PC0 to PC3 according to the wiki table): enough to connect a small TFT screen with an ILI9341 controller, a segmented display, or any SPI peripheral. You will enable the bus via Armbian configuration, verify the controller with a MOSI-to-MISO loopback test, then write bytes using python-spidev before tackling the framebuffer layer.
Hardware
- BPI-M2 Zero running Armbian
- 2.4" ILI9341 TFT screen in SPI mode (6 pins: VCC, GND, CS, RESET, DC, SDI — also wire LED/K to 3.3V)
- 6 Dupont wires; power the screen at 3.3V
- For the cable test: a simple jumper from MOSI (pin 19) to MISO (pin 21)
Complete code
# 1) Activer SPI0 (overlay) puis redémarrer
grep overlays /boot/armbianEnv.txt
sudo armbian-config # System > Hardware > SPI0 (spi-spidev)
sudo reboot
# 2) Le périphérique est apparu
ls /dev/spidev*
ls -l /sys/class/spi_master/ | cat
# 3) Test boucle-à-boucle : pont filaire broche 19 (MOSI) -> broche 21 (MISO)
sudo apt install -y python3-spidev
python3 - <<'EOF'
import spidev
spi = spidev.SpiDev
spi.open(0, 0) # bus 0, cs0
spi.max_speed_hz = 8000000
rx = spi.xfer2([0xA5, 0x5A, 0xF0])
print("reçu :", [hex(b) for b in rx]) # attendu 0xa5 0x5a 0xf0 en boucle-à-boucle
EOF
# 4) Écran ILI9341 : piloter via un pilote framebuffer (fbtft) ou une
# bibliothèque Python dédiée au contrôleur, en gardant SPI <= 8-16 MHz
Expected verification
After activation, /dev/spidev0.0 exists; the loopback test returns exactly the bytes sent (0xa5, 0x5a, 0xf0), proving that the controller, the PC0-PC3 muxing, and the wiring are correct. Once the screen is connected, the ILI9341 libraries display shapes and text.
Common errors
- Forgetting the overlay: without it, no /dev/spidev appears and gpioinfo shows the pins as free but silent.
- Powering the screen at 5V while the SPI logic outputs 3.3V: 5V-tolerant inputs are rare, stay at 3.3V.
- The ILI9341 RESET and DC pins require two additional GPIO pins: reserve them in the pinout before wiring everything.
- Pushing the SPI frequency too high with Dupont wires: incorrect pixels or a black screen, lower it to 8 MHz.
- Confusing SPI0 (PC0-PC3, pins 19/21/23/24) with SPI1 (PA13-PA16), whose signals also appear in the wiki table but on different pins.
Other tutorials for this board
- Flasher Armbian et premier boot du BPI-M2 Zero
- LED et bouton avec libgpiod sur le port 40 broches
- Wi-Fi AP6212 : le piège de l'antenne U.FL non fournie
- Console série sur USB-OTG : dépanner sans réseau ni câble UART
- Survivre avec 512 Mo : zram, swap compressé et services légers
- Câbler l'Ethernet 10/100 EMAC avec le carrier Zero-EPHY
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash