Arduino/ArduinoInAction.Chap8
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]
開始行:
[[FrontPage]]
#contents
2013/05/26からのアクセス回数 &counter;
8章は、EthernetとBluetooth等の接続を扱っていますが、ここ...
*** Ethernetライブラリのカスタマイズ [#sf8d22e0]
もっとも簡単にArduinoをイーサネットに接続するなら、イーサ...
他のCPUボードでもイーサネットに接続テストをしてみたいので...
[[WIZ820io>http://www.switch-science.com/catalog/875/]]
を購入しました。
イーサネットシールドでは、W5100というICを使っているのです...
若干の変更が必要です。
Mac OSXの場合で説明します。
+ Arduinoアプリケーションを右クリックして、「パッケージの...
+ Contents/Resources/Java/libraries/Ethernetをコピーし、
+ ユーザのホームページ/Documents/Arduinoにlibraries以下に...
+ WIZnetの
[[WIZ820io>http://www.wiznettechnology.com/Sub_Modules/en...
から、Library for Arduino + Ethernet(IDE ver1.0)をダウン...
+ ZIPファイルを解凍し、library_Arduino_v1_0ディレクトリの...
カスタマイズしたEthernetライブラリを使用する場合には、ス...
*** 配線 [#y5144579]
WIZ820ioは、3.3Vで動くのですが、WIZ820ioの最大消費電流120...
(([[WIZ820ioをつかってみました>http://trac.switch-science...
5Vから3.3Vへの変換は、秋月の
[[TA48M033F>http://akizukidenshi.com/catalog/g/gI-00538/]]
を使いました。
ArduinoとWIZ820ioの接続は、以下の様にします。
- D10 → nSS
- D11 → MOSI
- D12 ← MISO
- D13 → SCLK
- RESET → nRESET
- GND ⇔ GND
&ref(WIZ820_pin.png);
作成したブレッドボードは以下のようになります。
&ref(Bread_WIZ820io.png);
*** スケッチと動作確認 [#xccc6369]
スケッチは、EthernetのDhcpAdressPrinterの例題を修正して使...
残念ながら、この例題はATmega32U4ボードでは動きませんでし...
この例題は特にサーバのプログラムを作らなくても動作を確認...
#pre{{
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>
#include <util.h>
#include <SPI.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a...
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HT...
EthernetClient client;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) {
; // wait for serial port to connect. Needed for Leon...
}
Serial.println("Start Test");
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DH...
// no point in carrying on, so do nothing forevermore:
for(;;)
;
}
// print your local IP address:
Serial.print("My IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println();
Serial.println("End Test");
}
void loop() {
}
}}
実行するとシリアルモニタに以下の様に取得したアドレスが表...
#pre{{
Start Test
My IP address: 192.168.1.109.
End Test
}}
** Webサーバへのアクセス [#qc94c7fa]
次にWebサーバへのアクセスをテストします。
Arduinoの例題にあるWebClientは、googleのサーバにアクセス...
現在はGoogleサーバが接続を制限しており、そのままでは動き...
そこで、私の借りている「さくらVPSサーバ」上のSageサーバに...
- SageサーバのIPアドレスは、49.212.164.205
- ポート番号は、8000
です。
スケッチは、以下の様に修正しました。
#pre{{
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>
#include <util.h>
#include <SPI.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a...
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
IPAddress server(49,212,164,205); // Sage Server
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HT...
EthernetClient client;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leon...
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DH...
// no point in carrying on, so do nothing forevermore:
for(;;)
;
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, 8000)) {
Serial.println("connected");
// Make a HTTP request:
// client.println("GET /search?q=arduino HTTP/1.0");
client.println("GET / HTTP/1.0");
client.println();
}
else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
for(;;)
;
}
}
}}
実行するとシリアルモニタに以下の様にSageサーバからのレス...
#pre{{
connecting...
connected
HTTP/1.1 200 OK
Content-Length: 3626
Set-Cookie: cookie_test_8000=cookie_test
Accept-Ranges: bytes
Server: Twisted/9.0.0 TwistedWeb/[twisted.web2, version 8...
Date: Sun, 26 May 2013 01:46:27 GMT
Content-Type: text/html; charset=utf-8
Connection: close
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/htm...
<title>Sign in -- Sage</title>
<link type="text/css" rel="stylesheet" href="/css...
<script type="text/javascript" src="/javascript/j...
<script type="text/javascript" src="/javascript/s...
以下省略
}}
ArduinoのEthernetClientを使うと非常に簡単にWebサーバに接...
** コメント [#lc885b54]
#vote(おもしろかった[3],そうでもない[0],わかりずらい[0])
皆様のご意見、ご希望をお待ちしております。
#comment_kcaptcha
終了行:
[[FrontPage]]
#contents
2013/05/26からのアクセス回数 &counter;
8章は、EthernetとBluetooth等の接続を扱っていますが、ここ...
*** Ethernetライブラリのカスタマイズ [#sf8d22e0]
もっとも簡単にArduinoをイーサネットに接続するなら、イーサ...
他のCPUボードでもイーサネットに接続テストをしてみたいので...
[[WIZ820io>http://www.switch-science.com/catalog/875/]]
を購入しました。
イーサネットシールドでは、W5100というICを使っているのです...
若干の変更が必要です。
Mac OSXの場合で説明します。
+ Arduinoアプリケーションを右クリックして、「パッケージの...
+ Contents/Resources/Java/libraries/Ethernetをコピーし、
+ ユーザのホームページ/Documents/Arduinoにlibraries以下に...
+ WIZnetの
[[WIZ820io>http://www.wiznettechnology.com/Sub_Modules/en...
から、Library for Arduino + Ethernet(IDE ver1.0)をダウン...
+ ZIPファイルを解凍し、library_Arduino_v1_0ディレクトリの...
カスタマイズしたEthernetライブラリを使用する場合には、ス...
*** 配線 [#y5144579]
WIZ820ioは、3.3Vで動くのですが、WIZ820ioの最大消費電流120...
(([[WIZ820ioをつかってみました>http://trac.switch-science...
5Vから3.3Vへの変換は、秋月の
[[TA48M033F>http://akizukidenshi.com/catalog/g/gI-00538/]]
を使いました。
ArduinoとWIZ820ioの接続は、以下の様にします。
- D10 → nSS
- D11 → MOSI
- D12 ← MISO
- D13 → SCLK
- RESET → nRESET
- GND ⇔ GND
&ref(WIZ820_pin.png);
作成したブレッドボードは以下のようになります。
&ref(Bread_WIZ820io.png);
*** スケッチと動作確認 [#xccc6369]
スケッチは、EthernetのDhcpAdressPrinterの例題を修正して使...
残念ながら、この例題はATmega32U4ボードでは動きませんでし...
この例題は特にサーバのプログラムを作らなくても動作を確認...
#pre{{
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>
#include <util.h>
#include <SPI.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a...
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HT...
EthernetClient client;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) {
; // wait for serial port to connect. Needed for Leon...
}
Serial.println("Start Test");
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DH...
// no point in carrying on, so do nothing forevermore:
for(;;)
;
}
// print your local IP address:
Serial.print("My IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println();
Serial.println("End Test");
}
void loop() {
}
}}
実行するとシリアルモニタに以下の様に取得したアドレスが表...
#pre{{
Start Test
My IP address: 192.168.1.109.
End Test
}}
** Webサーバへのアクセス [#qc94c7fa]
次にWebサーバへのアクセスをテストします。
Arduinoの例題にあるWebClientは、googleのサーバにアクセス...
現在はGoogleサーバが接続を制限しており、そのままでは動き...
そこで、私の借りている「さくらVPSサーバ」上のSageサーバに...
- SageサーバのIPアドレスは、49.212.164.205
- ポート番号は、8000
です。
スケッチは、以下の様に修正しました。
#pre{{
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>
#include <util.h>
#include <SPI.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a...
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
IPAddress server(49,212,164,205); // Sage Server
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HT...
EthernetClient client;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leon...
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DH...
// no point in carrying on, so do nothing forevermore:
for(;;)
;
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, 8000)) {
Serial.println("connected");
// Make a HTTP request:
// client.println("GET /search?q=arduino HTTP/1.0");
client.println("GET / HTTP/1.0");
client.println();
}
else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
for(;;)
;
}
}
}}
実行するとシリアルモニタに以下の様にSageサーバからのレス...
#pre{{
connecting...
connected
HTTP/1.1 200 OK
Content-Length: 3626
Set-Cookie: cookie_test_8000=cookie_test
Accept-Ranges: bytes
Server: Twisted/9.0.0 TwistedWeb/[twisted.web2, version 8...
Date: Sun, 26 May 2013 01:46:27 GMT
Content-Type: text/html; charset=utf-8
Connection: close
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/htm...
<title>Sign in -- Sage</title>
<link type="text/css" rel="stylesheet" href="/css...
<script type="text/javascript" src="/javascript/j...
<script type="text/javascript" src="/javascript/s...
以下省略
}}
ArduinoのEthernetClientを使うと非常に簡単にWebサーバに接...
** コメント [#lc885b54]
#vote(おもしろかった[3],そうでもない[0],わかりずらい[0])
皆様のご意見、ご希望をお待ちしております。
#comment_kcaptcha
ページ名:
SmartDoc