Show Posts
Pages: 1 ... 49 50 [51] 52 53
751  Using Arduino / Programming Questions / Re: Floating point math on: February 01, 2011, 12:39:34 pm
The Arduinos are capable of both floating point math and trig functions.  They are relatively slow, but if you have the time, they will work.
752  Using Arduino / Programming Questions / Re: if statement and telnet combined on: February 01, 2011, 12:37:34 pm
You have all your code in setup().  That function only runs once, when the unit powers up to initialize.

You need to move most of your code into loop(), which runs continuously.  The only stuff that should be in setup() is your Ethernet, serial, and client setup.  You also need to move your analogRead() from your variable declaration into loop() as well, as that only runs when the variable is declared (as in just once as well, for a global variable)
753  Topics / Robotics / Re: l293d motor shield for Tamiya on: January 31, 2011, 11:54:08 am
1n4004 diodes aren't ideal for motor drivers.  You should really use a schottky diode for that purpose.  Something that should be well suited to the SN754410 as an example would be a 1n5818 schottky diode.  1amp current max, 30volts max, fits fairly well with that h-bridge IC.  If you really need 36v, you could go with the 1n5819 (or if you don't need more than 20v peak, the 1n5817).
754  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".
755  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.
756  Using Arduino / Programming Questions / Re: Servo Control on: January 28, 2011, 09:39:43 am
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
757  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.
758  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)
759  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.
760  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:

unsigned int timer = millis() + 2000;

void setup(){

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

void myRoutine(){
761  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.
762  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.
763  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:

  if( == '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.
764  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.
765  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?
Pages: 1 ... 49 50 [51] 52 53