LoginSignup
1
4

More than 3 years have passed since last update.

初めてのRaspberry Pi Pico ㉛ CircuitpythonでTFTディスプレイに表示

Posted at

 SPIバスは、I2Cバスに比べて転送速度が速いため、表示面積の大きな表示器で使われます。マニュアルでは、board.SPI() → busio.SPIと書かれているので、busioモジュールのSPIを使います。

TFTディスプレイST7789を利用

 Adafruitから入手したSPI接続のTFTディスプレイを利用します。320×240ドットで、バックライトはデフォルトでONです。
ファイル名

接続

ST7789ボードの端子 Picoの端子(GPIO) 名称
BackLight - -
SD CS - -
D/C GP7 GP7
RESET GP6 GP6
LCD CS GP5 GP5
MOSI GP3 SPI0 TX
MISO - -
SCK GP2 SPI0 SCK
GND GND GND
3.3 - -
Vin 3.3V 3V3(OUT)

プログラム

 Helvetica-Bold-16.bdfはここからダウンロードし、CIRCUITPYドライブのルートにコピーします。
 テキストの表示に絞っています。CPUの温度を、text_area2で表示しています。

# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

from board import *
import busio
import terminalio
import displayio
from adafruit_display_text import label
from adafruit_bitmap_font import bitmap_font
from adafruit_st7789 import ST7789
import microcontroller
import time

displayio.release_displays()  # Release any resources
spi = busio.SPI(clock=GP2, MOSI=GP3)  # SPI0BUS PIN
display_bus = displayio.FourWire(
    spi, command=GP7, chip_select=GP5, reset=GP6) # other PIN
display = ST7789(display_bus, width=240, height=320)
splash = displayio.Group()  # Make the display context
display.show(splash)

# Draw a label=text
text_group = displayio.Group(scale=4, x=20, y=110)
text = "Temp"
font = bitmap_font.load_font("/Helvetica-Bold-16.bdf")
label.anchor_point = (0.0, 0.0)
label.anchored_position = (0, 0)
text_area = label.Label(font, text=text, color=0xFF00FF)
text_group.append(text_area)  # Subgroup for text
splash.append(text_group)

text_group = displayio.Group(scale=2, x=100, y=10)
text = 'start'
text_area2 = label.Label(terminalio.FONT, text=text, color=0xFFFF00)
text_group.append(text_area2)  # Subgroup for text
splash.append(text_group)

RANGE = 66
while True:
    for i in range(1,RANGE):
        text_area2.text = str(round(microcontroller.cpu.temperature,1)) + 'C'
        text_area2.y = i
        text_area2.x = int(i/2)

    for i in range(1,RANGE):
        text_area2.text = str(round(microcontroller.cpu.temperature,1)) + 'C'
        text_area2.y = RANGE+i
        text_area2.x = RANGE-int(i/2+RANGE/2)

    for i in range(RANGE,1,-1):
        text_area2.text = str(round(microcontroller.cpu.temperature,1)) + 'C'
        text_area2.y = RANGE+i
        text_area2.x = int(i/2-RANGE + RANGE/2)

    for i in range(1,RANGE):
        text_area2.text = str(round(microcontroller.cpu.temperature,1)) + 'C'
        text_area2.y = RANGE-i
        text_area2.x = int(i/2 - RANGE/2)

 実行中の様子です。二つのテキスト領域はスプライト画面なので、独立しています。温度を表示している部分を、壁にぶつかるとコースを変えるような形で動かしています。

ファイル名

ファイル名

1
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
4