Show Posts
Pages: 1 2 [3] 4 5 ... 15
31  Using Arduino / Networking, Protocols, and Devices / mega 2560 and SPI on: October 24, 2012, 03:27:51 am
I am using th eethernet shiled on the mega without problems. But reading the documentation I get surprised that things work. If the SPI on the mega is on pins  50 (MISO), 51 (MOSI), 52 (SCK) and 53 (SS) how is possible that we can use one shield made for the UNO SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK)?
32  Using Arduino / Programming Questions / Re: programming error...Need Help!! on: October 24, 2012, 03:12:42 am
have you put libraries in the right place?
33  Using Arduino / Programming Questions / Re: UNO vs Mega2560 on: October 24, 2012, 02:36:36 am
If you are using an Arduino Mega, SDA is pin 20 and SCL is 21, so note that shields with I2C need to be specifically for the Mega (taken from http://tronixstuff.wordpress.com/2010/10/20/tutorial-arduino-and-the-i2c-bus/)
34  Using Arduino / Programming Questions / Re: SD.begin fails after the mircoSd is written & arduino resetted on: October 24, 2012, 02:34:26 am
exactly. The problem only happens if in order:

1)I write on the txt file
2)I Leave the file written (without canceling an recreating it empty)
3)the sd is not phisically removed
4)The arduino reset

After all this things in the new setup() the card is not recognisez.
In all other case (I don't reset, I phisically remove the sd, I cancel the file before resetting, ecc...) everything works without problems
35  Using Arduino / Programming Questions / Re: SD.begin fails after the mircoSd is written & arduino resetted on: October 24, 2012, 02:08:36 am
Quote
Please explain exactly what you mean by 'cancel'

With 'cancel the file' I mean "SD.remove("valori.txt");"
36  Using Arduino / Programming Questions / Re: SD.begin fails after the mircoSd is written & arduino resetted on: October 23, 2012, 09:08:28 am
Quote
2) I don't cancel the files
Do you mean that you don't close the file?

No, I really  mean cancel. I always close the file once I have written o read. If I cancel it an re-create before resetting it works. If I write on it and reset (leaving phisically the card inside the slot) the SD.begin in the setup fails
37  Using Arduino / Programming Questions / SD.begin fails after the mircoSd is written & arduino resetted on: October 23, 2012, 08:37:40 am
Hello. I have a problem with my microSD card used with an ethernet shiled and a mega 2560.
The problem is that SD.begin(pin) in the setup fails if:
1) I write the card 2) I don't cancel the files 3) I reset arduino
If these 3 things do not happen everything works fine (open, write, cancel, create ecc..) for example if i write on a file, cancel it and reset arduino the sdBegin succeed.
If I read from a computer the file written on the SD it always looks like to be correct.
This is how I initialize the sd:
Code:
  //initialize SD              SETUP->SD
   Serial1.println("Initializing SD card...");
   // disable w5100 SPI while setting up SD
   pinMode(10,OUTPUT);
  digitalWrite(10, HIGH);//for arduino mega http://arduino.cc/forum/index.php/topic,46976.0.html
  
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
   pinMode(53, OUTPUT);
   digitalWrite(53, HIGH);
  
  if (!SD.begin(4)) {
    Serial1.println("cant save on SD!");
    noSd=true;
  }
  else{
    Serial1.println(F("SD inizialized"));
    
    // open the file. note that only one file can be open at a time,
    // so you have to close this one before opening another.
    mioFile = SD.open("valori.txt", FILE_WRITE);  
    if (mioFile) {
      Serial1.print("file opened");
      if(mioFile.available()>0 )
        sdScritta=true;
      mioFile.close();
      Serial1.println("done.");
    } else {
      // if the file didn't open, print an error:
      Serial1.println(F("error opening valori.txt"));
    }

  }



this is where I write:

