Show Posts
Pages: 1 ... 244 245 [246] 247 248 ... 840
3676  Using Arduino / Programming Questions / Re: help with PWM soft motor pull timing on: November 05, 2013, 02:04:49 pm
If you need to keep synchronised with external events you should not just use delay() or delayMicroseconds() to control the execution speed. You need to manage the timing based on the value of millis() or micros().

You have a fundamental choice to make at the outset - whether your code is going to be blocking or non-blocking. Blocking code is easier to write for simple jobs but is only suitable for doing one thing at a time. If your sketch needs to control more than one thing concurrently then a non-blocking design would be more appropriate.

Do you need to measure the actual position/movement of each motor to keep them exactly in sync, or would it be sufficient to just make each motor change direction at the same instant so that they tend to stay roughly in sync?
3677  Using Arduino / Programming Questions / Re: output format question - XML? on: November 05, 2013, 01:59:10 pm
I don't know much about the opening/closing whatever's in this, is all new to me.

The idea of XML is that it is a tree structure of elements. Each element consists of an opening tag "<something>" and a closing tag "</something>" with the element content in between them. The name in the opening and closing tags must match. It's all very much like the structure of compound statements in C++ if you think of opening tags as being a named '{' and closing tags being a named '}' which must pair up with the opening tag.

(The code to print this out will be very repetitive - it would be much shorter and simpler if you implemented the repeating behaviour as functions.)
3678  Using Arduino / Programming Questions / Re: Hi, can someone help me with my code?? on: November 05, 2013, 01:49:37 pm
by processes i mean functions.
Maybe if i do change the void so i can return values

There's no general rule on whether it's right or wrong to return a value except that you must return one when you need it and should not when you don't. If you want to know whether a particular function should return a value, you need to explain what the function does and in particular what data needs to be passed into and out of the function.
3679  Using Arduino / Programming Questions / Re: Problem in Serial communication between 2 arduinos ! [SOLVED] on: November 05, 2013, 01:45:26 pm
as i said before the array has nothing to do with the problem here because i am just using the array for virtual wire for the transmitter

That's your assumption, but it's not a safe assumption. If the array size is wrong and you are overflowing the bounds of the array then you may be causing memory corruption. In that case, all bets are off. Until you know what is causing the problem, don't make any assumptions about what is not causing it.
3680  Using Arduino / Programming Questions / Re: Dual Ultra Sonic Sonar - Distance Reading Issue on: November 05, 2013, 01:41:06 pm
I have no idea how that shield is supposed to work or what the jumpers are for, and I don't see any technical information on the site you linked to.

Perhaps the shield is doing something with pins 0, 1 and perhaps that's why you need to use the jumpers to isolate those pins before you can use the serial port. That would explain the problems uploading, and the strange serial behaviour. But it's only speculation - you ought to look at the technical data supplied with the kit, which should have explained all this.
3681  Using Arduino / Programming Questions / Re: creating an averaging function correctly on: November 05, 2013, 01:34:07 pm
Code:
public int mean(int in){
  count++;
  if(count<numberReadings){
   avg += in;
   avg = avg/count;
  }
  if(count >= numberReadings){
    count = 0;
    avg = in;
  }
  return avg;
}

This seems to be trying to average every N samples, starting again for the next N samples. It is not producing a rolling average. Did you intend it to start again every N samples?

In order to calculate an average over a number of samples you need to record the sum and the count. You don't need to record the previous average. Instead of this:

Code:
   avg += in;
   avg = avg/count;

You want:
Code:
   sum += in;

The result is then sum / count.

If what you want is a rolling average you can do that easily using an exponential decaying average, e.g.:

Code:
average = (0.9 * average) + (0.1 * newValue);
3682  Using Arduino / Programming Questions / Re: Order of functions and function prototypes? on: November 05, 2013, 01:27:00 pm
The Arduino does various mucking about with code in your .ino file before it compiles it. Among other things, it tries to generate function prototypes for all the functions you have defined and puts them somewhere near the top of the sketch, in a location which is usually correct but sometimes not.

When you put your code in a 'C'/C++ source or header file it doesn't have this mucking about done and needs to conform to the usual 'C'/C++ requirements to be compilable. Among other things that means that all types and functions have to be declared or defined before they are used.

Putting executable code in header files is unconventional and not recommended. What you should do is put the code in a C++ source file, and put the corresponding external declarations in the associated C++ header file, and #include the header file in any other files that need visibility of those declarations.

Bear in mind that due to the mucking-about, the source code invoked by the compiler is not in the same directory as your original sketch and will usually be in a temporary directory, so any relative file references are likely to be problematic. If you implement the shared code as an Arduino library this works out much cleaner.
3683  Using Arduino / Project Guidance / Re: Self leveling camera platform on: November 05, 2013, 01:20:12 pm
often just not possible unless you are willing to throw away a lot of pixels.

This is why I suggested going for a wider field of view than you needed. If you have a margin you're prepared to lose during image stabilisation, then it's easy to do it in post-processing. If you aren't prepared to lose any of the image then it is massively harder.
3684  Using Arduino / Project Guidance / Re: Raspberry Pi or Arduino for Drone? on: November 05, 2013, 01:15:26 pm
I've considering purchasing an AeroQuad. Those can use different "brains" but one of the options is an Arduino Pro Mini so you can alter the code as desired using the Arduino IDE.

