Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 13
61  Using Arduino / Installation & Troubleshooting / arduino avrdude: stk500v2_ReceiveMessage(): timeout and Serial PRINT? on: March 10, 2014, 01:31:14 pm
arduino avrdude: stk500v2_ReceiveMessage(): timeout
so I got this message and thought oH boy, here we go. Did some googling and read it was anything from the IDE to the boot loader. I uploaded the sample 'Blink' and it worked fine.  I then found a obscure post where it was the code that caused the issue specifically the Serial.print.

I went into my classes and comment them out and uploading worked!
Any insights on this? Well this is here if anybody has the same problem.
62  Using Arduino / Storage / Re: SD card html page load time? on: March 07, 2014, 12:09:23 pm
Thanks, I think the problem was that tBuf[clientCount] = 0;
I guess it assigned 0 to somewhere it wasn't supposed to. I think I see it. It assigns tBuf[64] = 0 at one point BUT tBuf is only allotted for tBuff[0-63]

I'm surprised it worked in other people's code.
63  Using Arduino / Storage / Re: SD card html page load time? on: March 07, 2014, 08:38:57 am
Ok, I stripped down the code, got rid of custom libraries etc... and it still crashes and resets when tBuf is 64bytes.

Code:
#include <SD.h>
#include <SPI.h>
#include <WiFi.h>
#include <string.h>

/************* web ***************/
// set up WAP connection
char ssid[] = "SSIDNAME";      //  your network SSID (name)
char pass[] = "network pass";       // your network password

#define bufferMax 128
int bufferSize;
char queryBuffer[bufferMax];

int status = WL_IDLE_STATUS;
WiFiServer server(80);

/****************************************** sketch Logic **********************************************************/

void setup()
{
 
  // start serial port:
  Serial.begin(9600);
  
 
  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    delay(10000);
  }
  server.begin();
  // you're connected now, so print out the status:
  printWifiStatus();
  
  //************ initialize SD card *******************
  Serial.println("Initializing SD card...");
  if (!SD.begin(4)) {
        Serial.println("ERROR - SD card initialization failed!");
        return;    // init failed
  }
  Serial.println("SUCCESS - SD card initialized.");
    // check for index.htm file
    //it's picky with file extension, only 3 letters
  if (!SD.exists("index.htm")) {
        Serial.println("ERROR - Can't find index.htm file!");
        return;  // can't find index file
  }
  Serial.println("SUCCESS - Found index.htm file.");
  
}

void loop()
{

  // listen for incoming clients
  WiFiClient client = server.available();
 
  if (client) {
     boolean currentLineIsBlank = true;
     bufferSize = 0;
    
        while (client.connected()) {
            if (client.available()) {   // client data available to read
                char c = client.read(); // read 1 byte (character) from client
                if (bufferSize < bufferMax) queryBuffer[bufferSize++] = c;
                 if (c == '\n' && currentLineIsBlank) {
                   Serial.println("get in?");
                   parseReceivedRequest(client);
                   bufferSize = 0;
                   StrClear(queryBuffer, 128);
                   break;
                    
                 }
                 if (c == '\n') {
                    // last character on line of received text
                    // starting new line with next character read
                    currentLineIsBlank = true;
                }
                else if (c != '\r') {
                    // a text character was received from client
                    currentLineIsBlank = false;
                }
                
            }//end if available
        }//end while connected
    
    
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disonnected");
   //
    
  }//end client
  
}

/*********************************/

void parseReceivedRequest(WiFiClient client)
{
  //find query vars
  Serial.println(" ");
  Serial.println("*************");
  Serial.println(queryBuffer);
  Serial.println("*************");
  
    Serial.print("index page");
     // send a standard http response header
    client.println("HTTP/1.1 200 OK");
    client.println("Content-Type: text/html");
    client.println("Connection: keep-alive");
    client.println();
      
/* slowwwwww
    // send web page
    webFile = SD.open("index.htm");        // open web page file
    if (webFile) {
       while(webFile.available()) {
           client.write(webFile.read()); // send web page to client
       }
       webFile.close();
     }
*/

    byte tBuf[64];
    int clientCount = 0;

    File myFile = SD.open("index.htm");        // open web page file
    if (myFile) {
             while(myFile.available()) {
                    tBuf[clientCount] = myFile.read();
                    clientCount++;
                    tBuf[clientCount] = 0;

                    if(clientCount > 63) {
                      client.write((byte*)tBuf,64);
                      clientCount = 0;
                    }

            }
                  if(clientCount > 0) {
                    client.write((byte*)tBuf,clientCount);
                  }
        myFile.close();
    }  
  
}


