・2017/11/20
Raspberry Piに SPI接続の LANモジュール ENC28J60を接続して LANポートを増設する方法
(ラズパイの SPIに ENC28J60を接続して LANポートを増設する方法、dtoverlay=enc28j60で簡単)
Tags: [Raspberry Pi], [電子工作]
● Raspberry Pi 3 Model Bを遂に購入
Raspberry Pi3 Model B RPI2 RPI3
大人気の CPUボードの Raspberry Piに WiFiと Bluetoothが搭載されたモデルが新発売となりました。
以前から Raspberry Pi 2を買おうかどうか迷っていましたが、Raspberry Pi 3 Model Bの発売を機に購入を決意してラズベリアンになる事にしました。
※ ラズパイの OS Raspbianはバージョンが上がる毎に過去の版と OSの内部の作りが変わり、過去に書かれた製作記事(例えば Raspbian Wheezyの時代の記事)がそのままではエラーが出たりして動かない事が有ります。
※ 当方のホームページのラズパイ記事は全て Raspberry Pi 3 Model Bと Raspbian Jessieの組み合わせで動作確認をしております。
(ただし、将来的に新しい Raspbian OSが出た場合に、当方の Raspbian Jessieを基にした内容がそのままでは動かない可能性が有ります。)
※ 2017/08/16から Raspbian OSは Raspbian Jessieから Raspbian Stretchに変わりました。
※ 2019/06/20から Raspbian OSは Raspbian Stretchから Raspbian Busterに変わりました。
Download Raspbian for Raspberry Pi
ちなみに、歴代のバージョンと名称は
Debian | コードネーム | 年月 | 備考 | (参考)Ubuntuでの該当名称 |
Debian 11 | Bullseye | 2021/08/14~ | 2021/11からラズパイにリリース | Focal Fossa 20.04 LTS ? |
Debian 10 | Buster | 2019/06/20~ | 2019/06からラズパイ4対応 | Bionic 18.04 LTS |
Debian 9 | Stretch | 2017/08/16~ | 2018/03からラズパイ3B+対応 | Xenial 16.04 LTS |
Debian 8 | Jessie | 2015~ | 2016/02からラズパイ3対応 | Trusty 14.04 LTS |
Debian 7 | Wheezy | 2013~2016 | | |
Debian 6.0 | Squeeze | 2011~2014 | | |
Debian GNU/Linux 5.0 | Lenny | 2009~2012 | | |
● Raspberry Pi 3で ENC28J60 LANモジュールを動かしてみた
※ Raspberry Pi Zeroでも同じ手順で動きます。
ENC28J60 - Interface and Networking - Ethernet Controllers - Microchip
SPI I/Fを有効にします。
sudo raspi-configか dtparam=spi=onで有効にします。
/boot/config.txtに dtparam=spi=onと dtoverlay=enc28j60を追加します。
再起動して ifconfigで eth1が増えている事を確認します。
※ Raspberry Pi Zeroの場合は eth0かも。
/boot/config.txt
dtoverlay=enc28j60
sudo reboot
ifconfig
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.3.111 netmask 255.255.255.0 broadcast 192.168.3.255
inet6 fe80::bca:1234:1234:1234 prefixlen 64 scopeid 0x20<link>
ether de:0c:66:11:22:33 txqueuelen 1000 (Ethernet)
RX packets 44 bytes 9253 (9.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 33 bytes 4844 (4.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 191
● Raspberry Pi 3と ENC28J60 LANモジュールの接続図
・Raspberry Piと ENC28J60 LANモジュールの接続図
※ Raspberry Pi Zeroでも同じ接続方法で動きます。
※ ENC28J60 LANモジュールの「ネジ穴無し版」と「ネジ穴有り版」とは端子の配列が微妙に異なります。基板上のシルクに端子名が印刷されているのでそれを確認します。
※ 配線は 7本で、「CLK」「WCL」「RST」の 3個は未使用なので配線しません。
結線方法は下記の様に 7本使用してそれぞれ接続します。
(1) ENC28J60 LANモジュールの GNDを ラズパイの GPIOの GND (GND)(茶色)
(2) ENC28J60 LANモジュールの VCCを ラズパイの GPIOの +3.3V(3V3)(赤色)
(3) ENC28J60 LANモジュールの CS を ラズパイの GPIOの CE0 (GPIO8)(オレンジ色)
(4) ENC28J60 LANモジュールの SDIを ラズパイの GPIOの MOSI(GPIO10)(黄色)
(5) ENC28J60 LANモジュールの SCKを ラズパイの GPIOの SCLK(GPIO11)(緑色)
(6) ENC28J60 LANモジュールの SDOを ラズパイの GPIOの MISO(GPIO9) (青色)
(7) ENC28J60 LANモジュールの INTを ラズパイの GPIOの GPIO25(GPIO25)(紫色)
・ENC28J60 LANモジュール

・Raspberry Piと ENC28J60 LANモジュールの接続

・Raspberry Piと ENC28J60 LANモジュールの接続

● ENC28J60の SPIの最大動作周波数は 20MHzなので、ちょっと加減して 19.2MHzにします。
# SPI Interface with Clock Speeds up to 20 MHz
# speed=19200000 = SPI 19.2MHz
dtoverlay=enc28j60:int_pin=25,speed=19200000
Windowsパソコンから pingの試験
> ping 192.168.3.111
Pinging 192.168.3.111 with 32 bytes of data:
Reply from 192.168.3.111: bytes=32 time<1ms TTL=64
Reply from 192.168.3.111: bytes=32 time<1ms TTL=64
Reply from 192.168.3.111: bytes=32 time<1ms TTL=64
Reply from 192.168.3.111: bytes=32 time<1ms TTL=64
Ping statistics for 192.168.3.111:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
● ENC28J60の通信速度のベンチマーク speedtest-cli
sudo apt-get install python-pip
sudo easy_install speedtest-cli
speedtest-cli
pi@raspberrypi:~ $ speedtest-cli
Retrieving speedtest.net configuration...
Testing from XXXX (xxx.xxx.xxx.xxx)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by Allied Telesis Capital Corporation (Fussa-shi) [38.13 km]: 45.174 ms
Testing download speed................................................................................
Download: 6.07 Mbit/s
Testing upload speed.........
.......................................................................................
Upload: 4.07 Mbit/s
pi@raspberrypi:~ $ speedtest-cli
Retrieving speedtest.net configuration...
Testing from XXXX (xxx.xxx.xxx.xxx)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by IPA CyberLab (Bunkyo) [2.57 km]: 37.636 ms
Testing download speed................................................................................
Download: 5.97 Mbit/s
Testing upload speed................................................................................................
Upload: 4.17 Mbit/s
pi@raspberrypi:~ $ speedtest-cli
Retrieving speedtest.net configuration...
Testing from XXXX (xxx.xxx.xxx.xxx)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by OPEN Project with 20G SINET (Tokyo) [5.41 km]: 45.608 ms
Testing download speed................................................................................
Download: 6.22 Mbit/s
Testing upload speed................................................................................................
Upload: 4.20 Mbit/s
pi@raspberrypi:~ $ speedtest-cli --version
1.0.7
pi@raspberrypi:~ $ speedtest-cli
usage: speedtest-cli [-h] [--no-download] [--no-upload] [--bytes] [--share]
[--simple] [--csv] [--csv-delimiter CSV_DELIMITER]
[--csv-header] [--json] [--list] [--server SERVER]
[--mini MINI] [--source SOURCE] [--timeout TIMEOUT]
[--secure] [--no-pre-allocate] [--version]
pi@raspberrypi:~ $ speedtest-cli -h
usage: speedtest-cli [-h] [--no-download] [--no-upload] [--bytes] [--share]
[--simple] [--csv] [--csv-delimiter CSV_DELIMITER]
[--csv-header] [--json] [--list] [--server SERVER]
[--mini MINI] [--source SOURCE] [--timeout TIMEOUT]
[--secure] [--no-pre-allocate] [--version]
Command line interface for testing internet bandwidth using speedtest.net.
--------------------------------------------------------------------------
https://github.com/sivel/speedtest-cli
optional arguments:
-h, --help show this help message and exit
--no-download Do not perform download test
--no-upload Do not perform upload test
--bytes Display values in bytes instead of bits. Does not
affect the image generated by --share, nor output from
--json or --csv
--share Generate and provide a URL to the speedtest.net share
results image, not displayed with --csv
--simple Suppress verbose output, only show basic information
--csv Suppress verbose output, only show basic information
in CSV format. Speeds listed in bit/s and not affected
by --bytes
--csv-delimiter CSV_DELIMITER
Single character delimiter to use in CSV output.
Default ","
--csv-header Print CSV headers
--json Suppress verbose output, only show basic information
in JSON format. Speeds listed in bit/s and not
affected by --bytes
--list Display a list of speedtest.net servers sorted by
distance
--server SERVER Specify a server ID to test against
--mini MINI URL of the Speedtest Mini server
--source SOURCE Source IP address to bind to
--timeout TIMEOUT HTTP timeout in seconds. Default 10
--secure Use HTTPS instead of HTTP when communicating with
speedtest.net operated servers
--no-pre-allocate Do not pre allocate upload data. Pre allocation is
enabled by default to improve upload performance. To
support systems with insufficient memory, use this
option to avoid a MemoryError
--version Show the version number and exit
● ENC28J60 LANモジュール
※ ENC28J60 LANモジュールの「ネジ穴無し版」と「ネジ穴有り版」とは端子の配列が微妙に異なります。基板上のシルクに端子名が印刷されているのでそれを確認します。
● Raspberry Pi 3、Raspberry Pi Zero Wの Bluetoothを無効にする
raspberrypi/linux - linux/arch/arm/boot/dts/overlays/pi3-disable-bt-overlay.dts
dtoverlay=pi3-disable-bt
/dts-v1/;
/plugin/;
/* Disable Bluetooth and restore UART0/ttyAMA0 over GPIOs 14 & 15.
To disable the systemd service that initialises the modem so it doesn't use
the UART:
sudo systemctl disable hciuart
*/
/{
compatible = "brcm,bcm2708";
fragment@0 {
target = <&uart1>;
__overlay__ {
status = "disabled";
};
};
fragment@1 {
target = <&uart0>;
__overlay__ {
pinctrl-names = "default";
pinctrl-0 = <&uart0_pins>;
status = "okay";
};
};
fragment@2 {
target = <&uart0_pins>;
__overlay__ {
brcm,pins;
brcm,function;
brcm,pull;
};
};
fragment@3 {
target-path = "/aliases";
__overlay__ {
serial0 = "/soc/serial@7e201000";
serial1 = "/soc/serial@7e215040";
};
};
};
Tags: [Raspberry Pi], [電子工作]
●関連するコンテンツ(この記事を読んだ人は、次の記事も読んでいます)
FWinSdCardImager SDカード イメージ書き込みアプリ、ラズパイの Raspbian OS、Jetson Nanoの Ubuntuの書き込みに便利
ラズパイや Jetson Nano等のワンボードマイコン等への OSイメージの書き込みが簡単にできる
FWinPiFinder ラズベリーパイ IPアドレス発見アプリ。ARPコマンドでラズパイの IPアドレスを探索発見する
Raspberry Piや NVIDIA Jetson Nano等の IPアドレスを MACアドレスの OUI部分を使用して発見する
Raspberry Pi 3系のトラブルであるある第一位の電源トラブル、低電圧警報に関する情報のまとめ
ラズパイ3B系での低電圧警報に関する情報まとめ、コマンドラインやログファイルから低電圧を検知する方法
Raspberry Piで CPUの脆弱性 Spectreと Meltdownの脆弱性をチェックする方法
ラズパイで 2018年初頭に大騒ぎになったスペクターとメルトダウンの CPUの脆弱性をチェックする方法
Raspberry Pi Zero Wを海外通販の Pimoroni等での購入方法、購入できる通販ショップ一覧まとめ
ラズパイゼロW ワイヤレスモデルを海外通販でサクッと簡単に個人輸入で入手。技適通過でも国内販売は常に品切れ
Raspberry Pi 3で安定して使える相性の無い最適な microSDカードの種類のまとめ
ラズパイ3で安定して使える microSDカードを購入する Teamと SanDiskは絶対に買わない
Raspberry Pi 3 Model Bに専用カメラモジュール RaspiCamを接続する方法
ラズパイに専用カメラモジュールを接続して Raspbianで写真の静止画撮影や動画を録画する方法
Raspberry Pi 3の Linuxコンソール上で使用する各種コマンドまとめ
ラズパイの Raspbian OSのコマンドラインで使用する便利コマンド、負荷試験や CPUシリアル番号の確認方法等も
Raspberry Pi 3公式フォーラムの FAQの内容の日本語訳
ラズパイ公式フォーラムの「The Raspberry Pi 3 Model B Q&A thread」の日本語訳
Raspberry Pi 3で GPIO端子の I2C機能を有効化する方法
ラズパイ3の GPIO端子の I2C機能を有効にして各種センサーを繋げる方法まとめ
大人気の CPUボード、Raspberry Pi 3 Model Bで作ってみよう
Raspberry Piの開発環境の構築やタッチパネル付き液晶ディスプレイや各種センサーの使い方まとめ
Raspberry Pi関連はこちらへまとめました
下記以外にも多数のラズパイ関係の記事が有ります。
(I2C制御、GPIO制御、1-Wire制御、シリアル通信、日本語音声合成、日本語音声認識、中国語音声合成、MeCab 形態素解析エンジン、赤外線リモコン制御、秋月 I2C液晶モジュール、KeDei 3.5インチ液晶、HDMI 5インチ液晶、NFCカードリーダ、コマンドライン操作方法等)
Espressif ESP8266 Arduino互換でスケッチが使える ESP-12Eモジュール基板
Espressif ESP8266 ESP-12-E NodeMCU V1 ESP12 CP2102
BangGood通販はドローン以外にも面白い商品がまだまだ有った(電子工作編)
レーザー彫刻機、カラー液晶の DIYオシロ、Arduinoや Raspberry Pi用の小型カラー液晶
[HOME]
|
[BACK]
リンクフリー(連絡不要、ただしトップページ以外は Web構成の変更で移動する場合があります)
Copyright (c)
2017 FREE WING,Y.Sakamoto
Powered by 猫屋敷工房 & HTML Generator
http://www.neko.ne.jp/~freewing/raspberry_pi/raspberry_pi_spi_enc28j60_ether_net_lan_module/