{"id":328,"date":"2013-08-12T14:21:12","date_gmt":"2013-08-12T12:21:12","guid":{"rendered":"http:\/\/labalec.fr\/erwan\/?p=328"},"modified":"2014-05-09T23:04:06","modified_gmt":"2014-05-09T21:04:06","slug":"arduino-and-ethernet","status":"publish","type":"post","link":"https:\/\/labalec.fr\/erwan\/?p=328","title":{"rendered":"Arduino : use an ethernet controller (enc28j60)"},"content":{"rendered":"<p>Here below a quick how to use an arduino and a <a href=\"http:\/\/dx.com\/p\/149461\" target=\"_blank\">cheap enc28j60 ethernet module<\/a> (5\u20ac).<\/p>\n<p>Can be handy to built a quick web server and some sensors (like a ds18b20 for example).<\/p>\n<p>below the wiring :<\/p>\n<p><a href=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/08\/enc28j60_bb.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/08\/enc28j60_bb-279x300.png\" alt=\"enc28j60_bb\" width=\"279\" height=\"300\" class=\"alignnone size-medium wp-image-329\" srcset=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/08\/enc28j60_bb-279x300.png 279w, https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/08\/enc28j60_bb-953x1024.png 953w, https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/08\/enc28j60_bb.png 1467w\" sizes=\"auto, (max-width: 279px) 100vw, 279px\" \/><\/a><\/p>\n<p>below a sketch using the ethercard library (provided with Arduino GUI) :<\/p>\n<pre>\r\n\/\/ Present a \"Will be back soon web page\", as stand-in webserver.\r\n\/\/ 2011-01-30 <jc@wippler.nl> http:\/\/opensource.org\/licenses\/mit-license.php\r\n \r\n#include <EtherCard.h>\r\n\r\n#define STATIC 0  \/\/ set to 1 to disable DHCP (adjust myip\/gwip values below)\r\n\r\n#if STATIC\r\n\/\/ ethernet interface ip address\r\nstatic byte myip[] = { 192,168,1,200 };\r\n\/\/ gateway ip address\r\nstatic byte gwip[] = { 192,168,1,1 };\r\n#endif\r\n\r\n\/\/ ethernet mac address - must be unique on your network\r\nstatic byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };\r\n\r\nbyte Ethernet::buffer[500]; \/\/ tcp\/ip send and receive buffer\r\n\r\nchar page[] PROGMEM =\r\n\"HTTP\/1.0 200 OK\\r\\n\"\r\n\"Content-Type: text\/html\\r\\n\"\r\n\"Retry-After: 600\\r\\n\"\r\n\"\\r\\n\"\r\n\"<html>\"\r\n  \"<head><title>\"\r\n    \"my web page\"\r\n  \"<\/title><\/head>\"\r\n  \"<body>\"\r\n    \"<h3>hello world !<\/h3>\"\r\n  \"<\/body>\"\r\n\"<\/html>\"\r\n;\r\n\r\nvoid setup(){\r\n  Serial.begin(38400);\r\n  Serial.println(\"\\n[backSoon]\");\r\n  \r\n  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) \r\n    Serial.println( \"Failed to access Ethernet controller\");\r\n#if STATIC\r\n  ether.staticSetup(myip, gwip);\r\n#else\r\n  if (!ether.dhcpSetup())\r\n    Serial.println(\"DHCP failed\");\r\n#endif\r\n\r\n  ether.printIp(\"IP:  \", ether.myip);\r\n  ether.printIp(\"GW:  \", ether.gwip);  \r\n  ether.printIp(\"DNS: \", ether.dnsip);  \r\n}\r\n\r\nvoid loop(){\r\n  \/\/ wait for an incoming TCP packet, but ignore its contents\r\n  if (ether.packetLoop(ether.packetReceive())) {\r\n    memcpy_P(ether.tcpOffset(), page, sizeof page);\r\n    ether.httpServerReply(sizeof page - 1);\r\n  }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Here below a quick how to use an arduino and a cheap enc28j60 ethernet module (5\u20ac). Can be handy to built a quick web server and some sensors (like a ds18b20 for example). below the wiring : below a sketch using the ethercard library (provided with Arduino GUI) : \/\/ Present a \u00ab\u00a0Will be back <a href='https:\/\/labalec.fr\/erwan\/?p=328' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-328","post","type-post","status-publish","format-standard","hentry","category-arduino","category-18-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"_links":{"self":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/328","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=328"}],"version-history":[{"count":12,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/328\/revisions"}],"predecessor-version":[{"id":1216,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/328\/revisions\/1216"}],"wp:attachment":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=328"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=328"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=328"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}