Show Posts
Pages: 1 ... 49 50 [51] 52
751  Using Arduino / Programming Questions / Re: my code doesn't do waht i think it ought to.. on: January 31, 2011, 11:31:39 am
Do you have a link to the datasheet for this "Potentiometer strip with an open wiper".
752  Using Arduino / Programming Questions / Re: PROGMEM and strcpy_P on: January 28, 2011, 10:34:30 am
This is not documented anywhere that I've ever seen, and not well known either, but the PROGMEM attribute does not work properly with automatic local variables. Because these variables are automatically cleaned up when they go out of scope, that conflicts with the 'immutable' natural of PROGMEM variables in flash.

It may work by declaring them static, but I've never tried that.  It certainly works by keeping them global.
753  Using Arduino / Programming Questions / Re: Servo Control on: January 28, 2011, 09:39:43 am
Quote
which has always seemed rather odd to me, but that's the standard
Given the typical use for a hobby servo, such as steering a car, positioning a rudder, operating as a throttle, etc., 60 degrees is generally the full range that the servo needs to sweep. How much throttle travel do you have, and how much servo movement is required to make the throttle travel that far?

Well there you go.  Makes more sense knowing that.  Guess I've never used hobby servos in the manner they were designed for. smiley
754  Using Arduino / Programming Questions / Re: Servo Control on: January 28, 2011, 09:26:50 am
I tired 1000 delay after the attach, I should do that after the command to, didn't try that.

I will try thanks.