Code:
     mioFile = SD.open("valori.txt", FILE_WRITE);
      if (mioFile) {
        Serial1.println(perServer);    
        mioFile.println(perServer);
// close the file:
        mioFile.close();
        sdScritta=true;
        Serial1.println("done.");

and here I read one line

Code:
       while (mioFile.peek()!='\r' && mioFile.peek()!=EOF)
        {
          stringaTemp+=(char)(mioFile.read());
        }
        Serial1.write(mioFile.read());//cattura il carattere di a capo
        Serial1.write(mioFile.read());
        Serial1.println(stringaTemp);
        Serial1.println("fine di una riga");


and here I cancel the file

Code:

    if(mioFile.peek()==-1){
      Serial1.println("cancel old file");
      mioFile.close();
      SD.remove("valori.txt");
      mioFile = SD.open("valori.txt", FILE_WRITE);    //create new one
      sdScritta=false;
      nRiga=0;
  }

If I phisycally eject the SD,put it inside again with the same file written and only after I reset it works!
Do you know if anything is wrong?
Thanks in advance for the time you will spent
38  International / Software / Re: arduino si riavvia da solo ... poca ram? on: October 23, 2012, 07:42:01 am
per capire se davvero รจ la ram a mancare usaq questa funzione:

int freeRam () {
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}
39  Using Arduino / Programming Questions / Re: Program flow question on: October 22, 2012, 08:23:50 am
Quote
Should I be using a completley different approach?
yes you can. i suggest you to read http://www.google.it/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&ved=0CDYQFjAB&url=http%3A%2F%2Fciteseerx.ist.psu.edu%2Fviewdoc%2Fdownload%3Fdoi%3D10.1.1.88.9025%26rep%3Drep1%26type%3Dpdf&ei=kkiFULGPB4vMsgbN9YHIAQ&usg=AFQjCNHpg7FOkZg9-3JO1VNAFOSxIhcnOg&sig2=HwQhSKvap7BtM_SRr6AINg&cad=rja
40  Using Arduino / Programming Questions / Re: how ethernt library methods work on: October 22, 2012, 08:01:55 am
thank you SurferTim.
41  Using Arduino / Networking, Protocols, and Devices / Re: why won't ethernet stay connected for more than a few hours? on: October 22, 2012, 08:01:44 am
In the version with the timeout is it ok that you call two times the client.stop if the timeout is reached?
42  Using Arduino / Programming Questions / Re: how ethernt library methods work on: October 22, 2012, 06:05:39 am
you can go look at the code yourself to answer such questions

Of course before ask you have to check yourself... If I have asked it is because after looking at the code, arduino docs and technical docs about TCP connections I did not succed. Answers like your made the forum heavy to read. Anyway it's true that sometimes people ask thing they can solve by themselves but this discussion is out of topic.
43  Using Arduino / Programming Questions / Re: how ethernt library methods work on: October 22, 2012, 05:58:38 am
Thanks. I edit the question specifing that I am using arduino always as a client.
Quote
The Ethernet class can't tell the status of the connection on the other end
but so how ethernet client.connected() can works? (I have read the code but I can't understand how  readSnSR() works)

Quote
If there is no client connected, there is nothing to stop.
but in many official examples you can find:

Code:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
for(;;)
;
}
44  Using Arduino / Programming Questions / how ethernt library methods work on: October 22, 2012, 04:08:48 am
Hello. I need to periodically send data on the internet and I am sucessfully using the official ethernet shield and library The arduino only acts as CLIENT.
What I am doing is this:
A) Check if the connection in ON 
Code:
client.connected()

B) if not connect 
Code:
client.connect()
C) send data
D) while
Code:
client.connected()
  read and parse server answer
E) once obtained the right answer or once a timout elapses call
Code:
client.stop()

This works but I may be I can make it better understanding more deep what ethernet methods do.
My questions (unresolved afer reading the internet reference and the library code) are:

1) Does
Code:
client.connected
checks if the connection is opened only SERVER SIDE speaking? (On TCP it is like we have 2 connections, one server side and one client side).
2) If point "A" give false do I have do call
Code:
stop()
before call the
Code:
connect()
on point "B".
3) Does the
Code:
stop()
funtion only close the connection client side speaking? (I call the close every time I send data because I know it is not a good practice to leave too much connection opened to the server, but if it acts only only on client side...)

Thanks for you help if you could answer!

45  Using Arduino / Programming Questions / Re: High and low power switching on: October 22, 2012, 02:47:08 am
yes you can datect voltages. I suggest you to read this page:
http://openenergymonitor.org/emon/buildingblocks
Pages: 1 2 [3] 4 5 ... 15