Show Posts
Pages: 1 ... 25 26 [27] 28 29 30
391  Using Arduino / Storage / Re: SD card problem on: February 17, 2013, 06:56:22 pm
How do you create the html files? If you create them using a PC you can store them directly on the SD card without using the Arduino. The same for the images: you probably have them on the PC. If your html is already in an arduino sketch you can just copy and paste it when you are editing it on the PC. That would simplify your task. As for including images, as you know you just need to put into the html file an <img> tag, like this:

Code:
<img src="filename.jpg">

Now, the hard part is to use the html and images stored on the SD card with a web server running on arduino. Is this what you want to do? I don't understand if you already have a web server running on arduino or if you are planning to create one. Anyway, you need the Ethernet library and the SD library. When the server starts it listens on a TCP port for requests. Each time a client connects and makes a request the server uses the SD library to open the html or image file, read it, and send it to the client. This is the part where I am almost sure you will encounter serious memory limitations.

If you are still sure you want to do that, try dividing your project in smaller tasks: can you create a web server? check the documentation for the Ethernet library: http://arduino.cc/en/Reference/Ethernet; can you read from an SD card? check the documentation for the SD library: http://arduino.cc/en/Reference/SD. Many people in this forum are discussing problems and solutions related to both libraries, and you should give a look at these discussions so that you know what to expect.

Good luck smiley-wink.
392  Using Arduino / Storage / Re: SD card problem on: February 17, 2013, 06:06:38 pm
Are you running your web server on the Arduino, with html pages and images stored on the SD card? It doesn't look an easy task. You may try to verify the following conditions:

1. Have you got enough memory on the Arduino to serve html and images? It all depends on the Arduino (is it a Mega?) and on how memory-intensive is your use of the SD library, so you should post your code if you need help with that.

2. Is your server able to serve concurrent request from your server? When a browser reads an html containing a <img> tag it usually sends a parallel request to the server. The Ethernet library can only handle a limited number of concurrent requests. Even managing two concurrent connections, however, may be tricky. If you suspect this is the problem you should post your code.
393  Using Arduino / Programming Questions / Re: Uploading a file from st card to FTP server on: February 17, 2013, 05:50:53 pm
Looking for alternatives, is the destination server under your control (i.e., you can install whatever software you like, you have no special security concerns...)? Is the file binary or text? Is it like a log file, that you can append to an existing file?
394  Using Arduino / Programming Questions / Re: Uploading a file from st card to FTP server on: February 17, 2013, 05:43:04 pm
Sorry, I am confused by all those #ifdefs and I may have got your code wrong, but if you are using the SD library I think you should

Code:
open("file.txt", FILE_READ);
395  Using Arduino / Networking, Protocols, and Devices / Re: WiFi shield TCP to webserver is very slow on: February 17, 2013, 03:53:48 pm
Can it be encryption at work?
396  Using Arduino / Installation & Troubleshooting / Re: Build folder disappeared or could not be written - Mac OS on: February 17, 2013, 03:36:47 pm
Hi, /var/folders is the location where the IDE copies intermediate files before compiling them. Maybe you don't have write permission on that directory, or on the cq directory under it. I don't think you can change the location but you can change the permissions. As for the programmer I feel safe using AVRISP mkll, which is probably what I got as a default.
397  Using Arduino / Installation & Troubleshooting / Re: Problem Uploading on Mac Book running Mountain Lion on: February 17, 2013, 03:18:12 pm
I'm afraid I have no solution to offer, but recently another person had a similar problem with ML and (s)he also reported the device name as usbmodemfa141. I have Snow Leopard and the UNO is seen as usbmodem114. It may be just coincidence, but I wonder what that additional 'fa' in the device name may mean. The other person produced a detailed log of the upload attempt, showing that communication failed when the device would have sent information about voltage and oscillator frequency.

