Show Posts
Pages: [1] 2
1  Using Arduino / Networking, Protocols, and Devices / tcp connection does not close when Arduino resets on: September 19, 2012, 07:33:39 am
Hi there,
I have my Arduino connecting to my PC via a TCP socket (that means I use EthernetClient in Arduino to connect to a java ServerSocket on my PC).
But if I try to reset Arduino (by pressing the button) or removing the power, the java program does not detect that the connection is broken.
Is there a way to work-around this?
2  Using Arduino / Networking, Protocols, and Devices / Re: Configure Ethernet without specifying MAC address? on: September 19, 2012, 07:28:08 am
I was not aware of that.

Does this mean that I can assign _any_ MAC address (instead of the one provided in the sticker under the shield) and still work, as far as it does not conflict with any other MAC address in the local network?

3  Using Arduino / Networking, Protocols, and Devices / Configure Ethernet without specifying MAC address? on: September 19, 2012, 07:09:48 am
Hi there,
Is it possible to configure the Ethernet shield without providing the mac address to Ethernet.begin() ?
Or alternatively somehow detect the MAC address of the Ethernet Shield during run time?
I understand than the logic behind this is that there may be more than one Ethernet Shields present and then it is necessary to provide the MAC address in order to assign the IP to the desired shield only, but it seems like an unnecessary burden if there's only one shield present (which is I guess the case most of the times).
4  Using Arduino / Storage / Re: SD.begin() causes "slowness" when SD card is not present on: September 10, 2012, 04:59:34 am
I think I found what the problem was.

SD.begin() calls (among others) Sd2Card.init(), and inside init()'s code I found this lines of code (file Sd2Card.cpp):



that change the contents of the SPI Control and SPI Status registers respectively.

Later on, and because microSD card is on board, control goes to "fail" which simply calls chipSelectHigh() and returns false, but does not revert the contents of the SPI registers.

One solution to work-around this and still leave the library code untouched is to preserve the contents of the spi register and revert them in case of failure. This is how I fixed it in my sketch:

Code:
void setup() {
  Serial.begin(9600);
 
  // disable W5100 while setting up SD
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);
 
  uint8_t spcr = SPCR;
  uint8_t spsr = SPSR;
  if (! SD.begin(4)) {
    Serial.println(F("Error cannot initialize SD card!"));
    SPCR = spcr;
    SPSR = spsr;
  }
}

Now I can still try to check if SD card is present, and still keep the Ethernet i/o fast.
5  Using Arduino / Storage / SD.begin() causes "slowness" when SD card is not present on: September 10, 2012, 04:02:15 am
Hi All,
Recently I've added SD card support to my project, it all went well although I had to do a good  face-lift to make sure there's enough memory for the highly demanding SD library.
However I have realized that if the microSD card is not present, and I call SD.begin() then any subsequent writes to Ethernet clients is really really slow (I/O is being done finally, but with lots of delays, even few seconds).
If I comment out SD.begin() then everything comes back to normal and Ethernet i/o is super-fast again.
Can you please advise?

This is the code I use in my setup() for initializing the SD card:


Code:
void setup() {
  Serial.begin(9600);
 
  // disable W5100 while setting up SD
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);
 
  if (! SD.begin(4)) {
    Serial.println(F("Error cannot initialize SD card!"));
  }
}
6  Using Arduino / Programming Questions / Re: detect pin mode possible? on: August 30, 2012, 04:52:34 am
I think it is simpler that I initially thought, it was a good idea to look at arduino/wiring_digital.c where I found the definition of pinMode():

Code:
void pinMode(uint8_t pin, uint8_t mode)
{
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
volatile uint8_t *reg, *out;

if (port == NOT_A_PIN) return;

// JWS: can I let the optimizer do this?
reg = portModeRegister(port);
out = portOutputRegister(port);

if (mode == INPUT) {
uint8_t oldSREG = SREG;
                cli();
*reg &= ~bit;
*out &= ~bit;
SREG = oldSREG;
} else if (mode == INPUT_PULLUP) {
uint8_t oldSREG = SREG;
                cli();
*reg &= ~bit;
*out |= bit;
SREG = oldSREG;
} else {
uint8_t oldSREG = SREG;
                cli();
*reg |= bit;
SREG = oldSREG;
}
}

that was easily reversed to a "getter":

Code:
uint8_t getPinMode(uint8_t pin)
{
  uint8_t bit = digitalPinToBitMask(pin);
  uint8_t port = digitalPinToPort(pin);
  volatile uint8_t *reg = portModeRegister(port);

  if (*reg & bit) {
    return OUTPUT;
  } else {
    volatile uint8_t *out = portOutputRegister(port);
    if (*out & bit) {
      return INPUT_PULLUP;
    } else {
      return INPUT;
    }
  }
}

this compiles but I can't test it now. I'm still not sure about the "oldSREG = SREG" trick and the CLI that are used in pinMode()
7  Using Arduino / Programming Questions / Re: detect pin mode possible? on: August 30, 2012, 04:16:17 am
Thank you. And sorry to open a new thread, I actually did some googling before posting but probably the search criteria was poorly chosen.

