arduino-api icon indicating copy to clipboard operation
arduino-api copied to clipboard

Initializing Ethernet

Open ALeishman opened this issue 9 years ago • 7 comments

Hello - I'm new to Plotly and I'm having a tough time getting this stream set up. My Serial Monitor just hangs on "Initializing Ethernet".

Any idea what the issue could be?

Hardware: Ardunio Uno + SeeedStudio Ethernet Shield v2 + DHT22

The SeeedStudio Ethernet shield doesn't have a mac address so I assume the one I have in there should be fine. It's solo on the network.

I have my Arduino plugged into my PC. I have my Ethernet plugged into my Router I haven't tried port forwarding yet - I have no idea what port to forward.

Green and Red LED on the Ethernet Shield = On Little Orange light on the Ethernet Port is slowly blinking. So seems like there is no issue with the cable.

I ran the sample code in the Arduino IDE and I was able to get my private IP - so I believe my connection between hardware is fine.

Code:

include <SPI.h>

include <Ethernet.h>

include "plotly_streaming_ethernet.h"

include "DHT.h"

// Sign up to plotly here: https://plot.ly // View your API key and streamtokens here: https://plot.ly/settings

define nTraces 2

// View your tokens here: https://plot.ly/settings // Supply as many tokens as data traces // e.g. if you want to ploty A0 and A1 vs time, supply two tokens char *tokens[nTraces] = {"TOKEN1", "TOKEN2"}; // arguments: username, api key, streaming token, filename plotly graph("Leishman", "API_KEY", tokens, "filename", nTraces);

// DHT Sensor Setup

define DHTPIN 2 // We have connected the DHT to Digital Pin 2

define DHTTYPE DHT22 // This is the type of DHT Sensor (Change it to DHT11 if you're using that model)

DHT dht(DHTPIN, DHTTYPE); // Initialize DHT object

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; byte my_ip[] = { 11, 111, 111, 11}; // google will tell you: "public ip address"

void startEthernet(){ Serial.println("... Initializing ethernet"); if(Ethernet.begin(mac) == 0){ Serial.println("... Failed to configure Ethernet using DHCP"); // no point in carrying on, so do nothing forevermore: // try to congifure using IP address instead of DHCP: Ethernet.begin(mac, my_ip); } Serial.println("... Done initializing ethernet"); delay(1000); }

void setup() { graph.maxpoints = 100; // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only }

startEthernet();

bool success; success = graph.init(); if(!success){while(true){}} graph.openStream(); dht.begin(); }

float h, t;

void loop() { h = dht.readHumidity(); t = dht.readTemperature(); graph.plot(millis(), t, tokens[0]); graph.plot(millis(), h, tokens[1]); }

My gut says its an issue with the router - but I'm not sure. Any suggestions or advice would be helpful. I'd really like to get something up and running on Plotly.

ALeishman avatar Jan 13 '15 01:01 ALeishman

Some progress - I believe there is a different Library for the Seeed Studio v2. I am exploring that - seeing if I can adapt the code.

ALeishman avatar Jan 13 '15 02:01 ALeishman

Got it. Get the Seeed Studio new Library for the Ethernet Shield + make sure Plotly's CPP calls for the correct Ethernet library.

ALeishman avatar Jan 13 '15 02:01 ALeishman

Is that all you did what change the cpp and get the new W5200 library from git? ie: #include Ethernet.h (use of carrots of course) changed to #include EthernetV2_0.h (use of carrots of course)

Because I tried this and it isn't changing this annoying state of .........Initializing Ethernet

sheepsblood avatar Feb 24 '15 03:02 sheepsblood

That's all I remember doing. That and I opened plot.ly CPP file and made sure they referenced the v2 Ethernet file.

ALeishman avatar Feb 24 '15 16:02 ALeishman

Also make the change in your sketch...

ALeishman avatar Feb 24 '15 16:02 ALeishman

So far I have changed Plotly's CPP and h. Changed the include to EthernetV2_0.h in my sketch

Here is my sketch (of course all personal tokens and login are filled with X's)

//#include <Ethernet.h> #include <EthernetV2_0.h> #include <SPI.h> #include "plotly_streaming_ethernet.h"

// Sign up to plotly here: https://plot.ly // View your API key and streamtokens here: https://plot.ly/settings #define nTraces 2 // View your tokens here: https://plot.ly/settings // Supply as many tokens as data traces // e.g. if you want to ploty A0 and A1 vs time, supply two tokens char *tokens[nTraces] = {"xxxx", "xxxx"}; // arguments: username, api key, streaming token, filename plotly graph = plotly("xxxx", "xxxx", tokens, "xxxx", nTraces);

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; byte my_ip[] = { 192, 168, 1, 145 }; // google will tell you: "public ip address"

void startEthernet(){ Serial.println("... Initializing ethernet"); if(Ethernet.begin(mac) == 0){ Serial.println("... Failed to configure Ethernet using DHCP"); // no point in carrying on, so do nothing forevermore: // try to congifure using IP address instead of DHCP:

    Ethernet.begin(mac, my_ip);

}
Serial.println("... Done initializing ethernet");
delay(1000);

}

void setup() {

// Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only }

startEthernet();

graph.fileopt="overwrite"; // See the "Usage" section in https://github.com/plotly/arduino-api for details bool success; success = graph.init(); if(!success){while(true){}} graph.openStream(); }

unsigned long x; int y;

void loop() { graph.plot(millis(), analogRead(A0), tokens[0]); graph.plot(millis(), analogRead(A1), tokens[1]);

delay(50);

}

sheepsblood avatar Feb 25 '15 01:02 sheepsblood

I had this exact issue and used the solutions above with no success. Then I opened the examples from Seeed's library and noticed that they always disable the SD card (onboard the ethernet shield) by pulling it's chip select pin high. So I followed the steps from previous posts, then added the code below to my sketch. (Define the CS pins before the startEthernet() function, then modify the function to pull the CS pin high before initializing ethernet). This fixed it for me!

// CS pin of W5200 Controller
#define W5200_CS  10
// CS pin of SD card
#define SDCARD_CS 4

void startEthernet(){
  // The SD card and ethernet controller use the same SPI port.
  // We need to make sure that the SD card is deselected by setting the SD card CS pin to HIGH
  pinMode(SDCARD_CS,OUTPUT);
  digitalWrite(SDCARD_CS,HIGH);//Deselect the SD card

(...continue with the rest of the startEthernet() function from plot.ly example...)

z-l-p avatar Apr 07 '15 19:04 z-l-p