| 1 | = WIZ820ioをつかってみました = |
| 2 | |
| 3 | == 内容 == |
| 4 | 春先にWIZ820ioのお試しキャンペーンをさせていただきました。[[BR]] |
| 5 | 遅まきながら、ご応募いただいた方のブログなどを参考に、WIZ820ioを使ってみましたので、ご紹介いたします。[[BR]] |
| 6 | ちなみにArduino IDE 1.0.1を使いました。 |
| 7 | |
| 8 | == 使用部品など == |
| 9 | |
| 10 | * [http://www.switch-science.com/products/detail.php?product_id=875 WIZ820io] |
| 11 | * [http://www.switch-science.com/products/detail.php?product_id=789 Arduino Uno] |
| 12 | * [http://www.switch-science.com/products/detail.php?product_id=25 普通のブレッドボード] |
| 13 | * [http://www.switch-science.com/products/detail.php?product_id=620 普通のジャンパワイヤ(オス~オス)] |
| 14 | * 5Vから3.3Vに変換する回路[[BR]] |
| 15 | 今回は[http://www.switch-science.com/products/detail.php?product_id=25 SparkFunブレッドボード用電源ボードUSB版(キット)]を使ってみました。 |
| 16 | その他、USBケーブルやら、LANケーブルやら、ネットワークハブやら適宜ご用意ください。 |
| 17 | |
| 18 | == 配線 == |
| 19 | Arduino Uno ⇔ WIZ820io |
| 20 | * D10 → nSS |
| 21 | * D11 → MOSI |
| 22 | * D12 ← MISO |
| 23 | * D13 → SCLK |
| 24 | * RESET → nRESET |
| 25 | * GND ⇔ GND |
| 26 | * 5V→「5V→3.3V変換」→VIN3.3 |
| 27 | |
| 28 | Arduino Unoにも3.3V出力がありますが、WIZ820ioの最大消費電流120mAには足りないので、5Vから3.3Vを作っています。 |
| 29 | |
| 30 | == 写真 == |
| 31 | |
| 32 | 後で入れます。 |
| 33 | |
| 34 | == ライブラリのダウンロード == |
| 35 | WIZnetさんの[http://www.wiznettechnology.com/Sub_Modules/en/product/product_detail.asp?Refid=491&page=1&cate1=&cate2=&cate3=&pid=1161&cType=2 ダウンロードページ]から「Library for Arduino + Ethernet」をダウンロードしてください。[[BR]] |
| 36 | その中のw5100.hとw5100.cppを、Arduino IDEのフォルダのlibraries/Ethernet/utility/の中にある同名ファイルと差し替えてください。[[BR]] |
| 37 | さらに、Arduino IDEのフォルダのlibraries/Ethernet/のEthernet.hを以下の様に書き換えます。 |
| 38 | |
| 39 | {{{ |
| 40 | #!c |
| 41 | #ifndef ethernet_h |
| 42 | #define ethernet_h |
| 43 | |
| 44 | #include <inttypes.h> |
| 45 | #include "utility/w5100.h" // ←変更行 w5100.hを有効にします |
| 46 | #include "IPAddress.h" |
| 47 | #include "EthernetClient.h" |
| 48 | #include "EthernetServer.h" |
| 49 | #include "Dhcp.h" |
| 50 | |
| 51 | // #define MAX_SOCK_NUM 4 // ←変更行 この行を無効にします |
| 52 | |
| 53 | class EthernetClass { |
| 54 | private: |
| 55 | IPAddress _dnsServerAddress; |
| 56 | DhcpClass* _dhcp; |
| 57 | public: |
| 58 | static uint8_t _state[MAX_SOCK_NUM]; |
| 59 | static uint16_t _server_port[MAX_SOCK_NUM]; |
| 60 | // Initialise the Ethernet shield to use the provided MAC address and gain the rest of the |
| 61 | // configuration through DHCP. |
| 62 | // Returns 0 if the DHCP configuration failed, and 1 if it succeeded |
| 63 | int begin(uint8_t *mac_address); |
| 64 | void begin(uint8_t *mac_address, IPAddress local_ip); |
| 65 | void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server); |
| 66 | void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway); |
| 67 | void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet); |
| 68 | int maintain(); |
| 69 | |
| 70 | IPAddress localIP(); |
| 71 | IPAddress subnetMask(); |
| 72 | IPAddress gatewayIP(); |
| 73 | IPAddress dnsServerIP(); |
| 74 | |
| 75 | friend class EthernetClient; |
| 76 | friend class EthernetServer; |
| 77 | }; |
| 78 | |
| 79 | extern EthernetClass Ethernet; |
| 80 | |
| 81 | #endif |
| 82 | }}} |
| 83 | |
| 84 | == テスト == |
| 85 | Arduino IDEを立ち上げて、ファイル→スケッチの例→Ethernet→WebServerをクリック。 |
| 86 | 出てきたスケッチの |
| 87 | {{{ |
| 88 | #!c |
| 89 | byte mac[] = { |
| 90 | 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; |
| 91 | IPAddress ip(192,168,1, 177); |
| 92 | }}} |
| 93 | この部分を適宜書き換えてArduino Unoにアップロードします。 |
| 94 | パソコンのブラウザで、書き込んだIPアドレスにアクセスします。 |
| 95 | ブラウザにA0~A5の読み取り値が表示されればOKです。 |
| 96 | |
| 97 | == 補足 == |
| 98 | このままだとEthernetライブラリがW5200を使ったモジュールにしか対応しません。[[BR]] |
| 99 | 従来のW5100を使ったモジュール([http://www.switch-science.com/products/detail.php?product_id=838 Arduino イーサネットシールド R3])等を使ってスケッチをコンパイルする時は、事前に |
| 100 | Arduino IDEのフォルダのlibraries/Ethernet/utility/のw5100.hを開いて |
| 101 | {{{ |
| 102 | #!C |
| 103 | #define W5200 |
| 104 | }}} |
| 105 | の行の頭に // を付けてコメントにしてください。 |
| 106 | 差し替えたファイルを元に戻す必要はありません。 |
| 107 | |
| 108 | |
| 109 | == 謝辞 == |
| 110 | [http://trac.switch-science.com/wiki/2012-WIZ820io キャンペーン]にご応募いただた |
| 111 | @ytsuboi さま、@misodengaku さま、Nasupl さま、shigehiro さま、@a_ono さま、まつばば さま |
| 112 | 参考にさせていただきました。ありがとうございました。 |
| 113 | |