Show Posts
Pages: 1 [2] 3 4 ... 835
16  Using Arduino / Motors, Mechanics, and Power / Re: First lessons from using a stepper on: Today at 05:55:27 am
Normally a safe value to use for all stepper drivers on the market is 10us pulse time.

If the driver has high-speed opto coupler that pulsewidth can be much shorter.  If
the driver doesn't use an opto coupler (perhaps something like an A4988 breakout
board) then the pulse width can be much shorter.  Datasheets tell you these details,
always check them if you can.

The single/dual clock mode is about whether you have step/direction interface or
a forwards/backwards interface.

The default is step/direction - clocking pulses on the step pin, direction pin setup
to indicate which direction.

With dual clock the two pins are both clock pins, one to step forwards, one to step
backwards (and of course you must not step both together!).

Commercial stepper drivers always have an enable input and always use optocouplers.

The nice property of an opto coupler is you can drive it between pin and ground or
between pin and Vcc, which means you have a choice of polarity (active high or
active low).

Sometimes they have built-in resistors for the optocouplers, sometimes they don't,
you must read the datasheets as putting 5V across a bare optocoupler will blow it.
Most are sensible and have some resistance.
17  Using Arduino / General Electronics / Re: help with components for a bike light system on: Today at 05:44:38 am
Well several of those already have controllers wired into the circuit, which need
disconnecting alas - alternatively you can figure out the switch wiring that goes to
each controller (several flashing modes, presumably), or you can break-out at the
-ve battery terminal - again cutting traces needed smiley-sad

I'd sort of forgotten that LED bikelights tend to have flashing modes (non of
which are technically legal in the UK except for turn indicators).

If you're prepared to irreversibly modify them, just treat as a battery and LED,
break out at battery -ve.  If you can fit a logic-level n-MOSFET in the case then its
source -> battery -ve,
drain -> LED cathode.

bring out source and gate as a twisted pair or screened cable back to arduino.
At arduino end gate via 150 ohm resistor to a digital/PWM pin, source to ground.

Repeat for each light.
18  Using Arduino / Programming Questions / Re: AC signal voltage on: Today at 05:34:04 am
That's the one!

Although it does assume a low impedance source for the incoming AC to drive the ADC
properly, since there is no active buffering.  If the source impedance was already 10k
you'd want to lower the 10k resistor to perhaps 1k (or live with an LSB or two of error)
19  Using Arduino / Programming Questions / Re: AC signal voltage on: Today at 05:22:48 am
No, that's not what I said.

I said 10k resistor for overload protection, that's the maximum value you can use without
compromising the ADC input requirements.
20  Using Arduino / Programming Questions / Re: Ignoring IF statment. on: Today at 05:22:02 am
OK, that was a bit strong, but experience on these forums shows neophytes never
test the result of read() for -1, but many use available () - although not always
carefully enough.

available() is more general, as in

Code:
 if (Serial.available () >= 2)
  {
    byte hibyte = Serial.read () ;
    byte lobyte = Serial.read () ;
    ....
  }

So just use available() for availability testing - only one mechanism needs to be learnt.

Personally I'd have made read() blocking, since there is already available() available,
it would have meant less confusion for beginners.
21  Using Arduino / Programming Questions / Re: AC signal voltage on: Today at 05:08:25 am
I could but my camera's elsewhere!

The input circuit is like the one in Answer 1 here: http://www.techques.com/question/4-35735/Measure-AC-Sine-Wave-amplitude-with-ADC  Skip the opamp and
route the signal direct to the analog pin via a 10k resistor (overload protection).
22  Using Arduino / Programming Questions / Re: Converting timer 1 interrupt program into timer 2 interrupt? on: Today at 05:03:17 am
Its only a waste if you need it for other more urgent purposes smiley The timer's sat there clocking
away whether or not you use analogWrite () too...
23  Using Arduino / Programming Questions / Re: RE: TinyGPS++ Library Issues on: Today at 05:00:59 am
You are calling delay(), you are thus losing nearly all the output from
your GPS.  Remove that call.   Look at blinkWithoutDelay example if you want
to limit changes to the tone's frequency to regular intervals without stalling the
whole Arduino.
24  Using Arduino / Programming Questions / Re: Ignoring IF statment. on: Today at 04:50:39 am
You must never call Serial.read() if you haven't perviously called Serial.available() to
check there is at least one character available to read.

