Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Adafruit Logo
0
NFC Raspberry Pi Media Player Installing Blinka on Raspberry Pi

NFC Raspberry Pi Media Player

published November 08, 2024, last edited February 28, 2025
Save Link Note Download
34
Intermediate
Project guide
😍1
🔥1

Installing Blinka on Raspberry Pi

CircuitPython libraries and adafruit-blinka will work on any Raspberry Pi board! That means the original 1, the Pi 2, Pi 3, Pi 4, Pi 5, Pi Zero, Pi Zero 2 W, or even the compute modules.
At this time, Blinka requires Python version 3.7 or later, which means you will need to at least be running Raspberry Pi OS Bullseye.

Prerequisite Pi Setup!

In this page we'll assume you've already gotten your Raspberry Pi up and running and can log into the command line

Here's the quick-start for people with some experience:

  1. Download the latest Raspberry Pi OS or Raspberry Pi OS Lite to your computer
  2. Burn the OS image to your MicroSD card using your computer
  3. Re-plug the SD card into your computer (don't use your Pi yet!) and set up your wifi connection by editing supplicant.conf
  4. Activate SSH support
  5. Plug the SD card into the Pi
  6. If you have an HDMI monitor we recommend connecting it so you can see that the Pi is booting OK
  7. Plug in power to the Pi - you will see the green LED flicker a little. The Pi will reboot while it sets up so wait a good 10 minutes
  8. If you are running Windows on your computer, install Bonjour support so you can use .local names, you'll need to reboot Windows after installation
  9. You can then ssh into raspberrypi.local

The Pi Foundation has tons of guides as well

We really really recommend the latest Raspberry Pi OS only. If you have an older Raspberry Pi OS install, run "sudo apt-get update" and "sudo apt-get upgrade" to get the latest OS!

Update Your Pi and Python

Run the standard updates:

sudo apt-get updatesudo apt-get -y upgradesudo apt-get install -y python3-pip
sudo apt-get updatesudo apt-get -y upgradesudo apt-get install -y python3-pip

and upgrade setuptools:

sudo apt install --upgrade python3-setuptools
sudo apt install --upgrade python3-setuptools
You may need to reboot prior to installing Blinka. The raspi-blinka.py script will inform you if it is necessary.
If you are installing in a virtual environment, the installer may not work correctly since it requires sudo. We recommend using pip to manually install it in that case.

Setup Virtual Environment

If you are installing on the Bookworm version of Raspberry Pi OS, you will need to install your python modules in a virtual environment. You can find more information in thePython Virtual Environment Usage on Raspberry Pi guide. To Install and activate the virtual environment, use the following commands:

cd ~sudo apt install python3-venvpython3 -m venv env --system-site-packages
cd ~sudo apt install python3-venvpython3 -m venv env --system-site-packages

You will need to activate the virtual environment every time the Pi is rebooted. To activate it:

source env/bin/activate
source env/bin/activate

To deactivate, you can usedeactivate, but leave it active for now.

Automated Install

We put together a script to easily make sure your Pi is correctly configured and install Blinka. It requires just a few commands to run. Most of it is installing the dependencies.

cd ~pip3 install --upgrade adafruit-python-shellwget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/raspi-blinka.pysudo -E env PATH=$PATH python3 raspi-blinka.py
cd ~pip3 install --upgrade adafruit-python-shellwget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/raspi-blinka.pysudo -E env PATH=$PATH python3 raspi-blinka.py

If you are installing on an earlier version such as Bullseye of Raspberry Pi OS and not using a Virtual Environment, you can call the script like:

sudo python3 raspi-blinka.py

sensors_Python_Sys_Default.png

If you are installing an older version of Raspberry Pi OS, your system default Python is likely Python 2. If so, it will ask to confirm that you want to proceed. Choose yes.

sensors_Reboot_Now.png

It may take a few minutes to run. When it finishes, it will ask you if you would like to reboot.Choose yes.

sensors_Connection_Closed.png

Once it reboots, the connection will close. After a couple of minutes, you can reconnect.

Manual Install

If you are having trouble running the automated installation script, you can follow these steps to manually install Blinka.

Enable Interfaces

Run these commands to enable the various interfaces such as I2C and SPI:

sudo raspi-config nonint do_i2c 0sudo raspi-config nonint do_spi 0sudo raspi-config nonint do_serial_hw 0sudo raspi-config nonint do_ssh 0sudo raspi-config nonint do_camera 0sudo raspi-config nonint disable_raspi_config_at_boot 0
sudo raspi-config nonint do_i2c 0sudo raspi-config nonint do_spi 0sudo raspi-config nonint do_serial_hw 0sudo raspi-config nonint do_ssh 0sudo raspi-config nonint do_camera 0sudo raspi-config nonint disable_raspi_config_at_boot 0

Install Blinka and Dependencies

Blinka needs a few dependencies installed:

sudo apt-get install -y i2c-tools libgpiod-dev python3-libgpiodpip3 install --upgrade adafruit-blinka
sudo apt-get install -y i2c-tools libgpiod-dev python3-libgpiodpip3 install --upgrade adafruit-blinka

Raspberry Pi 5 Adjustments

At the moment, RPi.GPIO is installed, which causes issues. Just remove it with the following command:

pip3 uninstall -y RPi.GPIO
pip3 uninstall -y RPi.GPIO

Check I2C and SPI

The script will automatically enable I2C and SPI. You can run the following command to verify:

ls /dev/i2c* /dev/spi*
ls /dev/i2c* /dev/spi*

You should see the response

/dev/i2c-1 /dev/spidev0.0 /dev/spidev0.1

sensors_ls.png

Fixing CE0 and CE1 Device or Resource Busy Issue

In order to use the CE0 and CE1 pins in Python, you will need to disable them from OS usage. To do so, check out theReassigning or Disabling the SPI Chip Enable Lines section of this guide.

Enabling Second SPI

If you are using the main SPI port for a display or something and need another hardware SPI port, you can enable it by adding the line

dtoverlay=spi1-3cs

to the bottom of/boot/config.txt and rebooting. You'll then see the addition of some /dev/spidev1.x devices:

sensors_image.png

Pi 5 :Cannot determine SOC peripheral base address

comment out this line :

#dtparam=spi=on
#dtparam=spi=on

Blinka Test

If onewire is enabled, you may need to use another digital input besides D4.

Create a new file calledblinkatest.py withnano or your favorite text editor and put the following in:

import boardimport digitalioimport busioprint("Hello, blinka!")# Try to create a Digital inputpin = digitalio.DigitalInOut(board.D4)print("Digital IO ok!")# Try to create an I2C devicei2c = busio.I2C(board.SCL, board.SDA)print("I2C ok!")# Try to create an SPI devicespi = busio.SPI(board.SCLK, board.MOSI, board.MISO)print("SPI ok!")print("done!")
import boardimport digitalioimport busioprint("Hello, blinka!")# Try to create a Digital inputpin = digitalio.DigitalInOut(board.D4)print("Digital IO ok!")# Try to create an I2C devicei2c = busio.I2C(board.SCL, board.SDA)print("I2C ok!")# Try to create an SPI devicespi = busio.SPI(board.SCLK, board.MOSI, board.MISO)print("SPI ok!")print("done!")

Save it, make sure your virtual environment is activated, and run at the command line with:

python3 blinkatest.py
python3 blinkatest.py

You should see the following, indicating digital i/o, I2C and SPI all worked.

sensors_test.png

Page last edited January 21, 2025

Text editor powered bytinymce.

Related Guides
Search

Search

Categories

[8]ページ先頭

©2009-2025 Movatter.jp