arduino通过ENC28J60连接以太网

arduino通过ENC28J60连接以太网_第1张图片
**enc28j60**
  • 1 先把arduino 的IDE装好
  • 2 下载EtherCard库文件【下载地址】

EtherCard is a driver for the ENC28J60 chip, compatible with Arduino IDE. Adapted and extended from code written by Guido Socher and Pascal Stang.

EtherCard是ENC28J60芯片的一种驱动,与Arduino的开发环境兼容。项目借鉴并扩展了Guido Socher与Pascal Stang的代码。

  • 3 添加到Arduino IDE的开发库里面,重启Arduino程序就可以使用了


    arduino通过ENC28J60连接以太网_第2张图片
    操作方式如图
  • 4 连接arudino uno和enc28j60
PIN Connections (Using Arduino UNO):

VCC -   3.3V
GND -    GND
SCK - Pin 13
SO  - Pin 12
SI  - Pin 11
CS  - Pin  8 # Selectable with the ether.begin() function
arduino通过ENC28J60连接以太网_第3张图片
最终连线图
  • 5 设置一下本地网络以及arduino的网络,如果用192.168.1.0/24网段,最好把无线网先断了
// Present a "Will be back soon web page", as stand-in webserver.
// 2011-01-30  http://opensource.org/licenses/mit-license.php
 
#include 

#define STATIC 1  // 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\r\n"
"Content-Type: text/html\r\n"
"Retry-After: 600\r\n"
"\r\n"
""
  ""
    "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("\n[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); } }
arduino通过ENC28J60连接以太网_第4张图片
打开浏览器输入ip地址的效果

你可能感兴趣的:(arduino通过ENC28J60连接以太网)