You want something more like:
Code:
void loop()
{
  if (Serial.available () > 0)
  {
    int val=Serial.read();  // val shouldn't be global, its local
    if (val == 'F')     // NO SEMICOLON HERE
    {
      ...
    }
  }
  ...
25  Using Arduino / Programming Questions / Re: Jumping back to "void loop();"? on: Today at 04:48:59 am
Firstly break up that massive loop() function, its never easy to work with monolithic
chunks of code like that, our brains have a small scratchpad memory that won't function
efficiently if overloaded - we can only think about 1 or 2 things at once, basically, so
code functions that only do one of two things:

Code:
void loop ()
{
  if (digitalRead(locRemsw) == LOW)  // read local/remote switch on front panel
    handle_manual_switch () ;
  else
    handle_remote_mode () ;
}

void handle_manual_switch ()
{
   ...
}

void handle_remote_mode ()
{
  ...
}

Once the structure is more clear like this it will be obvious which bit of code has
responsibility for what.  For instance:

Code:
void handle_remote_mode ()
{
  if (Serial.available() == 0)
    return ;
  remoteSwSet = Serial.read();
  ...
}
Now seems very reasonable - the remote mode processing just returns if there's nothing
to do.
26  Using Arduino / Programming Questions / Re: How to write ÆØÅ ? on: Today at 04:37:32 am
Wrong hex code I'd guess.  Your lcd has a datasheet listing the inbuilt font?  You sure it
has accented characters and not just 7-bit ASCII?
27  Using Arduino / Programming Questions / Re: AC signal voltage on: Today at 04:36:22 am
Since an AC signal varies with time, you cannot just measure its amplitude
with a single ADC reading at a single time.

You have two approaches:  hardware or software. 
And you have to decide whether to measure peak voltage or rms voltage,
and whether that should be a true rms voltage or just peak voltage / root-2.

In hardware a peak detection circuit (related to precision rectification) can
be used - an opamp is used to capture peak voltage on a capacitor.

In software you sample the waveform repeatedly over a whole number of
cycles and calculate the value you want (be it maximum, or true rms).

Also to measure AC you have to voltage shift the signal so the whole
waveform is between 0 and 5V (ADC cannot measure outside that range,
and any significant currents (1mA or more?) flowing outside that range
will risk damaging the chip. 

The simplest level shift circuit is a capacitor to a 1:1 voltage divider
28  Using Arduino / Programming Questions / Re: How to write ÆØÅ ? on: Today at 04:29:44 am
Quote
Ithink the hex is \x9B but how to write it ?

You tried
Code:
lcd.print("Fors\x9Bg Tilbage ");
?
29  Using Arduino / Programming Questions / Re: Simple calculations ; wrong Syntax or ... on: Today at 04:26:19 am
The thing you have to realise is that integer-only division is not division, because
fractions cannot be represented as integers.  The relation

(a / b) * b == a

Simply does not and cannot hold when b is not 1, when using integer arithmetic.

Many computer languages support only integer and floating point arithmetic,
so fractions have to be represented as floating point.

In integer arithmetic the act of division a/b yields a quotient q and a remainder r
which obey the relations:

q *b + r = a,     0 <= r < |b|

(Except that in C this doesn't hold for negative numbers because the inventers
of the language failed maths AFAICT!)

In C % is the remainder operator, aka modulo operator.
30  Using Arduino / Programming Questions / Re: Reading RS485 packet - one byte always wrong - HELP PLEASE on: Today at 04:18:24 am
You'll have much less grief if you use blocking I/O for testing this,
even if you then recode it as non-blocking state-machine driven for
the final sketch:
Code:
int myRead ()
{
  while (Serial.available () == 0)
  {}
  return Serial.read () ;
}
Use myRead and you can't see 0xFF's due to buffer underruns, which seems
to be what's happening.

The generic approach to non-blocking I/O should be like this:

Code:
void loop ()
{
  ...
  if (Serial.available () > 0)
    handle_next_char (Serial.read ()) ;
  ...
}
And handle_next_char is not allowed to call Serial.read().  This way
again you prevent any issues with reading from an empty buffer
or blocking on I/O holding up the rest of loop()
Pages: 1 [2] 3 4 ... 835