I want it for the same reason with that guy that asked that question on the other thread. I am building an API to remotely control the Arduino over http as a project for my school, and it has to be generic.

So I want to know if there's anyway to read the current pin mode for a given pin.

I know that I can initialize all pins to some specific mode in my setup(), then keep in an array all calls to pinMode() but I was more curious to know if that was possible.

For example, what if I don't want to initialize the pins to some arbitrary state at setup? What if I want to just leave them as they happened to be at a given moment.
8  Using Arduino / Programming Questions / detect pin mode possible? on: August 30, 2012, 02:22:01 am
Hi all,
Is there a way to "detect" the mode of a pin?
Thanks!
9  Using Arduino / Storage / Re: micro SD "HC class 4" card on: August 27, 2012, 08:44:35 am
Thanks! Then I guess I will go for the 8GB Kingston Class 4 micro SD HC + SD adapter.

I was kind of afraid that the "new/modern" micro SD may not be compatible with the Ethernet Shield's card reader.
10  Using Arduino / Storage / micro SD "HC class 4" card on: August 27, 2012, 07:24:47 am
Hi all,
Has anyone test the SD card reader that comes included with the Ethernet Shield, in combination with one of those "HC class 4" micro SD cards?
Thanks.
11  Using Arduino / Networking, Protocols, and Devices / Re: server.available() problem on: August 24, 2012, 03:08:39 am
Thanks, that's a good idea. I guess one could also subclass the EthernetServer and override the available method (although in general this is not a good practice).
12  Using Arduino / Networking, Protocols, and Devices / Re: server.available() problem on: August 23, 2012, 04:04:02 pm
Thank you for the reply.

The problem is that I want to implement a time-out. I want to cut off the client if it takes too long to complete the http request. But this way, I cannot start counting until the client sends the first byte. That means, that if the client never sends anything, it may happen that the server process will hang waiting for ever.

Also any timer/signal will not do any good because again the problem is that I cannot record the _moment_ that the connection was established.

Any ideas welcome...
13  Using Arduino / Networking, Protocols, and Devices / server.available() problem on: August 23, 2012, 03:21:09 pm
Hi there,

I have this code which is nothing more than the usual for a web server:

Code:
#include <SPI.h>
#include <Ethernet.h>

#include "Model.h"
#include "Controller.h"

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x33, 0x89 };
IPAddress ip(10,0,0,177);
EthernetServer server(80);

void setup() {
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);
  Ethernet.begin(mac,ip);
  server.begin();
}

void loop() {
  if (EthernetClient client = server.available()) {
    // do stuf with client here.
  }
}

and I just discovered that: the server.available() call does not return "true" before the connected client sends its first byte.

Any idea why is this happening?
14  Using Arduino / Networking, Protocols, and Devices / Re: Ethernet Library bogus? on: August 19, 2012, 05:31:20 am
Try this web server with two form fields. See how it does.
http://arduino.cc/forum/index.php/topic,114461.msg867258.html#msg867258
IDE v1.0.1 ethernet library is the only version I trust.

My friend, you - are - a - GENIUS !!!

I checked the example you pointed out for differences, and it seems that the key-difference is those two magic lines in setup():

Code:
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);

that deselect the SD card peripheral that comes together with the Ethernet Shield.

Now I've been hitting the arduino with 20 concurrent requests per second for about 15 minutes and for now it is still stable as a horse!

I think those two lines should be also included in the webserver example that comes with the Arduino IDE, together with a comment explaining their importance.

Thank you so much!  smiley

I will keep this thread update if I find something more.
15  Using Arduino / Networking, Protocols, and Devices / Ethernet Library bogus? on: August 18, 2012, 01:46:26 pm
Hi all,
I'm currently working on my project which involves serving of frequent http request through an ethernet shield.
However, my program falls constantly into an unstable behavior, soon enough arduino acts like "crazy", throws "random" characters mixed together with several string literals on the screen (Serial, or ethernet client) and finally "hangs", and by hanging I mean it really crashes, the reset button is not helping, and I have to reboot it by removing the power.
Originally I thought that it might be my code's fault, but what I do isn't really that complicated, but then I started suspecting the Ethernet library.
Searching the web I found this article: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1238640832
which dates back to 2009. Describes symptoms similar to the ones I'm currently facing, but it states that the official Ethernet library is now updated and that's why I don't need to and I can't download the revised version (because it's nowadays already fixed).
To demonstrate the problem is very easy: you just need an arduino board + an ethernet shield. Then open from the examples the Ethernet -> "Webserver" example. Edit your mac address and IP , and upload to your arduino. Then hit the IP address from a browser window. You will see the values of the six analog inputs. The page refreshes automatically after 5 seconds. Then start opening new tabs on your browser, and open the url with the IP again. And again, and again, until you have a lot of tabs on your browser hitting the arduino. I tried with 15-20 tabs and then after a few seconds, I could see the garbage output, then the arduino hangs up completely.
Any ideas on how to overcome this?
Pages: [1] 2