Loading...
  Show Posts
Pages: 1 ... 4 5 [6] 7 8 ... 18
76  Using Arduino / Programming Questions / Re: Programming in Arduino Uno on: April 20, 2013, 12:32:52 pm
Have I got this correct?
You set the motor speeds and start the motors.
You then compare the actual speeds of the two motors.
You then adjust the set speed of one motor by the difference in actual speeds, bringing the actual speeds into sync.



77  Using Arduino / Programming Questions / Re: I think I am setting boolean values correctly but... on: April 19, 2013, 11:27:21 pm
Given the code I see no reason it can't simply be -

Code:
if ( key )


He originally cast 'key' as a char. Would 'if(key)' work without recasting it?
78  Using Arduino / Programming Questions / Re: Programming in Arduino Uno on: April 19, 2013, 11:07:03 pm
Hi, can someone help me with my code?

Code:

int compareValue(int x, int y){
  // Compare values from Master and Slave and send a signal that corrects the slave singal as a analog output A4
  int result;

  if ( x = y){
    result =y;
    return result;
  }
  else if( x < y){
    result = (x-y)+y;
    return result;
  }
  else if ( x > y){
    result = (x-y)+y;
    return result;
  }
  return 0;
}

(x-y)+y = x, whatever values you chose.
79  Using Arduino / Project Guidance / Re: Hello to the Arduino community. "Water" project advice... on: April 19, 2013, 09:37:18 am

The suggestion by Henry_Best of double-walled pipes is probably as good or better than any other suggestion. It is only impractical for cost and convenience reasons. Maybe it would be worth implementing in some locations.

Thanks for the vote of confidence, but it's also impractical to fit such a system. Imagine trying to fit the outer pipe around an elbow, bend or 'T' joint! For a 'T' joint, you'd have to split the outer 'T' into at least 2 pieces, fit them on and then 'weld' them back together...with no leaks! The same for an elbow. Also, all pipes would have to run 'uphill', away from the sump.
80  Using Arduino / General Electronics / Re: I will like to know how many watts are consumed in a led on: April 18, 2013, 11:25:18 pm

If you have a multimeter, you can measure the voltage across the resistor and LED to make a better calculation.  (The LED voltage rating is not always exact.)    In order to measure current you have to break the connection and insert the multimeter in series.  So, it's usually best to measure the voltage across the known resistance and calculate the current through it.

However, that only tells him how much power is consumed by the LED and its associated resistor. The Arduino is also consuming power, probably more than the LED and resistor.
81  Using Arduino / Programming Questions / Re: I think I am setting boolean values correctly but... on: April 18, 2013, 11:09:54 pm
Likewise:
Code:
if (int(key) != 0)

can be shortened to:
Code:
if (int(key))
82  Using Arduino / Programming Questions / Re: Completing a task in a loop before breaking out. on: April 18, 2013, 11:01:57 pm
Thanks for the ideas Henry_Best. I like that approach a lot, but my system is dynamic and the angle isn't a one time shot. The angle in the y_axis is always changing. While the motor is moving the amount of angles calculated in your code, by the time it stops it, it will be at completely different angle.


Try this:
Code:
Void loop(){
   myStepper.setSpeed(13);     //Setting Stepper Speed at 13rpms
// You only need do this once (unless you're  changing the
// speed of the motor), not every time you move the stepper.
   int xsensorReading = analogRead(A1);
    //get initial reading of xsensor
   while (xsensorReading > 333) {
     int xsensorReading = analogRead(A1);
     int ysensorReading = analogRead(A2);
     int angle = map(ysensorReading, 315, 345, 30, 0);
               //calculate angle each time through the loop
     myStepper.step((-stepsPerRevolution/50)*(angle - 13));
   }
//when it gets here, xsensor reading will be <=333. No need to check it.
   myStepper.setSpeed(0); //Stop motor
}


