在本篇文章中,我們將學(xué)習(xí)如何將ENC28J60以太網(wǎng)模塊與Arduino Web服務(wù)器進(jìn)行連接,以在LAN局域網(wǎng)或無線網(wǎng)絡(luò)中的計算機與Arduino之間建立通信。我們將ENC28J60以太網(wǎng)控制器與Arduino連接,以便我們的Arduino成為該網(wǎng)絡(luò)的成員之一。一旦完成,arduino可以控制該網(wǎng)絡(luò)中的事物,或者arduino可以由該網(wǎng)絡(luò)的其他設(shè)備控制。 ENC28J60以太網(wǎng)模塊與Arduino的連接將進(jìn)一步為我們提供在Arduino上自由使用互聯(lián)網(wǎng)。
ENC28J60以太網(wǎng)模塊簡介
ENC28J60以太網(wǎng)模塊使用Microchip ENC28J60獨立式以太網(wǎng)控制器IC,具有許多功能,可滿足大多數(shù)網(wǎng)絡(luò)協(xié)議要求。該板通過標(biāo)準(zhǔn)SPI接口直接連接到大多數(shù)微控制器,傳輸速度高達(dá)20MHz。
該以太網(wǎng)網(wǎng)模塊是向基于微控制器的產(chǎn)品和項目添加LAN連接的最簡單方法。
1.使用此模塊為您的產(chǎn)品啟用以太網(wǎng)接口。它可與任何工作于3. 3V或5V的微控制器一起使用。
2.該模塊工作在3.3V電壓下,并與5V接口兼容。
3.使用SPI進(jìn)程與其他連接。
4.托管Web服務(wù)器,對模塊執(zhí)行ping操作或通過Internet將其添加到家庭自動化中。
5.該模塊的核心是Microchip的ENC28J60以太網(wǎng)控制器。
6.使用集成磁性裝置的RJ45網(wǎng)口可以減小電路板的尺寸。
框圖和連接方式:
以下是一個簡單的框圖,介紹了Arduino和ENC28J60模塊如何與路由器和計算機連接。
路由器應(yīng)與LAN連接,并應(yīng)具有多個輸入輸出端口。從路由器將一根以太網(wǎng)電纜連接到計算機系統(tǒng),將另一根以太網(wǎng)電纜連接到ENC28J60模塊。同樣,ENC28J60模塊連接到Arduino。 Arduino和ENC28J60之間的連接如下。
如何將ENC28J60以太網(wǎng)模塊與Arduino Web服務(wù)器連接:
1.從此處下載ENC28J60庫:ENC28J60庫
2.將庫文件添加到您的Arduino IDE庫中:
3.添加完成后,打開示例,然后從 Master Library中選擇以下示例:
4.編譯代碼,然后將代碼上傳到Arduino UNO開發(fā)板:
5.打開串口監(jiān)視器并復(fù)制IP地址:
6. 打開網(wǎng)絡(luò)瀏覽器并粘貼IP地址,然后按下Enter:
Arduino連接ENC28J60以太網(wǎng)模塊的示例代碼:
#include
#define STATIC 0 // set to 1 to disable DHCP (adjust myip/gwip values below)
#if STATIC
// ethernet interface ip address
static byte myip[] = { 192,168,1,200 };
// gateway ip address
static byte gwip[] = { 192,168,1,1 };
#endif
// ethernet mac address - must be unique on your network
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
byte Ethernet::buffer[500]; // tcp/ip send and receive buffer
const char page[] PROGMEM =
"HTTP/1.0 503 Service Unavailable "
"Content-Type: text/html "
"Retry-After: 600 "
" "
""
"
"Service Temporarily Unavailable"
"
"
""
This service is currently unavailable
""
"
"The main server is currently off-line.
"
"Please try again later."
"
"""
""
;
void setup(){
Serial.begin(57600);
Serial.println(" [backSoon]");
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");
#if STATIC
ether.staticSetup(myip, gwip);
#else
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
#endif
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
}
void loop(){
// wait for an incoming TCP packet, but ignore its contents
if (ether.packetLoop(ether.packetReceive())) {
memcpy_P(ether.tcpOffset(), page, sizeof page);
ether.httpServerReply(sizeof page - 1);
}
}
編輯:hfy
-
以太網(wǎng)
+關(guān)注
關(guān)注
40文章
5463瀏覽量
172800 -
ENC28J60
+關(guān)注
關(guān)注
0文章
35瀏覽量
21655 -
Arduino
+關(guān)注
關(guān)注
188文章
6477瀏覽量
187917 -
控制器IC
+關(guān)注
關(guān)注
0文章
19瀏覽量
5861
發(fā)布評論請先 登錄
相關(guān)推薦
交換機與以太網(wǎng)怎么連接
TOSUN 車載以太網(wǎng)仿真測試解決方案
![TOSUN 車載<b class='flag-5'>以太網(wǎng)</b>仿真測試解決<b class='flag-5'>方案</b>](https://file.elecfans.com/web2/M00/40/07/pYYBAGJrUk2AaMaTAAAQONQtdzo461.jpg)
英偉達(dá)邁絡(luò)思以太網(wǎng)光模塊的介紹和型號梳理
![英偉達(dá)邁絡(luò)思<b class='flag-5'>以太網(wǎng)</b>光<b class='flag-5'>模塊</b>的<b class='flag-5'>介紹</b>和型號梳理](https://file1.elecfans.com/web1/M00/F5/C1/wKgZoWdD9hKAJrD0AAT6YvKyRAE921.jpg)
怎么檢查CAN以太網(wǎng)模塊的物理連接
以太網(wǎng)端口支持哪些類型的設(shè)備和連接方式
MX60千兆以太網(wǎng)非接觸式連接解決方案
以太網(wǎng)要怎么連接
![](https://file1.elecfans.com/web2/M00/EA/91/wKgZomZZNV6ABmUHAALQaX4H-ZI635.jpg)
車載以太網(wǎng)硬件接口VN5620設(shè)備展示與介紹#車載以太網(wǎng)
![](https://file1.elecfans.com/web2/M00/E5/38/wKgaomY_QQqANHQTAADb2CrD2i8864.jpg)
請問ENC28J60不使用TCPIP協(xié)議可否使用?
集成與創(chuàng)新:瑞薩工業(yè)以太網(wǎng)單芯片解決方案
![集成與創(chuàng)新:瑞薩工業(yè)<b class='flag-5'>以太網(wǎng)</b>單芯片解決<b class='flag-5'>方案</b>](https://file1.elecfans.com/web2/M00/C8/B5/wKgZomYeFh6ABy-_AAA15xD9oAU471.png)
PLC以太網(wǎng)通訊模塊是什么?PLC以太網(wǎng)通訊模塊的功能特點
數(shù)據(jù)中心市場的關(guān)鍵以太網(wǎng)解決方案
![數(shù)據(jù)中心市場的關(guān)鍵<b class='flag-5'>以太網(wǎng)</b>解決<b class='flag-5'>方案</b>](https://file1.elecfans.com/web2/M00/C3/E8/wKgZomXvtjaAZOBeAAAPIepkkZs521.jpg)
以太網(wǎng)怎么連接 以太網(wǎng)組網(wǎng)結(jié)構(gòu)分析
![<b class='flag-5'>以太網(wǎng)</b>怎么<b class='flag-5'>連接</b> <b class='flag-5'>以太網(wǎng)</b>組網(wǎng)結(jié)構(gòu)分析](https://file1.elecfans.com/web2/M00/C3/63/wKgZomXq2GeAQOWPAABCZuM0CiY485.png)
評論