You should try to make your code a little smarter about how much delay it needs.  All servos have an advertised speeds, typically in seconds per 60º (which has always seemed rather odd to me, but that's the standard).  A bit of quick math can give you a value of say, milliseconds per degree.

So say your servo takes 0.17 second to rotate 60 degrees (that's fairly typical for a hobby servo, not too fast, not too slow).  That is 170ms to rotate 60º or 170/60 = 2.83ms to rotate 1º.   Round that up to 3ms per degree.

As long as you keep track of your current position, and your target position, you can easily calculate how long it will take for your servo to move to the new position.

I'd also recommend handling the pan & tilt together.  That way it pans and tilts at the same time, one synchronous, smooth operation, as opposed to first panning, then tilting serially.
755  Using Arduino / Programming Questions / Re: delay() in only one method on: January 27, 2011, 03:06:33 pm
You can use millis() to get reasonably accurate timed activities.  Example:

Your example fails to work correctly as millis approaches the wrap.


Good point.  Couple minor tweaks can fix that.
1.Change the assignments to timer = millis();
2.Change the if condition to (millis() - timer > 2000)
756  Using Arduino / Motors, Mechanics, and Power / Re: Control stepper motor starting position? on: January 27, 2011, 12:25:18 pm
The standard method of initializing a stepper motor position is with a "home" position switch.

If you want your stepper motor to have a 0-180º range of motion, set up a mechanic switch at the 0 or 180º point.  During startup, move the stepper motor in the direction of your home switch until the switch is activated.  Now you know the position of the motor, and can move it to the 90º starting position.

Another option (since you do not require continuous rotation) is using a potentiometer as a voltage divider tied to the stepper motor shaft.  This will allow you to determine it's current position without having to move the motor.
757  Using Arduino / Programming Questions / Re: delay() in only one method on: January 27, 2011, 12:14:14 pm
delay() is a blocking delay, won't work for what you are trying to accomplish.

You can use millis() to get reasonably accurate timed activities.  Example:

Code:
unsigned int timer = millis() + 2000;

void setup(){
  Serial.begin(115200);
}

void loop(){
 
  if(millis() > timer){
    //run myRoutine every 2 seconds
    myRoutine();
    timer = millis() + 2000;
  }
 
  //Rest of program here
 
}

void myRoutine(){
  Serial.println(millis());
 
}
758  Using Arduino / Programming Questions / Re: HELP: max number count on: January 27, 2011, 12:10:32 pm
Use an unsigned long.

unsigned int is a 16bit type with a range of 0-65535.
unsigned long is a 32bit type with a range of 0-4,294,967,295.
759  Using Arduino / Programming Questions / Re: Microseconds? on: January 27, 2011, 11:54:45 am
tinkering with my attiny84 @ 16MHZ

What's the clock source for your attiny?  Is it a resonator or crystal?  Resonators are not very accurate and could easily account for the discrepancy you're seeing.
760  Forum 2005-2010 (read only) / Syntax & Programs / Re: polling the serial com port using arduino on: January 20, 2011, 04:51:40 pm
To trigger a task off a specific character received through the serial port:

Code:
if(Serial.available()){
  if(Serial.read() == '1'){
    //do task here
  }
}

If you need that task interrupted and restarted on another value being received from the serial port... that's a bit trickier.  You're either going to have to regularly check the serial data throughout the task you're doing, or generate a timed interrupt that checks the serial port at regular intervals, and somehow abort and restart the current task if another '1' is received.  It all depends on how instant your real time response needs to be.

If you also need to respond to other serial data coming in through the serial port, that only further complicates things.
761  Forum 2005-2010 (read only) / Syntax & Programs / Re: help for motorbike gear indicator on: January 20, 2011, 01:28:42 pm
So, store the "expected/ideal" gear ratio in your array.

Take your actual reading, calculate it's adsolute deviation from each of your ideal gear ratios, and select the one with the smallest deviation as the gear you are in.  So long as there is no overlap, the smallest deviation will always be the gear you are in.
762  Forum 2005-2010 (read only) / Syntax & Programs / Re: help for motorbike gear indicator on: January 20, 2011, 11:39:14 am
For any given gear, there should only be one actual ratio.  Why do you have a min and max ratio for each gear?
763  Forum 2005-2010 (read only) / Syntax & Programs / Re: Urgent - Split Long into 2 Int using BitShift on: January 20, 2011, 03:22:11 pm
The following should work to convert the two ints back into a long:

newlong = ((long)H << 16) | L;

But it will depend on the platform and programming environment you are working in to conver it back.  This assumes that H and L are two 16 bit variables, and that (long) is a 32 bit variable.  On most modern PCs and programming languages, ints are 32 bit variables and longs are 64 bit variables.  H and L may need to be declared as shorts and your 32 bit variable just declared as an int. (and the cast would be (int) instead of (long) as well)
764  Forum 2005-2010 (read only) / Syntax & Programs / Re: Urgent - Split Long into 2 Int using BitShift on: January 20, 2011, 01:15:03 pm
I'm not quite sure what your expectations are here.  The intermediate int decimal values will in no way correlate to the original long decimal value.  If they are only being used as a necessary step to transfer the entire data, then that doesn't matter.

What matters is that the bit representation is maintained.
Say you have a long value of (just for example) 1,582,081.
It's binary representation would be:
00000000 00011000 00100100 00000001

If you then assign that value to two ints with bitwise shifting, you would end up with
high int 00000000 00011000
low  int 00100100 00000001

If you then properly recompose that back into a new long, that new long will have the same decimal value as the previous one (assuming the binary representation of that decimal value is the same across any platform transitions).

You could use unsigned ints for your intermediate variables and it wouldn't make a difference.  You could even use 4 bytes or chars instead.

Quote
With -1 as ValueLong I read on serial monitor:

L = 11111111111111111111111111111111
H = 11111111111111111111111111111111

That looks completely correct.  Signed ints are stored in a twos complement format.  Google it for more info on how twos complement works, and why it's an ideal format to use for signed ints.
765  Forum 2005-2010 (read only) / Syntax & Programs / Re: Urgent - Split Long into 2 Int using BitShift on: January 20, 2011, 11:44:22 am
Bitwise manipulation in general doesn't care one bit (no pun intended) about the sign or format of the variable they are operating on.

If you decompose a 4 byte variable into two 2 byte variables, and then later recompose them back into a 4 byte variable, the bit patterns will remain identical.

That's not to say there won't be any sign issues, but they will not be related in any way to the bitwise operations (for example, there may be endian problems if you are transferring the data between platforms with different endian'ness').
Pages: 1 ... 49 50 [51] 52