Show Posts
Pages: 1 [2] 3 4 ... 165
16  Using Arduino / Programming Questions / Re: Trough Detector on: July 24, 2014, 08:39:09 pm
Well, as you can see, the Serial.prints are right before the "trough detector", which is likely significant.
Somehow they're "beneficial".  It's a little shagged out after all that float math and can do with a respite, a relaxation interval?

I was hasty in saying that if I leave even "just one" then it's OK.
That's not really so, as it turns out. I had just the first there and it repeated once that I saw this morning. Pretty early on (always after the same number of reps after pressing Reset), too, but still an overall improvement over the very first attempt.
I went and put the others back in.
With all of them there, I haven't noticed any hiccups.
I suppose in printing the three floating values and the spaces etc, that's maybe 35 characters, 350 bits, 9600bps, 35+msecs on that.
Still, the effect doesn't seem to suffer for it.

[ Inquiring minds want to know. They don't always know how to find out though.]
17  Using Arduino / Programming Questions / Re: Trough Detector on: July 23, 2014, 08:09:02 pm
The fading up/down works.
(This is a pretty easy circuit to set up.)

The conundrum has been in steering the fading action into alternating outputs.
In the original version, that didn't go consistently.
With the latest Trough Detector's comparing trends, it stayed stuck (stuck on 1 output ) till I introduced some Serial.,print statements whereupon (mysteriously?) it works.

> > > Clarification - "stuck on 1 output"

> > > > Is this a fringe benefit of float? you can't dive right when you want to?
18  Using Arduino / Programming Questions / Re: Trough Detector on: July 23, 2014, 07:56:13 pm
Yes - it was getting late, that's how I had it, but I started grasping at straws and just chucked the >.
So, sorry for any mix up.

This isn't happening (but should):
Code:
byte transistorPin;
byte x;
float currentVal;
float previousVal;
float formerDiff;  // old    currentVal - previousVal
float currentDiff; // latest currentVal - previousVal

void setup()
{
  pinMode(transistorPin, OUTPUT);
  transistorPin = 9;
  x = 1;                // freq of the ramping
  previousVal = 100.0;  // starter value, rubbishy
  formerDiff = -20.0;   // starter value, rubbishy
}

void loop()
{
  currentVal = (exp(sin(millis()/1500.0*x*PI)) - 0.36787944)*108.0;
  currentDiff = currentVal - previousVal;
  if( (currentDiff>0) && (formerDiff < 0) ) //
  {
    // trough detected, so swap pins
    swap_pins();
  }
  analogWrite(transistorPin, currentVal);
  formerDiff = currentVal - previousVal;
  previousVal = currentVal;
}

void swap_pins ()
{
  if(transistorPin == 9)
  {
    transistorPin = 10;
  }
  else
  {
    transistorPin = 9;
  }
}

So, I said "Rats! Why not??"
Then I punched in some Serial.prints to get some data (currentVal, currentDiff, formerDiff)
Code:
byte transistorPin;
byte x;
float currentVal;
float previousVal;
float formerDiff;  // old    currentVal - previousVal
float currentDiff; // latest currentVal - previousVal

void setup()
{
  pinMode(transistorPin, OUTPUT);
  transistorPin = 9;
  x = 1;                // freq of the ramping
  previousVal = 100.0;  // starter value, rubbishy
  formerDiff = -20.0;   // starter value, rubbishy
  Serial.begin(9600);
  delay(1000);
}

void loop()
{
  currentVal = (exp(sin(millis()/1500.0*x*PI)) - 0.36787944)*108.0;
  currentDiff = currentVal - previousVal;

  Serial.print(currentVal,DEC);
  Serial.print(" _ ");
  Serial.print(currentDiff,DEC);
  Serial.print(" _ ");
  Serial.println(formerDiff,DEC);

  if( (currentDiff>0) && (formerDiff < 0) ) //
  {
    // trough detected, so swap pins
    swap_pins();
  }
  analogWrite(transistorPin, currentVal);
  formerDiff = currentVal - previousVal;
  previousVal = currentVal;
}

void swap_pins ()
{
  if(transistorPin == 9)
  {
    transistorPin = 10;
  }
  else
  {
    transistorPin = 9;
  }
}

And all that data looked right.
And then I noticed - it was working perfectly !

I deleted all of the Serial.prints and it bombs.
If I leave just one of those in then it works.
So, What Gives?
19  Using Arduino / Programming Questions / Re: Trough Detector on: July 22, 2014, 10:26:53 pm
I think tht I understand what you're saying.
If the preceding current-previous were negative (<0) and the immediate current-previous were positive then that would indicate that the progress is pulling out of the trough.

I tried this
Code:
byte transistorPin;
byte x;
float previousVal;
float formerDiff;  // preceding  (current - previous)
float currentVal;

void setup()
{
  pinMode(transistorPin, OUTPUT);
  transistorPin = 9;
  x = 1;  // freq of the ramping
  previousVal = 100.0;  // starter value, magic number
  formerDiff = -20.0;   // starter value, magic number
}

void loop()
{
  currentVal = (exp(sin(millis()/1500.0*x*PI)) - 0.36787944)*108.0;
  if(((currentVal-previousVal)>0) && (formerDiff>0)) // trough det.
  {
    // to swap pins
    if(transistorPin == 9)
    {
      transistorPin = 10;
    }
    else
    {
      transistorPin = 9;
    }
  }
  analogWrite(transistorPin, currentVal);
  formerDiff = currentVal - previousVal;
  previousVal = currentVal;
}
but it doesn't change (it's stuck on pin 9.).

