Pages: [1]   Go Down
Author Topic: Arduino MEGA & Ethernet Shield ENC28J60  (Read 2339 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everybody, I am a new user of Arduino from Spain.

I have an Arduino MEGA2560 and a Ethernet Shied type ENC28J60, I have connected them & every is OK with this library:

http://iteadstudio.com/application-note/ethernet-shield-go-with-arduino-libraries/

I am able to do ping, like a server and like a client. But I need some suggestions. Let me explain my project:

I need to extract some information from the Microsoft FSX Simulator through the TCP protocol using the IOCP software. I have checked it usig LabView environment and it works fine. But I need not to use a PC, and use only the Arduino connected to a router.

It is easy, my Arduino needs to write to the server (192.2.1.2 port 8090) the next command: "Arn.Inicio:Var419"
After that, I must to read the incommnig messages "Arn.Var419:xxxxxx"


Must I connect the Arduino like a clent? I have tried (see bellow) this code but It doesn't work, what do you think?
Thanks you very much & My best regards.
Pedro


Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

#include <Ethernet.h>

byte mac[] = { 0x00, 0x1B, 0xB9, 0x84, 0xCB, 0x60 };
byte ip[] = { 192, 2, 1, 4 };
byte server[] = { 192, 2, 1, 2 };

Client client(server, 8090);

void setup() {
  Serial.begin(9600);
  Serial.println("Iniciando conexion FSX");
  delay(100);
  Ethernet.begin(mac, ip);
  delay(5000);
  Serial.println("conextando a ip: 192.2.1.2.??????...");
 
  if (client.connect()) {
    Serial.println("FSX Conectado----->");
    client.println("Arn.Inicio:Var419");
    //client.println();
    delay(10000);
  }
  else {
    Serial.println("FSX NO conectado *********");
  }
}

void loop() {
cnx:
  delay (1000);
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
 
  if (!client.connected()) {
    Serial.println();
    Serial.println("Reintentando");
    goto cnx;

  }
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If there client is no client connected, goto the start of a function that will be called again, in an infinite loop anyway. Why?

Quote
I have tried (see bellow) this code but It doesn't work, what do you think?
I think you need to lean a little to the left. You are blocking your screen. We can't see what the program actually does, and you haven't told us.

A little farther. Still can't see.

A little more...
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Paul,

I have simplified the code, still not working:

#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 2, 1, 4 };                                     //my ip
byte server[] = { 192, 2, 1, 2 };                               //FSX ip

Client client(server, 8090);                                     //port must be 8090

void setup() {
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
  delay(1000);
  Serial.println("Begin FSX connection");
}

void loop() {

  client.println("Arn.Inicio:Var419");       //command from Arduino to FSX
  client.println();
  delay (10000);
rdx:                                                 // scan for responses from FSX
  delay (100);
  if (client.available()) {
    char c = client.read();
    Serial.print(c);                 //link TCP messages to serial (for debugging)
    goto rdx;
  }
 
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void loop() {

  client.println("Arn.Inicio:Var419");       //command from Arduino to FSX
  client.println();
  delay (10000);
rdx:                                                 // scan for responses from FSX
  delay (100);
  if (client.available()) {
    char c = client.read();
    Serial.print(c);                 //link TCP messages to serial (for debugging)
    goto rdx;
  }
 
}
The client.available() function returns the number of characters available to read. Read them in a while loop, rather than inventing your own. The goto statement has very little going for it here.

Quote
I have simplified the code, still not working:
You have some expectation of what the code should do. There is something that the code does. All we can tell from the information you have provided is that those two are not the same thing. We have a pretty good idea of what you expect it to do. What it actually does is a mystery.

You need to clear up that mystery if you expect help.
Logged

0
Offline Offline
Edison Member
*
Karma: 17
Posts: 1413
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hadnt come across that library. Looks very simple and similar to the original ethernet shield.
Are you using the ENC28J60 shield with it??
Are you using a gateway?
Ive tried this and does not connect, maybe you can give me a hint.,

Code:
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 88 };
byte server[] = { 74, 125, 224, 72 };
byte gateway[] = {192,168,1,1};

Client client(server, 80);

void setup() {
 // Ethernet.begin(mac, ip);
  Ethernet.begin(mac, ip, gateway);            //Setup ethernet client
  Serial.begin(9600);
 
  delay(1000);
  Serial.println("connecting...");
 
  if (client.connect()) {
    Serial.println("connected");
    client.println("GET /search?q=arduino HTTP/1.0");
    client.println();
  }
  else {
    Serial.println("connection failed");
  }
}

void loop() {
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
 
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;;)
      ;
  }
}
Logged

* Si preguntas, pon el código de tu programa, hace mucho mas fácil ayudarte. Y me ahorro un mensaje pidiendo que lo hagas.
* Si consigues solucionar tu problema, dedica unos minutos a explicar en tu post como lo conseguiste para beneficio de todos.
* Cambia el 'Subject' de tu hilo y añade 'SOLUCIONADO' cuando hayas llegado a una solución al problema que planteaste.
* Utiliza un 'Subject' para tu hilo que explique de que va el hilo.
Si estas empezando:
* Comienza a usar Arduino
* Guías de iniciación a Arduino
* Ejemplos
* Referencia del Lenguaje
* Conceptos básicos
Guia de usuario de arduino
Tutoriales en Ingles
Si necesitas que alguien te escriba el código: http://www.freelancer.com/  o esta  http://www.guru.com/

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

