Hello everyone. I've got a functioning program that uses the W5100 Ethernet chip [the same as on the ethernet shield]. It basically works perfect, but sometimes I have to disconnect the chip and reconnect it and stuff like this till it actually connects to the network. Sometimes it has power but when you plug in the ethernet cable nothing happens on the breakout board. Not even a single LED on the Female connector is flashing.
This is the Board i am using in connection to the Nano.
The board so far needs two seperate 3,3V Voltage inputs to work, a GND connection, SCLK,SCS,MISO,MOSI. That's all the connections i am using. Maybe i was just lucky to get it working that way sometimes, maybe i also need to use the SPI_EN or other connections or maybe i have to write some delays into the code to "give it some time" to boot ... i sadly have no idea.
Here in the bottom you can find the two header connectors. Maybe you guys have an idea
Well, yeah. There must be some reason you posted this question in the programming section of the forum. We expect to deal with programming issues here. Your programming. You seem to have forgotten something.
Well... i am some kind of genius. The problem must appear somewhere in the void_setup() because that's where it gets stuck when it wants to obtain the DHCP Lease and there is no functioning connection to the W5100
#include <VirtualWire.h>
#include <SPI.h>
#include <Ethernet.h>
#include <HTTPClient.h>
#include <Ethernet.h>
#include <Avviso.h>
#define DEBUG 1
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
const int led_pin = 13;
const int receive_pin = 7;
int flag = 0;
void setup()
{
pinMode(led_pin, OUTPUT);
Serial.begin(115200); // Debugging only
vw_set_rx_pin(receive_pin);
vw_setup(500); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
if (DEBUG) Serial.println("Attempting to obtain a DHCP lease...");
Ethernet.begin(mac);
if (DEBUG) {
Serial.print("My IP address: ");
Ethernet.localIP().printTo(Serial);
Serial.println();
Serial.print("Gateway IP address is ");
Ethernet.gatewayIP().printTo(Serial);
Serial.println();
Serial.print("DNS IP address is ");
Ethernet.dnsServerIP().printTo(Serial);
Serial.println();
Serial.println("Waiting for someone to ring the bell");
}
Avviso.begin(NOTIFY_MY_ANDROID);
Avviso.setApiKey("4f8560d3eab3b2e3732b362bf4b31e4e50109dc4005531b0");
Avviso.setApplicationName("Es hat geklingelt");
}
char msg[9] = ""; //Speicher für die eingehende Nachricht
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i; // Zähler für den Array pointer
digitalWrite(led_pin, LOW); // Empfange Nachricht [LED AN]
for (i = 0; i < buflen; i++)
{
msg[i] = buf[i];
}
Serial.print(" MSG lautet: ");
Serial.println(msg);
}
else if (strcmp(msg, "klingel#") == 0)
{
digitalWrite(led_pin, HIGH);
Serial.println("Nachricht erfolgreich angekommen");
msg[1] = '0';
Serial.print("Sending push notification...");
int returnCode = Avviso.push("Jemand ist an der Vordertuer", "", 0);
if (returnCode == 200)
{
Serial.println("OK.");
delay(5000);
digitalWrite(led_pin, LOW);
}
else
{
Serial.print("Error. Server returned: ");
Serial.print(returnCode);
delay(5000);
}
}
}
The other "crap" that i am using is only the VirtualWire library should not interfere with the setup process since it's only used for a receiver and get's called upon in void_loop()
Avviso in the void_setup() just gets its information wich later will be sent in void_loop() when the right message is received via 433Mhz connection (virtualwire). It's only software and should have no effect on hardware pins.
Since the virtualwire pins don't match the SPI Pins D10-D13 this should be okay, too.
Just as a reminder, it's not the original Ethernet shield it just uses the same chip. And like i said before IT WORKS, the Problem only appears sometimes when I plug the Nano board into USB to supply it with power. Sometimes the Ethernet chip works, sometimes it doesn't. I have the feeling that I have to connect another pin of the Ethernet board to get it to work stable.
When you look into the picture of the header connectors I have connected:
Avviso in the void_setup() just gets its information wich later will be sent in void_loop() when the right message is received via 433Mhz connection (virtualwire). It's only software and should have no effect on hardware pins.
To get away from everything that could cause trouble I switched to my original Arduino Uno board instead of my Sainsmart Nano 3.0. Also i am now using the original "DhcpAddressPrinter" example from the Ethernet library.
/*
DHCP-based IP printer
This sketch uses the DHCP extensions to the Ethernet library
to get an IP address via DHCP and print the address obtained.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
created 12 April 2011
modified 9 Apr 2012
by Tom Igoe
*/
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for(;;)
;
}
// print your local IP address:
Serial.print("My IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println();
}
void loop() {
}
And i still have the exact same problem. Sometimes the Ethernet Board connects to the Arduino and sometimes it doesn't.
I have to remove and reconnect the 3,3V supply and/or the Ethernet cable and at some magical point it works perfectly fine. I can't really reproduce how i get it to work. Sometimes i just have to take away the power supply, sometimes i also have to disconnect the Ethernet cable .... It's really messed up I am trying to make a video about it and upload it to youtube so you can take a look for yourself
Sometimes the Ethernet Board connects to the Arduino and sometimes it doesn't.
I don't think it's a hardware problem with the shield or the Arduino. A poor connection to the power supply or a bad network cable seem far more likely.
In any case, it is not a matter of the ethernet shield connecting to the Arduino. It is a matter of the ethernet class getting an answer from your DHCP server. Are you running a DHCP server?
I find it easier to tell the router that my Arduino is at IP address 192.168.0.XX, and that that address is not to be used for any other device. That way, I don't need to have a DHCP server around.
The Problem seems to be the different speed these two Boards boot up to their working state. The Ethernet board just needs a kick in the nads with a 3,3V High on the Reset pin. Then it works properly all the time.
I come in late on this, but as PaulS is implying, if you think something is not working, then it's best to wipe everything else out of the program [all the other "crap"], and just address the one single issue.
That's also the ONLY way to write code in the first place. Get each of the different subsystems working in isolation from everything else, and THEN put them together. Then, the 2nd guessing [especially by forum members] is minimal.
The other thing is, your original post indicated there may also be a power issue:
Sometimes it has power but when you plug in the ethernet cable nothing happens on the breakout board. Not even a single LED on the Female connector is flashing.
I just had a problem yesterday where my SD card shield stopped working. Turned out to be the flakey female headers on the Arduino board were not making good contact with the flakey shield pins, so I bent the pins slightly. The problem is, none of these pins or receptacles are square - like they ought to be - but they're either flat or spade, and good contact may be iffy.
I have taken a deeper look into the problem. The problem was that the Reset pin was floating. You need to connect it to the Arduino Board and first define the pin as an Output and give it a HIGH Signal for a second and after that change the Pin to an Input. I don't know what the exact voltage levels are that the W5100 Reset Pin needs so it will work perfectly, but i know GND or 3,3V connected to the reset Pin won't get it to work properly.
As you can i see i chose the IO Pin 8. Since then i never had this problem again
void setup()
{
pinMode(led_pin, OUTPUT);
pinMode(8, OUTPUT);
Serial.begin(115200); // Debugging only
vw_set_rx_pin(receive_pin);
vw_setup(500); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
digitalWrite(8, HIGH);
delay(1000);
digitalWrite(8, LOW);
pinMode(8, INPUT);
if (DEBUG) Serial.println("Attempting to obtain a DHCP lease...");
Ethernet.begin(mac);