If I change the "trough detector" to
if(((currentVal-previousVal)>0) && (formerDiff>=0)) // trough det
then it kind of does it weird like on both pins, hard to describe.
20  Using Arduino / Programming Questions / Re: Trough Detector on: July 21, 2014, 08:51:04 pm
val "is a value between -40 and 68."

I got the "original" version of the sketch, just one output, and did
Serial.println(val,DEC);
before ea. analogWrite
and val ranges from mouse-nuts to > 250 and change.
It starts out right around "68" though.

The value of val at the trough:

1
0.04219
A 0.0055
B 0.0042  ***
C 0.11304

2
A 0.025189
B 0.0000901  ***
C 0.014728

3
A 0.0589
B 0.012546  ***
C 0.0139
D 0.0282

So I need to keep rolling track of values of val
and test for when (A > B) && (B < C)
Then I would know that the trend had just begun upward again.
21  Using Arduino / Programming Questions / Re: Trough Detector on: July 21, 2014, 07:08:31 pm
I think the result of this:
Code:
val = (exp(sin(millis()/1500.0*x*PI)) - 0.36787944)*108.0;
is a value between -40 and 68.
I have actually no idea what those numbers are and what they do and why.
But with a value of -40 and 68, the 0.2 might be too small.

Start with this:
Code:
boolean nearZero = false;
if (val > -1.0 && val < 1.0) {
    nearZero = true;
}

The equation is the work of another. He had trouble with it "not working", but after a lot of post and counter-post, "not working" turned out how to seamlessly change the rate of change (with x derived from a "sensor reading".)
I liked the effect and thought it would be kind of novel to have it go out on alternating outputs.

I, too, thought about using a Flag ("nearZero")

not that it matters, but I am curious why you set up (pin0?) as an output.  Is this part of larger code?

Maybe you meant why I didn't set up pin 10 as an output?
I didn't know that analogWrite didn't require a pinMode. (now I'm wise - to that.)

No, there's no "larger code", this is all that there is.
22  Using Arduino / Programming Questions / Re: Trough Detector on: July 20, 2014, 08:59:28 pm
if((previousVal > 0.0) && (val < 0.2))
made it worse.
23  Using Arduino / Programming Questions / Re: Trough Detector on: July 20, 2014, 08:49:18 pm
OK, well it does alternate, but every several times it woofs it.
I'll  try to incorporate your suggestions and report back.
24  Using Arduino / Programming Questions / Trough Detector on: July 20, 2014, 08:24:54 pm
With the sketch that follows, I'm trying to toggle the output pins for the sine output such that it goes from dim to bright and back to dim on one pin and then do likewise on the other, ...
Code:
byte transistorPin;
byte x;
float previousVal;

void setup()
{
  pinMode(transistorPin, OUTPUT);
  transistorPin = 9;
  x = 1;  // freq of the ramping
}

void loop()
{
  float val = (exp(sin(millis()/1500.0*x*PI)) - 0.36787944)*108.0;
  if((previousVal > 0) && (val == 0))  // trough detector
  {
    if(transistorPin == 9)
    {
      transistorPin = 10;
    }
    else
    {
      transistorPin = 9;
    }
  }
  analogWrite(transistorPin, val);
  previousVal = val;
}

Viz. my "trough detector",
if((previousVal > 0) && (val == 0))
I'm looking for when the previous value was greater than zero, but the current value is 0, indicating that it's bottomed out.
However, at times the output pin ("transistorPin") doesn't change.

I don't know if it's not changing, or it's doing a double-take, or it's not making it to 0.
Care to open my eyes (or maybe kick sand in my face)?
25  Using Arduino / Programming Questions / Re: Why does this program drop my digital pin out voltage? on: July 20, 2014, 08:30:31 am
Maybe I'm blind in one eye and can't see out the other, but the scope traces look like "4.8V" to me.
26  Using Arduino / Programming Questions / Re: How to use TX and RX pins on Arduino Duemilanove on: July 20, 2014, 08:20:10 am
nothing has worked so far, I can use the same code to send from uno to uno with no problem.
but I cant use the sketch for uno > Duemilanove

You need to connect the GND from UNO to Duemilanove. Do you have this?

Dear luisilva
no I havent done that, I will try it and let you know

There's a profound contradiction afoot here.
I don't think that "the sketch" is doing what you think it is and there are other issues as well.
27  Using Arduino / General Electronics / Re: ebay relay boards on: July 20, 2014, 08:13:27 am
if I look at the bottom of this thing and see those small traces, I can't imagine it could withstand 2.5kW. What do you think, are they safe to use? (I would use it at 240V/7A)

There's not 2500W here.  You're figuring, "Oh, 250V * 10A", but the rating should be interpreted as the contacts can switch, at max., 250V and make/break 10A [assuming those ratings are genuine]. 
Either way, don't push the envelope.
28  Using Arduino / Microcontrollers / Re: I want to be sure before going to the next step..... on: July 19, 2014, 11:45:03 pm
I want to be sure this board will "work" before going to the next stage of project building.


http://www.ebay.com.au/itm/351080750215?ssPageName=STRK:MEWAX:IT&_trksid=p3984.m1438.l2649


I have a few SMALL projects on which I am working.

If this *IS* arduino compatible for programming, pin I/O (digital/analogue I/O etc) I will be very happy.

It is, so be happy, let joy be unconstrained.

(And when/if I get one, what is it called in the board drop down menu?  I've never looked before as I have never changed it.)

What do you mean "If/when"?
Commit!
In previous versions I always used Arduino Duemilanove w/Atmega328
and still do with 1.0.x, even though there's a Arduino Nano w/ Atmega328 choice.
They're supposed to be Duemilanoves only in a smaller form-factor


29  Using Arduino / Programming Questions / Re: How to use TX and RX pins on Arduino Duemilanove on: July 19, 2014, 04:37:09 pm
Let's go back to your first two sketches.
The transmitter sends "ON", "Of",...
The receiver waits for serial data, any serial data, and upon receiving serial data digtalWrites 13 HIGH, and some other stuff.
Don't have a delay in the receiver part -and-
In the receiver sketch, you should be examining this received data - to determine a course of action (which you are not.)
30  Using Arduino / General Electronics / Re: Does a mosfet require PWM? on: July 19, 2014, 08:02:55 am
Well I have an irf520n mosfet running a 0.5 amp load.

I'm not very good at understanding the data sheets

IRF520
IRF520

VGS, output & transfer characteristics not a good match with 5V, separate drive ckt req'd.
Pages: 1 [2] 3 4 ... 165