Good to know that it's working on XP. You may try to produce two detailed logs for the attempts made on the two machines. I don't think I'll be able to find a solution but perhaps it will help others to help you. Please have a look at this discussion for more details:
http://arduino.cc/forum/index.php/topic,148510.msg1122040.html
398  Using Arduino / Project Guidance / Re: Beginner Traffic light project on: February 17, 2013, 02:23:16 pm
If you group different function calls into a separate function (see comment #2) you improve the readability of your code, but also get a clearer picture of the logic of your program. Besides, you can delay the implementation of some functions. There are really many advantages.

In your case you have a cycle involving four states. You can immediately translate it into four function calls. Let's call them (for brevity) green(), yellowPed(), yellowCar(), red(). Then you need to define the logic of the transition, involving either a timer or a button.

One thing that is worth remembering is that each loop() function is executed many times a second, so you have two choices:
- use delay() with large values, and interrupts when the button is pressed (your approach); this way, a single loop can last many seconds;
- add conditions that trigger a change of state. This is the approach followed when programming a PLC, and I believe is the one you are trying to emulate.

Let's call the four states G, P, Y, R. Leaving aside the button, the transition is based on a timer. Here is a simple one (not the best one, but it works):

Code:
// declare this as a global variable
long timer_start = millis();

int check_timer(int duration_in_seconds)
{
  long current_time = millis(); // get current time in milliseconds
  // compare the seconds since last reset with duration_in_seconds
  if ((current_time - timer_start) / 1000 > duration_in_seconds)
  {
    return 1;
  }
  return 0;
}

// let's also add a reset function
int reset_timer() {
  timer_start = millis();
}

Now in your loop you can call check_timer with different durations.

Code:
char current_state;
long timer_start;

void setup()
{
  current_state = 'R';
// edited: initialize the timer
  reset_timer();
}

void loop()
{
  switch(current_state) {
  case 'G':
    if (check_timer(4))
    {
      reset_timer();
      current_state = 'P';
      yellowPed();
    }
    break;
  case 'P':
    if (check_timer(2))
    {
      reset_timer();
      current_state = 'Y';
      yellow();
    }
    break;
  case 'Y':
    if (check_timer(2))
    {
      reset_timer();
      current_state = 'R';
      red();
    }
    break;
  case 'R':
    if (check_timer(5))
    {
      reset_timer();
      current_state = 'G';
      green();
    }
    break;
  }    
}

See the advantage of having green(), yellow(), red() defined as separate functions? They don't clutter the logic and you may decide to implement them at a later time. You must define them now, otherwise the code won't compile, but you can just let them do a Serial.println().

As you can see, I have hard-coded the duration in the call to check_timer(), and this is bad practice, but you can find a way to make the value configurable.

Now this loop() is fast since there are no calls to delay(), so you can also manage a buttonpress without an interrupt. The buttonpress would only shorten the duration passed to check_timer() when the lights are red. Does it make sense?
399  Using Arduino / Installation & Troubleshooting / Re: LiquidWare Buttonshield Errors- Don't Understand. on: February 16, 2013, 07:49:40 pm
Try editing ButtonShield.cpp and replace #include <wiring.h> with #include <Arduino.h>.
400  Using Arduino / Project Guidance / Re: Arduino project to apply what I have learned in logic design on: February 16, 2013, 06:35:46 pm
What about a programmable something? I don't know about the "something" part, but you can make it programmable if you instruct the Arduino to take input from a keypad and take that input as a "program" (procedure) in some custom language. E.g. I1 is input 1, O1 is output 1. Accept logical operators and apply them to produce an output from your inputs, define a way to use latches, maybe timers and counters. Then imagine some interesting domain (light, sound, temperature, home automation?) where you want to give end users the ability to program their own system.
401  Using Arduino / Programming Questions / Re: Transferring variables from android to arduino on: February 16, 2013, 05:14:18 pm
You may use the '<' and '>' chars as signaling the start and end of a string. When you get a '<' you start appending characters to your target string, when you get '>' you stop appending and process the string. You can use a char[] instead of a String. Each time you read a '<' you initialize the array to 0. Since all your data are integers you may try this:

Code:
// assuming you declared led_no, red_val, green_val, blue_val as integers
sscanf(your_string, "L%d,%d,%d,%d", &led_no,&red_val,&green_val,&blue_val);
402  Using Arduino / Installation & Troubleshooting / Re: A beginner's question: arduino with mac os x 10.8.2 can't upload on: February 16, 2013, 04:28:01 pm
I bought my board from website

I think you should be more specific about which website (did you mean this site?).

Anyway, from your log I can see that your UNO is communicating with the Mac, up to a certain point. It stops at the moment when it should send information about voltage and oscillator frequency. Unless other people experienced the same problem and knows of a solution, it is almost impossible to make a diagnosis without running test that require a certain experience (have you seen the loopback test? do you think you could do it?).

The only things I can suggest are small changes without touching the UNO:
  • With the Arduino connected to the Mac (powered on), try press and release the reset button (near the USB port). You should see the orange LED near PIN 13 blink for a while, then stay on.
  • Try using a different USB cable.
  • If you can find another computer, try installing the Arduino software on it and see what happens with your UNO.
  • Search the forum for issues with the drivers for 10.8.2 and how people dealt with them.

If you cannot resolve the problem you may consider asking for a replacement.
403  Using Arduino / Programming Questions / Re: indexOf does not work with a string value? on: February 16, 2013, 03:36:30 pm
A quick example of the diy approach. This will locate the beginning of the query string:

Code:
char *find_start_of_query_string(char *s) {
  while (*s != '?' && *s != '\0') {
    s++;
  }
  return s;
}

and this will locate parameter names and values
Code:

void parse_query_parameters(char *s) {
  char *name_start_pos;
  char *value_start_pos;
  size_t name_length;
  size_t value_length;

  while(1) { // return only on '\0'

    name_start_pos = ++s;
    name_length = 0;
// look for the equals sign or end-of-string
    while (*s != '=' && *s != '\0') {
      name_length++;
      s++;
    }
    if (*s == '\0') {
      return;
    }

    value_start_pos = ++s;
    value_length = 0;
// look for ampersand, space or end-of-string
    while(*s != '&' && *s != ' ' && *s != '\0') {
      value_length++;
      s++;
    }
    if (value_length > 0) {
// assuming you have declared and initialized a time_value variable, e.g.
// char time_value[20] = {0};
      if (strncmp("time", name_start_pos, name_length)) {
        strncpy(time_value, value_start_pos, value_length);  
      }      
    }
    if (*s == '\0') {
      return;
    }
  }
}

A tangential issue is that you don't want people to mess around with your parameters (e.g., sending "time=999999,abc,-15" in the query string). So you will probably need to have some control in place before accepting the values.
404  Using Arduino / Programming Questions / Re: calling a function repeatedly on: February 16, 2013, 02:12:03 pm
I donĀ“t even know what indentation , less tool + Auto Format means.

You should know by now. PaulS' advice is right for beginners, who might ignore that very few people will read their code line by line. Most people will do a fast scan of the code before zooming in to a smaller portion that attracts their attention, using visual clues such as the placement of instructions on the screen (spacing, empty lines). If it takes too much for people to understand your code they will loose interest and you won't get their help.
405  Using Arduino / Programming Questions / Re: Determine device at build time? on: February 16, 2013, 01:06:41 pm
Some processor-related #defines are actually passed to the compiler. So

Code:

#if defined(__AVR_ATmega328P__)
#define kBufSize  1024
#endif

may do the trick. Check this:
http://electronics4dogs.blogspot.it/2011/01/arduino-predefined-constants.html
Pages: 1 ... 25 26 [27] 28 29 30