Lincolnshire, UK
Offline
Newbie
Karma: 0
Posts: 14
|
 |
« on: June 15, 2012, 09:26:47 am » |
I have recent bought an Ethernet Shield for the arduino for use in a renewable energy project. I have written a small test sketch which every 200 milliseconds sends a number which is incremented at the end of each loop. The problem I'm having is that sometimes (seeemly completely random) the packets will not send. I dont just mean missing a few i mean after one reset each one will send fine but then another time the USB cable is plugged in they wont send at all. I was wondering if some collisions or something is taking place. When theyre not sending a green LED marked 'L' on the shield comes on, but this can even happen when the ethernet cable is not plugged in. Is it a code error or a hardware error? http://i.ebayimg.com/00/s/NjAwWDYwMA==/$(KGrHqN,!qsE88gcHj3HBPTfK+uBcQ~~60_12.JPG The above link is a photo of the shield I bought its the top LED in the row of four marked 'L' that lights up when the loops fail to send UDP packets #include <SPI.h> #include <Ethernet.h> #include <EthernetUdp.h>
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; IPAddress ip(192, 168, 1, 126); unsigned int port = 12668; EthernetUDP Udp;
IPAddress client(192, 168, 1, 9);
int i = 0;
void setup() { pinMode(10, OUTPUT); Ethernet.begin(mac, ip); Udp.begin(port); delay(1000); }
void loop() { char holder[8]; memset(holder, 0, sizeof(holder)); itoa(i, holder, 10); Udp.beginPacket(client, port); Udp.write(holder); Udp.endPacket(); delay(200); i++; }
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3448
|
 |
« Reply #1 on: June 15, 2012, 09:43:18 am » |
Do you have a microSD card in the slot? That will cause UDP fails if not disabled or initialized.
|
|
|
|
|
Logged
|
|
|
|
|
Switzerland
Offline
Faraday Member
Karma: 69
Posts: 3268
|
 |
« Reply #2 on: June 15, 2012, 09:49:55 am » |
You'd better linked to a datasheet than to just a picture. From what I see on the picture I guess that the 'L' means link detected. This is not switched by software but by the chip itself. In my experience a failing link often means cabling problems. Replace your network cable (take a cat 5 to stay on the save side) and try again. What does the other side of the network cable (probably a switch) mean? Is the link going down there too?
|
|
|
|
|
Logged
|
|
|
|
|
Lincolnshire, UK
Offline
Newbie
Karma: 0
Posts: 14
|
 |
« Reply #3 on: June 15, 2012, 09:54:49 am » |
@SurferTim
I do have an microSD in the slot, if i remove that will that stop the problem? I'll give it a try.
@pylon
'L' is not link on this board, thats at the other side of the RJ45 socket and that lights up fine. The problem even persists when theres no cable plugged in. I noticed on this board there is no collision LED and wondered if that's what the LED represented?
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3448
|
 |
« Reply #4 on: June 15, 2012, 09:57:31 am » |
Yes, removing it will stop the fail, but I like to get stuff set up correctly the first time. Just disable it for now. void setup() { // disable the microSD card SPI pinMode(4,OUTPUT); digitalWrite(4,HIGH);
// now do your ethernet setup stuff }
edit: The 'L' led is connected to the SPI clock pin. When you have the microSD card in the slot, that is the SD card stepping all over your w5100/w5200 UDP send. Mine glows dim with the microSD card in the slot and not disabled.
|
|
|
|
« Last Edit: June 15, 2012, 10:06:42 am by SurferTim »
|
Logged
|
|
|
|
|
Lincolnshire, UK
Offline
Newbie
Karma: 0
Posts: 14
|
 |
« Reply #5 on: June 15, 2012, 10:08:21 am » |
I tried removing the SD card and changing the code to the following, but i still do not get UDP packets sent. Is there something else I'm missing? #include <SPI.h> #include <Ethernet.h> #include <EthernetUdp.h>
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; IPAddress ip(192, 168, 1, 126); unsigned int port = 12668; EthernetUDP Udp;
IPAddress client(192, 168, 1, 9);
int i = 0;
void setup() { pinMode(4, OUTPUT); digitalWrite(4, HIGH); Ethernet.begin(mac, ip); Udp.begin(port); delay(1000); }
void loop() { char holder[8]; memset(holder, 0, sizeof(holder)); itoa(i, holder, 10); Udp.beginPacket(client, port); Udp.write(holder); Udp.endPacket(); delay(100); i++; }
The 'L' LED is still lit up bright green. I understand what you mean by it glowing dim because on the occasion that the packets are sent out, i get the same.
|
|
|
|
« Last Edit: June 15, 2012, 10:19:36 am by alexyoung91 »
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3448
|
 |
« Reply #6 on: June 15, 2012, 10:22:37 am » |
Is the other localnet ip (192.168.1.9) a computer? If so, can you ping 192.168.1.126 from it?
|
|
|
|
|
Logged
|
|
|
|
|
Lincolnshire, UK
Offline
Newbie
Karma: 0
Posts: 14
|
 |
« Reply #7 on: June 15, 2012, 10:29:35 am » |
I used the command prompt and typed ping 192.168.1.126 and i got the following:
Pinging 192.168.1.126 with 32 bytes of data: Reply from 192.168.1.126: bytes=32 time=11ms TTL=128 Reply from 192.168.1.126: bytes=32 time=7ms TTL=128 Request timed out. Reply from 192.168.1.126: bytes=32 time=3ms TTL=128
Ping statistics for 192.168.1.126: Packets: Sent = 4, Received = 3, Lost = 1 (25% loss), Approximate round trip times in milli-seconds: Minimum = 3ms, Maximum = 11ms, Average = 7ms
Then the green LED went dim and it started working :S I got this ping response:
Pinging 192.168.1.126 with 32 bytes of data: Reply from 192.168.1.126: bytes=32 time=3ms TTL=128 Reply from 192.168.1.126: bytes=32 time=4ms TTL=128 Reply from 192.168.1.126: bytes=32 time=4ms TTL=128 Reply from 192.168.1.126: bytes=32 time=6ms TTL=128
Ping statistics for 192.168.1.126: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 3ms, Maximum = 6ms, Average = 4ms
|
|
|
|
|
Logged
|
|
|
|
|
Lincolnshire, UK
Offline
Newbie
Karma: 0
Posts: 14
|
 |
« Reply #8 on: June 15, 2012, 11:03:08 am » |
It can even send UDP data for about 10 minutes and then the 'L' LED comes on again and it will stop sending and vice versa. I wish i had a solution. It's very random when it works and i can't seem to change it. I wonder if its a problem with the shield?
It seems to be fine always receiving UDP packets.
|
|
|
|
« Last Edit: June 15, 2012, 11:06:37 am by alexyoung91 »
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 50
Posts: 3448
|
 |
« Reply #9 on: June 15, 2012, 11:35:11 am » |
Is it the time or the number of iterations that cause the fail? If you double the time between sends, does the time before fail double also? Or does it fail about the same time?
|
|
|
|
|
Logged
|
|
|
|
|
|