这个库已经很久没人更新了,现在更新比较快的是ethercard库。目前最新最全的enc28j60的库,支持最新arduino ide。和原ethernet库不冲突。
参考一下张老师的《第二弹》?那里面做的比较成功
刚买的ENC28J60小卡,在新中发地下层,用EncEthernet库能用,但只有一个Examples中只有一个程序可试,成功,楼主这个一直未能成功。
JUST_DO_IT 发表于 2012-8-30 22:11 static/image/common/back.gif
我这个已经做成功,但想传到yeelink上面去,能帮我看看代码吗/*
* Web Server
*
http://geek-workshop.com/thread-1747-1-1.html
参考上面的帖子代码,是张老师做的硬件
JUST_DO_IT 发表于 2012-8-30 22:11 static/image/common/back.gif
我这个已经做成功,但想传到yeelink上面去,能帮我看看代码吗/*
* Web Server
*
http://geek-workshop.com/thread-1747-1-1.html
参考上面的帖子代码,是张老师做的硬件
但还是不行
代码:/*
Yeelink sensor client
by zcb
2012.07.17
*/
#include <EtherCard.h>
#include <OneWire.h>
//
//18B20
#define ONEWIRE_PIN 7
OneWire ds(ONEWIRE_PIN);
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
char SensorID[] PROGMEM = "626"; // replace your sensor ID
const uint8_t MyMac = {
0x74,0x69,0x69,0x2D,0x32,0x06};
const uint8_t MyIP = {
222,16,228,228 };
////////////////////////////////////////////////////////////
// for yeelink api
char APIKey[] PROGMEM = "5c137bc47b1fe0d3d7854509d7783c78"; // replace your yeelink api key here
char DeviceID[] PROGMEM = "500"; / replace your device ID
// 分配一个MAC IP网关的以太网控制器的DNS assign a MAC IP gateway dns for the ethernet controller.
const uint8_t MyGateway = {
222,16,228,15 };
const uint8_t yeelinkIP = {
202,136,60,231};
const uint16_t PostingInterval = 15000;// 2个数据点之间的延迟时间delay between 2 datapoints, 30s
// 一些全局变量Some global variables
char sensorData;
uint8_t dataLength;
uint8_t Ethernet::buffer;
uint32_t lastConnectionTime = 0; //你最后一次连接到服务器,以毫秒为单位 last time you connected to the server, in milliseconds
Stash stash;
void setup() {
Serial.begin(4800);
//启动串行端口 start serial port:
// 启动以太网连接start the Ethernet connection:
ether.begin(sizeof Ethernet::buffer, MyMac);
//
ether.staticSetup(MyIP,MyGateway);
}
void loop() {
Serial.print("yeelink:");
Serial.println(get_Current_Temp());
ether.packetLoop(ether.packetReceive());
if(millis() - lastConnectionTime > PostingInterval){
get_Send_String();
send_Data();
}
}
void send_Data() {
// 创建一个发表yeelink服务器Create a Post for yeelink server,
// 发送请求保存会话IDand send request saving sessionID
Stash::prepare(PSTR("POST /v1.0/device/$F/sensor/$F/datapoints HTTP/1.1" "\r\n"
"Host: api.yeelink.net" "\r\n"
"U-ApiKey: $F" "\r\n"
"Content-Length: $D" "\r\n"
"Content-Type: application/x-www-form-urlencoded" "\r\n" "\r\n"
"$S"),
DeviceID,SensorID,APIKey,dataLength,sensorData);
ether.copyIp(ether.hisip, yeelinkIP);
ether.tcpSend();
lastConnectionTime = millis();
}
///////////////////////////////////////////////////////////////////////////
//从温度传感器中获取数据 get data from temperature sensor
// 您的传感器,你可以替换此代码you can replace this code for your sensor
void get_Send_String(){
uint16_t Tc_100 = get_Current_Temp();
uint8_t i,whole, fract;
whole = Tc_100/10 ;// 分开的整数和小数部分separate off the whole and fractional portions
fract = Tc_100 % 10;
dataLength = sprintf(sensorData,"{\"value\":%d.%d}",whole,fract);
}
uint16_t get_Current_Temp(){ //0.1C
//returns the temperature from one DS18S20 in DEG Celsius
byte data;
byte addr;
if ( !ds.search(addr)) {
//no more sensors on chain, reset search
ds.reset_search();
return 0;
}
if ( OneWire::crc8( addr, 7) != addr) {
return 1000;
}
if ( addr != 0x28) {
return 1000;
}
ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end
delay(1000);
ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for (int i = 0; i < 9; i++) { // we need 9 bytes
data = ds.read();
}
ds.reset_search();
uint16_t tempRead = (data << 8) | data; //using two's compliment
return tempRead*10/16;
}
有着片子的51板,不知能不能改
楼主你好~我入了一块28j60,想用他和arduino通信,比如结合labview来控制舵机,应该怎么去实现?
现在看用的都是ethercard库,基本上没注释看不懂,也不知道该怎么调用啊
不知道为什么 不管按照大哥你的程序还是zcbzjx的方法我这边都不行.... 难道是我的ENC28J60有问题? 串口返回时一串乱码
茕兔 发表于 2012-9-30 15:10 static/image/common/back.gif
不知道为什么 不管按照大哥你的程序还是zcbzjx的方法我这边都不行.... 难道是我的ENC28J60有问题? 串口 ...
调整串口波特率试试,把那几个波特率都试一次。因为有时候因为电脑原因,会导致不是所有波特率都能用
太好了,卖家一直没有提供库,害的我自己编写,累死...
救命,程序烧进去了,可是,打开那个IP网页确不成功,求解答
hk386 发表于 2012-10-11 21:10 static/image/common/back.gif
救命,程序烧进去了,可是,打开那个IP网页确不成功,求解答
这个库有点老了,看张老师写的新版本的库的介绍吧,内容全很多。。。
http://www.geek-workshop.com/thread-2049-1-1.html
yeguiren773 发表于 2011-12-24 12:31 static/image/common/back.gif
**** 作者被禁止或删除 内容自动屏蔽 ****
能否给出nec28j60的电路图,我有这个芯片,想跳线试试
本帖最后由 洛克王国专用号 于 2013-3-24 22:39 编辑
网页无法访问http://192.168.1.123,怎么也弄不通?求解答,路由器和ping 截图如下:
代码:
/*
* Web Server
*
* A simple web server that shows the value of the analog input pins.
*/
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 123 };
Server server(80);
void setup()
{
Ethernet.begin(mac, ip);
server.begin();
}
void loop()
{
Client client = server.available();
if (client) {
// an http request ends with a blank line
boolean current_line_is_blank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if we've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so we can send a reply
if (c == '\n' && current_line_is_blank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
// output the value of each analog input pin
for (int i = 0; i < 6; i++) {
client.print("analog input ");
client.print(i);
client.print(" is ");
client.print(analogRead(i));
client.println("<br />");
}
break;
}
if (c == '\n') {
// we're starting a new line
current_line_is_blank = true;
} else if (c != '\r') {
// we've gotten a character on the current line
current_line_is_blank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
client.stop();
}
}