All the examples included in the ibrary works fine. I have tried all of them with my ip's.

Tomorrow I will try your code, and i will tell you about it.

Regards.
Logged

0
Offline Offline
Edison Member
*
Karma: 17
Posts: 1413
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My code is just the WebClient code that comes with the library you posted, but with a fixed gateway and changed server IP to call google.

These parts...
Code:
byte server[] = { 74, 125, 224, 72 };
byte gateway[] = {192,168,1,1};
 Ethernet.begin(mac, ip, gateway);            //Setup ethernet client

please let me know if this code works for you cause i dont understand what is happening.
this is the one i used with an Arduino UNO.
http://www.ebay.com/itm/170696120342?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649

Logged

* Si preguntas, pon el código de tu programa, hace mucho mas fácil ayudarte. Y me ahorro un mensaje pidiendo que lo hagas.
* Si consigues solucionar tu problema, dedica unos minutos a explicar en tu post como lo conseguiste para beneficio de todos.
* Cambia el 'Subject' de tu hilo y añade 'SOLUCIONADO' cuando hayas llegado a una solución al problema que planteaste.
* Utiliza un 'Subject' para tu hilo que explique de que va el hilo.
Si estas empezando:
* Comienza a usar Arduino
* Guías de iniciación a Arduino
* Ejemplos
* Referencia del Lenguaje
* Conceptos básicos
Guia de usuario de arduino
Tutoriales en Ingles
Si necesitas que alguien te escriba el código: http://www.freelancer.com/  o esta  http://www.guru.com/

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The code you posted looks like code for the wiznet 5100 chip. Below is what seems to be the ENC28J60 type coding. If you got ping to work, then maybe not.

Code:
#include "etherShield.h"

static uint8_t mymac[6] = {0x54,0x55,0x58,0x10,0x00,0x24};
static uint8_t myip[4] = {192,168,1,15};
static char baseurl[]="http://192.168.1.15/";
static uint16_t mywwwport =80; // listen port for tcp/www (max range 1-254)
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The code you posted looks like code for the wiznet 5100 chip. Below is what seems to be the ENC28J60 type coding. If you got ping to work, then maybe not.


With the library indicated at the beginning of the topic, is valid for ENC28J60.

Regards
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My code is just the WebClient code that comes with the library you posted, but with a fixed gateway and changed server IP to call google.

These parts...
Code:
byte server[] = { 74, 125, 224, 72 };
byte gateway[] = {192,168,1,1};
 Ethernet.begin(mac, ip, gateway);            //Setup ethernet client
please let me know if this code works for you cause i dont understand what is happening.
this is the one i used with an Arduino UNO.
I suppose that if you want to go out to the internet, without a router, through your PC, you need a crossover ethernet cable, take a look for this:
http://www.kiranjose.com/blog/2011/09/connect-to-internet-with-arduino-mega-2560-and-enc28j60-breakout-board_crossover_ethernet_cable/

Regards

Logged

0
Offline Offline
Edison Member
*
Karma: 17
Posts: 1413
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My code is just the WebClient code that comes with the library you posted, but with a fixed gateway and changed server IP to call google.

These parts...
Code:
byte server[] = { 74, 125, 224, 72 };
byte gateway[] = {192,168,1,1};
 Ethernet.begin(mac, ip, gateway);            //Setup ethernet client
please let me know if this code works for you cause i dont understand what is happening.
this is the one i used with an Arduino UNO.
I suppose that if you want to go out to the internet, without a router, through your PC, you need a crossover ethernet cable, take a look for this:
http://www.kiranjose.com/blog/2011/09/connect-to-internet-with-arduino-mega-2560-and-enc28j60-breakout-board_crossover_ethernet_cable/

Regards



no, i want to go out to the internet but i am using a router that has ip 192.168.1.1 thats why i need the gateway cause if not it does not find the router (same happens in my computers) i need to specify the routers ip.
Logged

* Si preguntas, pon el código de tu programa, hace mucho mas fácil ayudarte. Y me ahorro un mensaje pidiendo que lo hagas.
* Si consigues solucionar tu problema, dedica unos minutos a explicar en tu post como lo conseguiste para beneficio de todos.
* Cambia el 'Subject' de tu hilo y añade 'SOLUCIONADO' cuando hayas llegado a una solución al problema que planteaste.
* Utiliza un 'Subject' para tu hilo que explique de que va el hilo.
Si estas empezando:
* Comienza a usar Arduino
* Guías de iniciación a Arduino
* Ejemplos
* Referencia del Lenguaje
* Conceptos básicos
Guia de usuario de arduino
Tutoriales en Ingles
Si necesitas que alguien te escriba el código: http://www.freelancer.com/  o esta  http://www.guru.com/

Pages: [1]   Go Up
Jump to: