最終更新日:2023/3/10
インクルードするライブラリですが、Ethernet3を使用します。このライブラリは安定していると思います。
TM1637用のポートは確保します。
/* Web client This sketch connects to a website (http://www.google.com) using an Arduino Wiznet Ethernet shield. Circuit: * Ethernet shield attached to pins 10, 11, 12, 13 created 18 Dec 2009 by David A. Mellis modified 9 Apr 2012 by Tom Igoe, based on work by Adrian McEwen */ #include <SPI.h> #include <Ethernet3.h> // Enter a MAC address for your controller below. // Newer Ethernet shields have a MAC address printed on a sticker on the shield byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // if you don't want to use DNS (and reduce your sketch size) // use the numeric IP instead of the name for the server: //IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) char server[] = "www.google.com"; // name address for Google (using DNS) // Set the static IP address to use if the DHCP fails to assign IPAddress ip(192, 168, 0, 177); // 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 HTTP): 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 Leonardo only } // start the Ethernet connection: if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); // no point in carrying on, so do nothing forevermore: // try to congifure using IP address instead of DHCP: Ethernet.begin(mac, ip); } // 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, 80)) { Serial.println("connected"); // Make a HTTP request: client.println("GET /search?q=arduino HTTP/1.1"); client.println("Host: www.google.com"); client.println("Connection: close"); 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: while (true); } } |
|
/* * 2023/03/13 T.Wanibe * Web client * このスケッチは Web サイト (http://www.google.com) に接続します * W5500-EVB-PICOを使用します。 */ #include <SPI.h> #include <Ethernet3.h> #define SPI_SCK 18 #define SPI_RX 16 #define SPI_TX 19 #define SPI_CS 17 #define NICReset 20 #define HTTPport 80 #define TELNETport 23 #define SerialRate 115200 // コントローラの MAC アドレスと IP アドレスを以下に入力します。 // IP アドレスは、ローカル ネットワークによって異なります。 // ゲートウェイとサブネットはオプションです。 byte mac[] = {0x00,0x08,0xDC,0x54,0x4D,0xE0}; //WIZNET byte ip[] = {192, 168, 0, 210}; byte dns_server[] = {192, 168, 0, 1}; byte gateway[] = {0, 0, 0, 0}; byte subnet[] = {255, 255, 255, 0}; //IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) char server[] = "www.google.com"; // name address for Google (using DNS) int count = 0; // イーサネット サーバー ライブラリの初期化 // 使用する IP アドレスとポート(ポート 80 は HTTP のデフォルトです): EthernetClient client; //---------------- void setup() { pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, HIGH); // シリアル通信を開き、ポートが開くのを待ちます。 Serial.begin(SerialRate); while (!Serial) { ; // シリアルポートが接続されるのを待ちます。 } pinMode(SPI_CS,OUTPUT); pinMode(NICReset,OUTPUT); // イーサネット接続とサーバーを開始します。 SPI.setSCK(SPI_SCK); SPI.setRX(SPI_RX); SPI.setTX(SPI_TX); SPI.setCS(SPI_CS); SPI.begin(); // Ethernet.init(pin)を使用してCSピンを設定できます Ethernet.setCsPin(SPI_CS); Ethernet.setRstPin(NICReset); digitalWrite(NICReset,LOW); delay(10); digitalWrite(NICReset,HIGH); Ethernet.init(SPI_CS); // イーサネット デバイスを初期化する if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); //続行しても意味がないので、今後は何もしないでください: //DHCP の代わりに IP アドレスを使用して設定を試みます: Ethernet.begin(mac, ip); } // イーサネット シールドを初期化するために 1 秒待ちます。 delay(1000); Serial.println("connecting..."); Serial.print("server is at "); Serial.println(Ethernet.localIP()); // 接続が確立されたら、シリアル経由で報告します。 if (client.connect(server, HTTPport)) { Serial.println("connected"); // Make a HTTP request: client.println("GET /search?q=arduino HTTP/1.1"); client.println("Host: www.google.com"); client.println("Connection: close"); client.println(); } else { // kf you didn't get a connection to the server: Serial.println("connection failed"); } } //------------- void loop(){ delay(100); if(count++ % 2){ digitalWrite(LED_BUILTIN, HIGH); }else{ digitalWrite(LED_BUILTIN, LOW); } // サーバーから受信可能なバイトがある場合は、それらを読み取って出力します。 if (client.available()) { char c = client.read(); Serial.print(c); } // サーバーが切断されている場合は、クライアントを停止します。 if (!client.connected()) { Serial.println(); Serial.println("disconnecting."); client.stop(); // do nothing forevermore: while (true); } } |
本ソフトウエアは、あなたに対して何も保証しません。本ソフトウエアの関係者(他の利用者も含む)は、あなたに対して一切責任を負いません。
あなたが、本ソフトウエアを利用(コンパイル後の再利用など全てを含む)する場合は、自己責任で行う必要があります。本ソフトウエアの著作権はToolsBoxに帰属します。
本ソフトウエアをご利用の結果生じた損害について、ToolsBoxは一切責任を負いません。
ToolsBoxはコンテンツとして提供する全ての文章、画像等について、内容の合法性・正確性・安全性等、において最善の注意をし、作成していますが、保証するものではありません。
ToolsBoxはリンクをしている外部サイトについては、何ら保証しません。
ToolsBoxは事前の予告無く、本ソフトウエアの開発・提供を中止する可能性があります。
Microsoft、Windows、WindowsNTは米国Microsoft Corporationの米国およびその他の国における登録商標です。
Windows Vista、Windows XPは、米国Microsoft Corporation.の商品名称です。
LabVIEW、National Instruments、NI、ni.comはNational Instrumentsの登録商標です。
I2Cは、NXP Semiconductors社の登録商標です。
その他の企業名ならびに製品名は、それぞれの会社の商標もしくは登録商標です。
すべての商標および登録商標は、それぞれの所有者に帰属します。