Surely the point of all the open source controllers is that you can alter the source on any platform.
3685  Using Arduino / Project Guidance / Re: I want my stepper motor to switch speed while traveling on: November 05, 2013, 10:57:52 am
I'm not sure what the problem is, but the way you're using the stepper motor API assumes that the library does what you expect - some of those methods have subtleties that aren't obvious and it would be easy for them to have unexpected side effects. You aren't really controlling what happens and when, either, so you could be inadvertantly running the wrong logic at the wrong time.

I can see two approaches to take.

First approach is to implement your sketch as a state machine. This fits the way the AcelStepper is designed to work since it is obviously designed with non-blocking operation in mind. The simplest way to do this is to define your states as integer values and then use a switch / case statement to execute the logic appropriate to the current state. For example you could define your states as enum States { PARKING, SLOW_FORWARDS, FAST_FORWARDS, REVERSING }; and then use a switch to do whatever is appropriate to the current state:

Code:
switch(state)
{
case PARKING:
    if(parkingSensorTriggered())
    {
        stepper1.setCurrentPosition(0); // this also stops the motor
        // start moving forward at slow speed
        stepper1.moveTo(2500);
        stepper1.setSpeed(200);
        state = SLOW_FORWARDS;
    }
    break;
case SLOW_FORWARDS:
    if(stepper1.distanceToGo() == 0)
    {
        stepper1.moveTo(5800);
        stepper1.setSpeed(400);
        state = FAST_FORWARDS;       
    }
    break;
case FAST_FORWARDS:
    if(stepper1.distanceToGo() == 0)
    {
        stepper1.moveTo(0);
        stepper1.setSpeed(400);
        state = REVERSE;       
    }
    break;
case REVERSE:
    if(stepper1.distanceToGo() == 0)
    {
        stepper1.moveTo(2500);
        stepper1.setSpeed(200);
        state = SLOW_FORWARDS;       
    }
    break;
}
stepper1.run();

This would treat the slow and fast parts of the movement as separate operations which I expect means the stepper driver will slow and stop at 2500. If you want it to be a continuous movement then at the start of SLOW_FORWARD you would command a movement to 5800 and set MaxSpeed to 200; at the start of FAST_FORWARD you would just change MaxSpeed to 400.
3686  Using Arduino / Project Guidance / Re: Tact switch mimicking a keypress on: November 05, 2013, 10:27:28 am
Nick, I have already corrected the stated issues. We have moved on from that point. Thanks. If you read further you will find the corrected code.

Now would you follow PaulS' advice please, and correct the formatting in your code and then repost it? It makes it much easier for us to understand.

Quote
Put every { on a new line.
Put every } on a new line.
Use Tools + Auto Format.
Post your code properly.

I have previously suggested using SoftwareSerial instead of the hardware Serial port. I guess your reply "I guess I'm not tracking what your wanting me to do then, can you explain further please" was in response to that. You're already using SoftwareSerial in one of your sketches and I'm suggesting you use it in the other one too.
3687  Using Arduino / Project Guidance / Re: turn on/off a led from sms message on: November 05, 2013, 10:15:55 am
I want to read the sms message and compare with a text written in my code and be able to turn on/off a led in my board.

You're unlikely to find existing code that does exactly what you want, so you'll need to write it. You should have no trouble finding examples dealing with the individual parts of your problem. Where have you got to so far, and which part of it are you having trouble with?
3688  Using Arduino / Programming Questions / Re: output format question - XML? on: November 04, 2013, 10:07:32 pm
By 'the fifteen total' I assume you mean the channels 0 .. 14.

You don't show a closing tag to match the opening tag for <interface> - is there supposed to be one?

The basic scheme would be that when setting channelCount to zero you print the opening tag <interface>. For each item you would print the opening and closing tags for each element with the content in between.

If you want to close the interfaces element after the fourteenth element then you would do that before opening the next one. I don't know whether you want to have the XML indented like that - usually, XML is layout neutral and linefeeds and indentation would not be used unless you were formatting it for display to a human (in which case the displaying software would do that layout for you. In other words, you would do stuff like:

Code:
    if (channelCount ==15){
      Serial.print("</interface><interface>
      channelCount = 0; // reset
    }
    Serial.print("<item><id>");
    Serial.print(channelCount);
    Serial.print("</id><description>");
    Serial.print(" ...

If it was me I'd implement functions to write an opening and closing tag with the tag name specified by a parameter, and a function to write opening and closing tags with a string in between them, but I seem to remember you aren't keen on functions. smiley-wink
3689  Using Arduino / Programming Questions / Re: Speakjet, repeating messages on: November 04, 2013, 09:53:26 pm
Firstly, please read the sticky at the top of this section about how to post code.

Secondly, can you give an example of what you typed into the serial monitor, what the sketch did in response and what serial output it produced?

Thirdly, if you're checking for specific characters being received it is much clearer to specify the character as '1', '2' etc rather than by the corresponding numeric ascii codes.

Fourthly, what line ending mode do you have selected in the serial monitor?
3690  Products / Arduino Yún / Re: Arduino YUN with PHP and MySQL - error on: November 04, 2013, 09:48:37 pm

trying to connect from my Arduino YUN through a PHP file to my MySQL database located on a Godaddy hosting.

once uploaded files. Php to MicroSD card located in the Arduino YUN, when connecting from my browser, it takes a few minutes and then throws me http error 502 "Bad Gateway".

Can you explain this a bit more clearly? At the moment I can't follow where the PHP webapp(s) is/are or how your browser comes into this.
Pages: 1 ... 244 245 [246] 247 248 ... 840