LoginSignup
2
2

More than 5 years have passed since last update.

arduinoでethernet

Last updated at Posted at 2015-08-29

オークションで手に入れたenc28j60をarduino unoにつないで見ました。

写真

MVC-007S.JPG

回路図

enc2.PNG

ハイパーターミナル

enc.PNG

サンプルコード

#include "EtherCard.h"

static byte mymac[] = {
    0x74,
    0x69,
    0x69,
    0x2D,
    0x30,
    0x31
};
byte Ethernet::buffer[700];
static uint32_t timer;
const char website[] PROGMEM = "tanista.dip.jp";
static void my_callback(byte status, word off, word len)
{
    Serial.println(">>>");
    Ethernet::buffer[off + 300] = 0;
    Serial.print((const char *) Ethernet::buffer + off);
    Serial.println("...");
}
void setup()
{
    Serial.begin(9600);
    Serial.println(F("\n[webClient]"));
    if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) Serial.println(F("Failed to access Ethernet controller"));
    if (!ether.dhcpSetup()) Serial.println(F("DHCP failed"));
    ether.printIp("IP: ", ether.myip);
    ether.printIp("GW: ", ether.gwip);
    ether.printIp("DNS: ", ether.dnsip);
    if (!ether.dnsLookup(website)) Serial.println("DNS failed");
    ether.printIp("SRV: ", ether.hisip);
}
void loop()
{
    ether.packetLoop(ether.packetReceive());
    if (millis() > timer)
    {
        timer = millis() + 50000;
        Serial.println();
        Serial.print("<<< REQ ");
        ether.browseUrl(PSTR("/"), "", website, my_callback);
    }
}

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2