Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 14
61  Using Arduino / Installation & Troubleshooting / Re: arduino avrdude: stk500v2_ReceiveMessage(): timeout and Serial PRINT? on: March 11, 2014, 08:58:44 am
Maybe but I didn't have any !!!. I did have ***
I'm using serial prints now with no symbols. Everything is fine now.
62  Using Arduino / Programming Questions / Re: Calling child member from Base/Parent array? on: March 11, 2014, 08:20:25 am
yeah, it is complicated.
I want to make it simple for people to use so obviously, the code has to be complicated.

As long as it doesn't crash, I'm cool with it.
63  Using Arduino / Programming Questions / Re: Calling child member from Base/Parent array? on: March 10, 2014, 09:28:10 pm
I found the answer. I cast it wrong.

this is the right way
Code:
((Relay *)devices[i])->toggleSwitch();
64  Using Arduino / Programming Questions / Calling child member from Base/Parent array? on: March 10, 2014, 07:45:35 pm
Hi,

So, I have a base class and a child class. Something like
Code:
Class Device
{
     double read();
}

Class Relay : Public Device
{
      void toggleSwitch();
}

Class Sensor : Public Device
{
      int getValue();
}


I have an array to store the objects so I can keep track of them
Code:
Device *devices[10];
devices[0] = new Relay();
devices[1] = new Sensor();
etc…


devices[0]->toggleSwitch(); // error

I can call the member read() from any of these devices fine since read() is in the base class. So how do I call toggleSwitch() in Relay? I would get an error saying 'class Device' has no member named 'toggleSwith'. It makes sense since the 'devices' array is of Device. So how do I call a member of the child? I tried casting but it wasn't having it.
thanks.

65  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.
66  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.
67  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;
}

68  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.
69  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.
70  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.
71  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.
72  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.
73  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();
    }

74  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

75  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.
Pages: 1 ... 3 4 [5] 6 7 ... 14