Cheyenne:
Aprovecho que se ha subido este tema. Al final yo también adquirí un módulo ENC28J60 y lo hice funcionar. Yo he utilizado la librería EtherCard.h. Sin embargo os comento una limitación que he visto y es que ninguna de las librerías para este módulo que hay por la red (al menos no he sabido encontrar ninguna) permite la comunicación UDP.
SI LO soporta, bajate esta libreria.http://kmtronic.com/dino-internet-ethernet-io-board-ping-example.html
aqui, mi code-
#include "EtherShield.h"
uint8_t mymac[6] = {0xCF,0x70,0x7C,0xE4,0x8A,0xB8};
uint8_t myip[4] = {192,168,1,25};
uint16_t MYWWWPORT = 80;
#define BUFFER_SIZE 750
static uint8_t buf[BUFFER_SIZE+1];
char reply[]="Realized";
static uint8_t udp_length;
static float udp_buffer[50];
EtherShield es=EtherShield();
uint16_t plen, dat_p;
///----------------------------------------------------------
void setup(){
Serial.begin(9600);
es.ES_enc28j60Init(mymac);
es.ES_init_ip_arp_udp_tcp(mymac,myip, MYWWWPORT);
} // end setup
///----------------------------------------------------------
String readString;
float n;
char c;
void loop(){
// read packet, handle ping and wait for a tcp packet:
dat_p=es.ES_packetloop_icmp_tcp(buf,es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf));
if (buf[IP_PROTO_P]==IP_PROTO_UDP_V){
udp_length=buf[39]-8; // calculate UDP data lenght
for (int i = 0; i < udp_length; i++)
{
c = buf[42+i];
readString += c;
// Serial.println(udp_length);
}
char carray[readString.length()+1];
//readString.toCharArray(carray, sizeof(carray));
readString.toCharArray(carray, sizeof(carray));
n = atof(carray);
// udp_buffer[0]= n;
Serial.print(" ");
Serial.println(carray);
Serial.println(n);
es.ES_make_udp_reply_from_request(buf,carray,sizeof(carray),12345);
readString="";
buf[IP_PROTO_P]=0;
}
} // end loop
Para Processing 1.5 o te bajas este programita del aautor.http://www.kmtronic.com/software/DINo/UDP_Example/KMTronic%20DINo%204%20Relay%20UDP%20Test%20Software.zip
import hypermedia.net.*;
UDP udp; // define the UDP object
void setup() {
udp = new UDP( this, 12345 ); // create a new datagram connection on port 6000
//udp.log( true ); // <-- printout the connection activity
udp.listen( true ); // and wait for incoming message
}
void draw()
{
}
void keyPressed() {
String ip = "192.168.1.25"; // the remote IP address
int port = 12345; // the destination port
float f=1.9;
String s2 = Float.toString(f); //version 2
udp.send(s2, ip, port ); // the message to send
}
void receive( byte[] data ) { // <-- default handler
//void receive( byte[] data, String ip, int port ) { // <-- extended handler
for(int i=0; i < data.length; i++)
print(char(data[i]));
println();
}
.................................
el problema que me tiene en vela, es que siempre actua el envio como un estimulo-repuesta.
es decir, que siempre que se quiera enviar un paquete udp desde el arduino se debe hacer un ping (o enviar un paquete)al "Server Arduino".
yo quiero que actue de forma independiente, como si seria un puerto serial, envio y resivo si ninguna condicion .espero que se me alla
entendido.
Si alguien tiene a solucion se lo agradeceria