void printWifiStatus()
{
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

// sets every element of str to 0 (clears array)
void StrClear(char *str, char length)
{
    for (int i = 0; i < length; i++) {
        str[i] = 0;
    }
}

// searches for the string sfind in the string str
// returns 1 if string found
// returns 0 if string not found
char StrContains(char *str, char *sfind)
{
    char found = 0;
    char index = 0;
    char len;

    len = strlen(str);
    
    if (strlen(sfind) > len) {
        return 0;
    }
    while (index < len) {
        if (str[index] == sfind[found]) {
            found++;
            if (strlen(sfind) == found) {
                return 1;
            }
        }
        else {
            found = 0;
        }
        index++;
    }

    return 0;
}

64  Using Arduino / Storage / Re: SD card html page load time? on: March 07, 2014, 12:26:19 am
It does make little sense why it's not working properly. I think it is the clone the could be the issue.
There's no reason to post hundreds line of code.
65  Using Arduino / Storage / Re: SD card html page load time? on: March 06, 2014, 11:29:37 pm
Ok, I bumped the tBuf down to 16 bytes and it's working. It takes 2-3 seconds to load now instead of a minute.
Thanks folks.
66  Using Arduino / Storage / Re: SD card html page load time? on: March 06, 2014, 11:24:15 pm
Yup, I'm on a 2560 mega clone, maybe that's the cause.
67  Using Arduino / Storage / Re: SD card html page load time? on: March 06, 2014, 11:16:34 pm
Are you saying it restarts the Arduino again? Is it running the setup function when using that code? That could be caused by a SRAM problem. The extra 64 bytes used by that array may be enough to overflow the SRAM.


Yup, the Void Setup is called again. I have Serial prints that tells me. I suspected it's a memory issue but I have plenty left on the board like 5200 bytes.

Ok, I'm bumping tBuf down to 32 bytes and see.
68  Using Arduino / Storage / Re: SD card html page load time? on: March 06, 2014, 10:55:56 pm
Ah, Yeah, it's weird. The code above resets the wifi shield. It restarts the wifi init process.
69  Using Arduino / Storage / Re: SD card html page load time? on: March 06, 2014, 09:32:00 pm
You should post your complete code.

No, WiFi client write works differently than the rest of write. You should use write(*byte, int) instead.

according to the documentation, there is no second parameter

http://arduino.cc/en/Reference/WiFiClientWrite#.Uxkw3lxdJoo

I deleted the code but it's basically this
Code:
byte tBuf[64];
int clientCount = 0;

    File myFile = SD.open("index.htm");        // open web page file
    if (myFile) {
             while(myFile.available()) {
                    tBuf[clientCount] = myFile.read();
                    clientCount++;
                    tBuf[clientCount] = 0;

                    if(clientCount > 63) {
                      client.write((byte*)tBuf,64);
                      clientCount = 0;
                    }

            }
                  if(clientCount > 0) {
                    client.write((byte*)tBuf,clientCount);
                  }
        myFile.close();
    }

70  Using Arduino / Storage / Re: SD card html page load time? on: March 06, 2014, 04:45:17 pm
It looks like the client.write for WIFI can't do chunks. oh well

71  Using Arduino / Programming Questions / Re: Arduino + LED RGB + Adobe Flash ( as3 ) on: March 06, 2014, 04:19:43 pm
How is Flash communicating with the Arduino ?

You'd need a server on your computer to act As a go between.
72  Using Arduino / Storage / Re: SD card html page load time? on: March 06, 2014, 12:49:49 pm
Oh, well, the code doesn't work. It resets the app/web server for some reason instead of loading the index.htm.
When I'm done, I guess I'll just put the html file on the arduino itself. I still have plenty of space on the mega.

Here is what I use. tBuf is a 64 byte array. This gives you a 4x improvement in speed.
Code:
                  while(myFile.available()) {
                    tBuf[clientCount] = myFile.read();
                    clientCount++;
                    tBuf[clientCount] = 0;

                    if(clientCount > 63) {
                      client.write((byte*)tBuf,64);
                      clientCount = 0;
                    }

                  }
                  if(clientCount > 0) {
                    client.write((byte*)tBuf,clientCount);
                  }
 

73  Using Arduino / Storage / Re: SD card html page load time? on: March 06, 2014, 11:49:39 am
I'm using the wifi shield.

Thanks SurferTim, I'll give the code a try.
74  Using Arduino / Storage / SD card html page load time? on: March 06, 2014, 10:40:38 am
Hi,
I'm working on a web server that pulls a simple html page off the SD card, about 50 lines.
It takes 1 minute - 12 seconds to load! Is that normal?

code below

Code:
webFile = SD.open("index.htm");        // open web page file
    if (webFile) {
       while(webFile.available()) {
           client.write(webFile.read()); // send web page to client
       }
       webFile.close();
     }
75  Using Arduino / Programming Questions / Re: RTC Timer events on: March 05, 2014, 08:59:49 am
You can use the timeAlarms library if programming isn't your forte. It'll trigger events for you without you writing if statements.
Pages: 1 ... 3 4 [5] 6 7 ... 13