0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

blinka.logo Adafruit Blinka とは

マイコンデバイスで動作する CircuitPython のライブラリを,Linux SBC の Python から利用するための API を提供する Python モジュールです。

Raspberry Pi 4 に Blinka をインストールする

↓ 次の環境のRaspberry Pi 4 に Blinka をインストールした手順を説明する。

環境
$ cat /sys/firmware/devicetree/base/model
Raspberry Pi 4 Model B Rev 1.5

$ cat /etc/debian_version
11.9

$ cat /etc/issue
Debian GNU/Linux 11 \n \l

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 11 (bullseye)
Release:	11
Codename:	bullseye

$ uname -a
Linux raspberrypi4 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr  3 17:24:16 BST 2023 aarch64 GNU/Linux

$ cat /proc/version
Linux version 6.1.21-v8+ (dom@buildbot) (aarch64-linux-gnu-gcc-8 (Ubuntu/Linaro 8.4.0-3ubuntu1) 8.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #1642 SMP PREEMPT Mon Apr  3 17:24:16 BST 2023

↑このサイトの手順に従っている。

Update Your Pi and Python

RasPi と python を最新にする

$ sudo apt update
$ sudo apt upgrade -y

$ sudo apt install --upgrade python3-setuptools -y

Setup Virtual Environment

Bookwormバージョンにインストールする場合は、仮想環境にPythonモジュールをインストールする必要があるようだが、Bullseye でも仮想化して問題ないはず。

$ sudo apt install python3-venv
$ python3 -m venv env --system-site-packages

$ source env/bin/activate

Automated Install

raspi-blinka.pyをダウンロードして、自動インストールします。

$ cd ~
$ pip3 install --upgrade adafruit-python-shell
$ wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/raspi-blinka.py
$ sudo -E env PATH=$PATH python3 raspi-blinka.py
  :  :  :
Settings take effect on next boot.
REBOOT NOW? [Y/n] 

インストール後、リブートします。

Blinka Test

Blinka がインストールできたことをテストします。
仮想環境にして、後述するblinkatest.pyを実行します。

$ source env/bin/activate
(env) $ python3 blinkatest.py
Hello, blinka!
Digital IO ok!
I2C ok!
SPI ok!
done!

問題ないようです。

blinkatest.pyのコード

blinkatest.py
import board
import digitalio
import busio

print("Hello, blinka!")

# Try to create a Digital input
pin = digitalio.DigitalInOut(board.D4)
print("Digital IO ok!")

# Try to create an I2C device
i2c = busio.I2C(board.SCL, board.SDA)
print("I2C ok!")

# Try to create an SPI device
spi = busio.SPI(board.SCLK, board.MOSI, board.MISO)
print("SPI ok!")

print("done!")

digitaliobusioといった、CircuitPythonのライブラリが使えます。

help("modules")

使えるモジュールを確認しようとしましたが、↓なぜかエラーになります。

$ source env/bin/activate
(env) $ python
Python 3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> help("modules")

Please wait a moment while I gather a list of all available modules...

Warning, could not find Analog or Touch...
Please check your i2c settings!
(env) $ 

ネット上で 同じ現象のQ&Aを多く見つけることができますが、どの解決策も有効ではありませんでした。

↓ ちなみに、ESP32-S3 にインストールしたCircuitPythonhelp("modules")を実行した結果は、次のとおり。

Adafruit CircuitPython 9.0.4 on 2024-04-16; VCC-GND YD-ESP32-S3 (N16R8) with ESP32S3
>>> help('modules')
__future__        collections       memorymap         supervisor
__main__          countio           microcontroller   synthio
_asyncio          digitalio         micropython       sys
_bleio            displayio         msgpack           terminalio
_pixelmap         dualbank          neopixel          time
adafruit_bus_device                 epaperdisplay     neopixel_write    touchio
adafruit_bus_device.i2c_device      errno             nvm               traceback
adafruit_bus_device.spi_device      espcamera         onewireio         ulab
adafruit_pixelbuf espidf            os                ulab.numpy
aesio             espnow            paralleldisplay   ulab.numpy.fft
alarm             espulp            paralleldisplaybus                  ulab.numpy.linalg
analogbufio       fontio            ps2io             ulab.scipy
analogio          fourwire          pulseio           ulab.scipy.linalg
array             framebufferio     pwmio             ulab.scipy.optimize
atexit            frequencyio       qrio              ulab.scipy.signal
audiobusio        gc                rainbowio         ulab.scipy.special
audiocore         getpass           random            ulab.utils
audiomixer        gifio             re                usb_cdc
binascii          hashlib           rgbmatrix         usb_hid
bitbangio         i2cdisplaybus     rotaryio          usb_midi
bitmapfilter      io                rtc               vectorio
bitmaptools       ipaddress         sdcardio          warnings
board             jpegio            select            watchdog
builtins          json              sharpdisplay      wifi
busdisplay        keypad            socketpool        zlib
busio             locale            ssl
canio             math              storage
codeop            mdns              struct
Plus any modules on the filesystem
>>> 

CircuitPython Libraries

(env) $ pip list
Package                                  Version
---------------------------------------- ---------
Adafruit-Blinka                          8.45.2
adafruit-circuitpython-busdevice         5.2.9
adafruit-circuitpython-connectionmanager 3.1.1
adafruit-circuitpython-requests          4.1.3
adafruit-circuitpython-typing            1.10.3
Adafruit-PlatformDetect                  3.71.0
Adafruit-PureIO                          1.1.11
adafruit-python-shell                    1.8.1
 :  :

Adafruit-Blinka 8.45.2とあるので、CircuitPython 8.x ではないかと思います。

CircuitPython の最新は 9.0.5(執筆時点)

CircuitPython のライブラリは、↓こちらにリンクがあります。

  • Bundles
  • The Community Bundle

以上

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?