If your motor is turning at 13 rpm and you turn 1/50th of revolution, it will take
(60/13)/50 seconds = less than 0.1 seconds (not allowing for the miniscule amount of time it takes for the program to run the loop). The angle should never be more than 2 or 3 degrees away from your 13 degrees between one reading and the next. 3 degrees will take the motor 0.3 seconds.
How much faster do you want it?
83  Using Arduino / Programming Questions / Re: switch / case not switching as expected...need second pair of eyes on: April 18, 2013, 10:06:58 pm
>UKHeliBob
I took your advice and went with the "if" statements only. Works like a charm now. Thanks a lot. I have used switch/case many times in the past with various languages (but I'm just a newbie) so that was the first thing I tried. This is the first time I couldn't get it to work. The sketch works now but I'm still wanting to know why switch didn't work. "Inquiring minds want to know."

"If it ain't broke, fix it 'til it is."

Check your if statements. What happens if iVal ==150?
84  Using Arduino / Project Guidance / Re: Advice for debugging a circuit? on: April 18, 2013, 09:40:19 pm
A first!
A partial schematic with the legend "To Cockroach leg".

"First, catch your cockroach..."  smiley

But he's asked for advice on de-bugging it?
85  Using Arduino / Project Guidance / Re: Hello to the Arduino community. "Water" project advice... on: April 18, 2013, 09:24:49 pm
Surround all your water supply pipes with wastepipes.
Have the wastepipes drain into a sump.
If the sump has water in it, you've got a leak somewhere!
The trouble will then be finding the leak.  smiley

(Not a serious suggestion, but it will work.)
86  Using Arduino / Programming Questions / Re: Completing a task in a loop before breaking out. on: April 17, 2013, 10:13:41 pm
Its just one stepper motor responding to the y-axis, but wont do anything until a condition in the x-axis is met.

My code for the while's is:

void loop(){
...  while (angle > 13)                     // While the angle is greater than 13
{                                         // initiate Stepper
   myStepper.setSpeed(13);     //Setting Stepper Speed at 13rpms
   myStepper.step(-stepsPerRevolution/50);   //Telling Stepper to rotate in the counterclockwise direction 2050/50 steps = 41 steps
}

  while (angle < 13)         //While angle is less than 13
{                                               //initiate Stepper
    myStepper.setSpeed(13);          //Set stepper speed to 13 rpms
    myStepper.step(stepsPerRevolution/50);}     //Step 41 steps
}
...

What happens if the start angle is 12 degrees?
Will one motor movement (41 steps) change the angle to more than 13 degrees?
In other words, will your program make the motor 'hunt', never reaching exactly 13 degrees?

Also, you don't need either an if or a while statement if your 41 steps represent exactly one degree.
Code:

{     // initiate Stepper
   myStepper.setSpeed(13);     //Setting Stepper Speed at 13rpms
   myStepper.step((-stepsPerRevolution/50)*(angle - 13));   
//Tell Stepper to rotate until angle = 13
//if angle is less than 13, (angle - 13) will be a negative number
//so the step direction will be anticlockwise. (- * - = +)
//If angle is = 13, (angle - 13) will be zero, so the stepper will
//rotate 0 steps!!
}
87  Using Arduino / Project Guidance / Re: Need help with my project on: April 17, 2013, 08:25:30 pm
When posting code, USE CODE TAGS.

Because you didn't use code tags, your
Code:
value[i]
was turned into 'value' [start italics], a non-printing character, so we can't see the
Code:
[i]
.
88  Topics / Device Hacking / Re: Decoding bytes from Tower wireless thermostat on: April 16, 2013, 09:55:14 pm
I suggest that these may be ASCII characters, as the last 3 numbers in most blocks represent space, carriage return and line feed. Alternate characters are 20h (space). I'll leave you to check the rest....  smiley-grin
89  Using Arduino / Programming Questions / Re: A function that won't work as expected. on: April 16, 2013, 08:55:40 pm
I have run into a problem with a function I have. I use Arduino as ISP to program an Attiny 45. Below is my current fix that is working - proving that my library work. The scopeSens1.getValue(samples, variation) is a simple routine that defines a pin, read the analogvalue and does some filtering to return an average whereby outlying values is discarded in calculating the average. I call it many times in the rest of my program.

Code:
    powerLevel = powerLevel - 25; 
    if (powerLevel < 0) {
      powerLevel = 0; 


Here you're puting powerLevel out of bounds and then correcting it.
Try instead
Code:

if (powerLevel<25){ //Check first if the change will take powerLevel out of bounds
powerLevel =0; //if so, set it to zero
}
else{
powerLevel = powerLevel - 25 //won't go out of bounds, so ok to change powerLevel
}
------------------------------------------------------------------------------
if (powerLevel>230){ //Check first if the change will take powerLevel out of bounds
powerLevel =255; //if so, set it to 255
}
else{
powerLevel = powerLevel + 25 //won't go out of bounds, so ok to change powerLevel
}
That way powerLevel can never go out of bounds. Treat all your variables in the same way.
90  Using Arduino / Programming Questions / Re: PWM motor speed question on: April 16, 2013, 08:34:04 pm
Maybe there is another approach.

Code:
    for ( int motorspeed ; motorspeed < stir_speed; motorspeed++) {
      analogWrite(44, motorspeed);
      delay(stir_ramp);
}

Another approach:
Code:
if (motorspeedA >= stirspeed){ //?? reached desired speed?
// next step
// Rest of your program
//
}
else {
   motorspeedA++;
   analogWrite(44, motorspeedA);
   delay(stir_ramp);
}
This will loop until the motor has reached the desired speed, then go onto your next step.
You'll need to use different variable names for each of your motorspeeds within the program.
Pages: 1 ... 4 5 [6] 7 8 ... 18